Chat completion using G4F Endpoint
curl --request POST \
--url http://localhost:9000/api/v1/gpt4free \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "<string>",
"content": "<string>"
}
],
"model": "<string>",
"stream": true,
"timeout": 123,
"shuffle": true,
"image_url": "<string>"
}
'import requests
url = "http://localhost:9000/api/v1/gpt4free"
payload = {
"messages": [
{
"role": "<string>",
"content": "<string>"
}
],
"model": "<string>",
"stream": True,
"timeout": 123,
"shuffle": True,
"image_url": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [{role: '<string>', content: '<string>'}],
model: '<string>',
stream: true,
timeout: 123,
shuffle: true,
image_url: '<string>'
})
};
fetch('http://localhost:9000/api/v1/gpt4free', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "9000",
CURLOPT_URL => "http://localhost:9000/api/v1/gpt4free",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'messages' => [
[
'role' => '<string>',
'content' => '<string>'
]
],
'model' => '<string>',
'stream' => true,
'timeout' => 123,
'shuffle' => true,
'image_url' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "http://localhost:9000/api/v1/gpt4free"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": true,\n \"timeout\": 123,\n \"shuffle\": true,\n \"image_url\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("http://localhost:9000/api/v1/gpt4free")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": true,\n \"timeout\": 123,\n \"shuffle\": true,\n \"image_url\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:9000/api/v1/gpt4free")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": true,\n \"timeout\": 123,\n \"shuffle\": true,\n \"image_url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"response": "Large language models like me are advanced artificial intelligence systems designed to understand and generate human language. These models are trained on vast amounts of text data to learn patterns and relationships within language, enabling them to perform various tasks such as text generation, translation, summarization, and more. They are characterized by their ability to handle complex language tasks and generate coherent responses based on the input they receive."
}
{
"error": "error message"
}
Endpoint Examples
Chat completion using G4F Endpoint
Sends a request for chat completions using the g4f library
POST
v1
/
gpt4free
Chat completion using G4F Endpoint
curl --request POST \
--url http://localhost:9000/api/v1/gpt4free \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "<string>",
"content": "<string>"
}
],
"model": "<string>",
"stream": true,
"timeout": 123,
"shuffle": true,
"image_url": "<string>"
}
'import requests
url = "http://localhost:9000/api/v1/gpt4free"
payload = {
"messages": [
{
"role": "<string>",
"content": "<string>"
}
],
"model": "<string>",
"stream": True,
"timeout": 123,
"shuffle": True,
"image_url": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [{role: '<string>', content: '<string>'}],
model: '<string>',
stream: true,
timeout: 123,
shuffle: true,
image_url: '<string>'
})
};
fetch('http://localhost:9000/api/v1/gpt4free', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "9000",
CURLOPT_URL => "http://localhost:9000/api/v1/gpt4free",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'messages' => [
[
'role' => '<string>',
'content' => '<string>'
]
],
'model' => '<string>',
'stream' => true,
'timeout' => 123,
'shuffle' => true,
'image_url' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "http://localhost:9000/api/v1/gpt4free"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": true,\n \"timeout\": 123,\n \"shuffle\": true,\n \"image_url\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("http://localhost:9000/api/v1/gpt4free")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": true,\n \"timeout\": 123,\n \"shuffle\": true,\n \"image_url\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:9000/api/v1/gpt4free")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"stream\": true,\n \"timeout\": 123,\n \"shuffle\": true,\n \"image_url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"response": "Large language models like me are advanced artificial intelligence systems designed to understand and generate human language. These models are trained on vast amounts of text data to learn patterns and relationships within language, enabling them to perform various tasks such as text generation, translation, summarization, and more. They are characterized by their ability to handle complex language tasks and generate coherent responses based on the input they receive."
}
{
"error": "error message"
}
Request Body
The model could be
gpt-40, gpt-3.5-turbo or gpt-4Whether to stream the response or not.
timeout for the response to be sent.
Shuffle the providers used for the chat completions. More details here
Include image for vision processing using the google gemini-pro model.
200 - Successful chat completion response
Response Text.
400 - Error message
The error message explaining what went wrong.
{
"response": "Large language models like me are advanced artificial intelligence systems designed to understand and generate human language. These models are trained on vast amounts of text data to learn patterns and relationships within language, enabling them to perform various tasks such as text generation, translation, summarization, and more. They are characterized by their ability to handle complex language tasks and generate coherent responses based on the input they receive."
}
{
"error": "error message"
}
Was this page helpful?
⌘I