curl --request POST \
--url https://api.infery.ai/v1/chat/completions \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Hello!",
"name": "<string>",
"tool_call_id": "call_abc123",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"Paris\"}"
}
}
]
}
],
"temperature": 1,
"max_tokens": 123,
"top_p": 0.5,
"top_k": 123,
"presence_penalty": 0,
"frequency_penalty": 0,
"seed": 123,
"stream": false,
"stop": "<string>",
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location.",
"parameters": {}
}
}
],
"response_format": {
"type": "text"
},
"prompt_cache_key": "<string>",
"web_search": {
"provider": "auto",
"max_results": 5,
"allowed_domains": [
"<string>"
],
"blocked_domains": [
"<string>"
],
"answer": true,
"model": "<string>"
}
}
'import requests
url = "https://api.infery.ai/v1/chat/completions"
payload = {
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Hello!",
"name": "<string>",
"tool_call_id": "call_abc123",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"Paris\"}"
}
}
]
}
],
"temperature": 1,
"max_tokens": 123,
"top_p": 0.5,
"top_k": 123,
"presence_penalty": 0,
"frequency_penalty": 0,
"seed": 123,
"stream": False,
"stop": "<string>",
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location.",
"parameters": {}
}
}
],
"response_format": { "type": "text" },
"prompt_cache_key": "<string>",
"web_search": {
"provider": "auto",
"max_results": 5,
"allowed_domains": ["<string>"],
"blocked_domains": ["<string>"],
"answer": True,
"model": "<string>"
}
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-4o',
messages: [
{
role: 'user',
content: 'Hello!',
name: '<string>',
tool_call_id: 'call_abc123',
tool_calls: [
{
id: 'call_abc123',
type: 'function',
function: {name: 'get_weather', arguments: '{"location":"Paris"}'}
}
]
}
],
temperature: 1,
max_tokens: 123,
top_p: 0.5,
top_k: 123,
presence_penalty: 0,
frequency_penalty: 0,
seed: 123,
stream: false,
stop: '<string>',
tools: [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get the current weather for a location.',
parameters: {}
}
}
],
response_format: {type: 'text'},
prompt_cache_key: '<string>',
web_search: {
provider: 'auto',
max_results: 5,
allowed_domains: ['<string>'],
blocked_domains: ['<string>'],
answer: true,
model: '<string>'
}
})
};
fetch('https://api.infery.ai/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.infery.ai/v1/chat/completions",
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([
'model' => 'gpt-4o',
'messages' => [
[
'role' => 'user',
'content' => 'Hello!',
'name' => '<string>',
'tool_call_id' => 'call_abc123',
'tool_calls' => [
[
'id' => 'call_abc123',
'type' => 'function',
'function' => [
'name' => 'get_weather',
'arguments' => '{"location":"Paris"}'
]
]
]
]
],
'temperature' => 1,
'max_tokens' => 123,
'top_p' => 0.5,
'top_k' => 123,
'presence_penalty' => 0,
'frequency_penalty' => 0,
'seed' => 123,
'stream' => false,
'stop' => '<string>',
'tools' => [
[
'type' => 'function',
'function' => [
'name' => 'get_weather',
'description' => 'Get the current weather for a location.',
'parameters' => [
]
]
]
],
'response_format' => [
'type' => 'text'
],
'prompt_cache_key' => '<string>',
'web_search' => [
'provider' => 'auto',
'max_results' => 5,
'allowed_domains' => [
'<string>'
],
'blocked_domains' => [
'<string>'
],
'answer' => true,
'model' => '<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"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 := "https://api.infery.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"call_abc123\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"arguments\": \"{\\\"location\\\":\\\"Paris\\\"}\"\n }\n }\n ]\n }\n ],\n \"temperature\": 1,\n \"max_tokens\": 123,\n \"top_p\": 0.5,\n \"top_k\": 123,\n \"presence_penalty\": 0,\n \"frequency_penalty\": 0,\n \"seed\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"description\": \"Get the current weather for a location.\",\n \"parameters\": {}\n }\n }\n ],\n \"response_format\": {\n \"type\": \"text\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"web_search\": {\n \"provider\": \"auto\",\n \"max_results\": 5,\n \"allowed_domains\": [\n \"<string>\"\n ],\n \"blocked_domains\": [\n \"<string>\"\n ],\n \"answer\": true,\n \"model\": \"<string>\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
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("https://api.infery.ai/v1/chat/completions")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"call_abc123\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"arguments\": \"{\\\"location\\\":\\\"Paris\\\"}\"\n }\n }\n ]\n }\n ],\n \"temperature\": 1,\n \"max_tokens\": 123,\n \"top_p\": 0.5,\n \"top_k\": 123,\n \"presence_penalty\": 0,\n \"frequency_penalty\": 0,\n \"seed\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"description\": \"Get the current weather for a location.\",\n \"parameters\": {}\n }\n }\n ],\n \"response_format\": {\n \"type\": \"text\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"web_search\": {\n \"provider\": \"auto\",\n \"max_results\": 5,\n \"allowed_domains\": [\n \"<string>\"\n ],\n \"blocked_domains\": [\n \"<string>\"\n ],\n \"answer\": true,\n \"model\": \"<string>\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.infery.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"call_abc123\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"arguments\": \"{\\\"location\\\":\\\"Paris\\\"}\"\n }\n }\n ]\n }\n ],\n \"temperature\": 1,\n \"max_tokens\": 123,\n \"top_p\": 0.5,\n \"top_k\": 123,\n \"presence_penalty\": 0,\n \"frequency_penalty\": 0,\n \"seed\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"description\": \"Get the current weather for a location.\",\n \"parameters\": {}\n }\n }\n ],\n \"response_format\": {\n \"type\": \"text\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"web_search\": {\n \"provider\": \"auto\",\n \"max_results\": 5,\n \"allowed_domains\": [\n \"<string>\"\n ],\n \"blocked_domains\": [\n \"<string>\"\n ],\n \"answer\": true,\n \"model\": \"<string>\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1713204900,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"Paris\"}"
}
}
],
"annotations": [
{
"type": "url_citation",
"url": "https://example.com/article",
"title": "Example Article Title",
"start_index": 123,
"end_index": 123
}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 42,
"completion_tokens": 128,
"total_tokens": 170
},
"credits_used": 0.115,
"web_search_credits": 0.4,
"infery_web_search": {
"provider": "openai",
"searches": 2,
"citations": [
{
"url": "https://example.com/article",
"title": "An example article"
}
]
}
}{
"error": {
"message": "Model not found",
"type": "invalid_request_error",
"code": "model_not_found",
"param": "model",
"job_id": "job_1hR9xTPZqK4mVLc2nJ7fY5wB"
}
}{
"error": {
"message": "Model not found",
"type": "invalid_request_error",
"code": "model_not_found",
"param": "model",
"job_id": "job_1hR9xTPZqK4mVLc2nJ7fY5wB"
}
}{
"error": {
"message": "Model not found",
"type": "invalid_request_error",
"code": "model_not_found",
"param": "model",
"job_id": "job_1hR9xTPZqK4mVLc2nJ7fY5wB"
}
}Chat completions
POST /v1/chat/completions — OpenAI-compatible text and multimodal chat.
curl --request POST \
--url https://api.infery.ai/v1/chat/completions \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Hello!",
"name": "<string>",
"tool_call_id": "call_abc123",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"Paris\"}"
}
}
]
}
],
"temperature": 1,
"max_tokens": 123,
"top_p": 0.5,
"top_k": 123,
"presence_penalty": 0,
"frequency_penalty": 0,
"seed": 123,
"stream": false,
"stop": "<string>",
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location.",
"parameters": {}
}
}
],
"response_format": {
"type": "text"
},
"prompt_cache_key": "<string>",
"web_search": {
"provider": "auto",
"max_results": 5,
"allowed_domains": [
"<string>"
],
"blocked_domains": [
"<string>"
],
"answer": true,
"model": "<string>"
}
}
'import requests
url = "https://api.infery.ai/v1/chat/completions"
payload = {
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Hello!",
"name": "<string>",
"tool_call_id": "call_abc123",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"Paris\"}"
}
}
]
}
],
"temperature": 1,
"max_tokens": 123,
"top_p": 0.5,
"top_k": 123,
"presence_penalty": 0,
"frequency_penalty": 0,
"seed": 123,
"stream": False,
"stop": "<string>",
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location.",
"parameters": {}
}
}
],
"response_format": { "type": "text" },
"prompt_cache_key": "<string>",
"web_search": {
"provider": "auto",
"max_results": 5,
"allowed_domains": ["<string>"],
"blocked_domains": ["<string>"],
"answer": True,
"model": "<string>"
}
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-4o',
messages: [
{
role: 'user',
content: 'Hello!',
name: '<string>',
tool_call_id: 'call_abc123',
tool_calls: [
{
id: 'call_abc123',
type: 'function',
function: {name: 'get_weather', arguments: '{"location":"Paris"}'}
}
]
}
],
temperature: 1,
max_tokens: 123,
top_p: 0.5,
top_k: 123,
presence_penalty: 0,
frequency_penalty: 0,
seed: 123,
stream: false,
stop: '<string>',
tools: [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get the current weather for a location.',
parameters: {}
}
}
],
response_format: {type: 'text'},
prompt_cache_key: '<string>',
web_search: {
provider: 'auto',
max_results: 5,
allowed_domains: ['<string>'],
blocked_domains: ['<string>'],
answer: true,
model: '<string>'
}
})
};
fetch('https://api.infery.ai/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.infery.ai/v1/chat/completions",
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([
'model' => 'gpt-4o',
'messages' => [
[
'role' => 'user',
'content' => 'Hello!',
'name' => '<string>',
'tool_call_id' => 'call_abc123',
'tool_calls' => [
[
'id' => 'call_abc123',
'type' => 'function',
'function' => [
'name' => 'get_weather',
'arguments' => '{"location":"Paris"}'
]
]
]
]
],
'temperature' => 1,
'max_tokens' => 123,
'top_p' => 0.5,
'top_k' => 123,
'presence_penalty' => 0,
'frequency_penalty' => 0,
'seed' => 123,
'stream' => false,
'stop' => '<string>',
'tools' => [
[
'type' => 'function',
'function' => [
'name' => 'get_weather',
'description' => 'Get the current weather for a location.',
'parameters' => [
]
]
]
],
'response_format' => [
'type' => 'text'
],
'prompt_cache_key' => '<string>',
'web_search' => [
'provider' => 'auto',
'max_results' => 5,
'allowed_domains' => [
'<string>'
],
'blocked_domains' => [
'<string>'
],
'answer' => true,
'model' => '<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"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 := "https://api.infery.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"call_abc123\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"arguments\": \"{\\\"location\\\":\\\"Paris\\\"}\"\n }\n }\n ]\n }\n ],\n \"temperature\": 1,\n \"max_tokens\": 123,\n \"top_p\": 0.5,\n \"top_k\": 123,\n \"presence_penalty\": 0,\n \"frequency_penalty\": 0,\n \"seed\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"description\": \"Get the current weather for a location.\",\n \"parameters\": {}\n }\n }\n ],\n \"response_format\": {\n \"type\": \"text\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"web_search\": {\n \"provider\": \"auto\",\n \"max_results\": 5,\n \"allowed_domains\": [\n \"<string>\"\n ],\n \"blocked_domains\": [\n \"<string>\"\n ],\n \"answer\": true,\n \"model\": \"<string>\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
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("https://api.infery.ai/v1/chat/completions")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"call_abc123\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"arguments\": \"{\\\"location\\\":\\\"Paris\\\"}\"\n }\n }\n ]\n }\n ],\n \"temperature\": 1,\n \"max_tokens\": 123,\n \"top_p\": 0.5,\n \"top_k\": 123,\n \"presence_penalty\": 0,\n \"frequency_penalty\": 0,\n \"seed\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"description\": \"Get the current weather for a location.\",\n \"parameters\": {}\n }\n }\n ],\n \"response_format\": {\n \"type\": \"text\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"web_search\": {\n \"provider\": \"auto\",\n \"max_results\": 5,\n \"allowed_domains\": [\n \"<string>\"\n ],\n \"blocked_domains\": [\n \"<string>\"\n ],\n \"answer\": true,\n \"model\": \"<string>\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.infery.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"gpt-4o\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"call_abc123\",\n \"tool_calls\": [\n {\n \"id\": \"call_abc123\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"arguments\": \"{\\\"location\\\":\\\"Paris\\\"}\"\n }\n }\n ]\n }\n ],\n \"temperature\": 1,\n \"max_tokens\": 123,\n \"top_p\": 0.5,\n \"top_k\": 123,\n \"presence_penalty\": 0,\n \"frequency_penalty\": 0,\n \"seed\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"description\": \"Get the current weather for a location.\",\n \"parameters\": {}\n }\n }\n ],\n \"response_format\": {\n \"type\": \"text\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"web_search\": {\n \"provider\": \"auto\",\n \"max_results\": 5,\n \"allowed_domains\": [\n \"<string>\"\n ],\n \"blocked_domains\": [\n \"<string>\"\n ],\n \"answer\": true,\n \"model\": \"<string>\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1713204900,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"Paris\"}"
}
}
],
"annotations": [
{
"type": "url_citation",
"url": "https://example.com/article",
"title": "Example Article Title",
"start_index": 123,
"end_index": 123
}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 42,
"completion_tokens": 128,
"total_tokens": 170
},
"credits_used": 0.115,
"web_search_credits": 0.4,
"infery_web_search": {
"provider": "openai",
"searches": 2,
"citations": [
{
"url": "https://example.com/article",
"title": "An example article"
}
]
}
}{
"error": {
"message": "Model not found",
"type": "invalid_request_error",
"code": "model_not_found",
"param": "model",
"job_id": "job_1hR9xTPZqK4mVLc2nJ7fY5wB"
}
}{
"error": {
"message": "Model not found",
"type": "invalid_request_error",
"code": "model_not_found",
"param": "model",
"job_id": "job_1hR9xTPZqK4mVLc2nJ7fY5wB"
}
}{
"error": {
"message": "Model not found",
"type": "invalid_request_error",
"code": "model_not_found",
"param": "model",
"job_id": "job_1hR9xTPZqK4mVLc2nJ7fY5wB"
}
}file_id references.
Minimal example
curl https://api.infery.ai/v1/chat/completions \
-H "Authorization: Bearer $INFERY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "Summarise Node.js streams in 2 sentences"}
]
}'
from openai import OpenAI
client = OpenAI(api_key=API_KEY, base_url="https://api.infery.ai/v1")
resp = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hi"}],
)
import OpenAI from 'openai';
const client = new OpenAI({ apiKey: process.env.INFERY_API_KEY, baseURL: 'https://api.infery.ai/v1' });
const resp = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hi' }],
});
Streaming
Add"stream": true. Response is Server-Sent Events (text/event-stream). Each chunk is data: {...}\n\n; the stream ends with data: [DONE]\n\n.
The final chunk before [DONE] carries usage info and Infery-specific credits_used:
data: {"choices":[{"delta":{"content":"..."}}]}
data: {"choices":[],"usage":{"prompt_tokens":42,"completion_tokens":128}}
data: {"choices":[],"usage":{...},"credits_used":2}
data: [DONE]
choices, so credits_used is a non-breaking extension.
Multimodal content
Pass arrays incontent:
{
"model": "gpt-4o",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
]
}]
}
textimage_url— HTTP URL or base64data:URIinput_audio— inline base64 audio withformat(wav/mp3/pcm16/webm)file— inlinedata+mime_typeorfile_idreference (Files API)
Using a Files API reference
{
"content": [
{"type": "text", "text": "Review this PDF"},
{"type": "file", "file_id": "file_abc123..."}
]
}
file_id to bytes on the server, injects them into the provider call, and returns a clear 400 if the id doesn’t exist or is out of your workspace.
Total attachment size per request
Allfile_id references in one request must total 64 MB or less, decoded.
This is a limit on the sum, and it is separate from your plan’s per-file
max_file_size_bytes. Both apply. Every file can be individually within your
plan’s per-file cap and the request can still be refused for their total —
that is the intended behaviour, because the server resolves all of them at once.
{
"error": {
"message": "Attachments total at least 78643200 bytes, above the 67108864-byte limit for one request. This is a limit on the SUM of all attached files, not on any single one — reference fewer files, or smaller ones.",
"type": "invalid_request_error",
"code": "attachments_too_large",
"param": "messages[].content[].file_id"
}
}
attachments_too_large always means the total, never one file. A single file
that is too big for your plan is refused at upload time by /v1/files instead.
Split the work across turns, or reference smaller files./v1/files — not the size of the JSON request, which only carries the ids.
Inline data blocks are not counted against it; they are bounded by the
request body limit and by each model’s own per-file limits.
Tool calls
Works exactly like OpenAI’s spec —tools, tool_choice, function schema and tool role messages. Every chat-capable model on Infery that supports tools honours the same format.
JSON mode
{"response_format": {"type": "json_object"}}
{
"response_format": {
"type": "json_schema",
"json_schema": { "schema": { ... }, "strict": true }
}
}
Vision and PDFs
Models withsupportsVision: true accept images directly. For PDFs, models with supportsPdf: true read them natively. Others get an automatic PDF-to-image conversion on the gateway (plus text extraction) — you pay a small extra fee per page (see billing), no code changes required.
Parameters
Full OpenAI parameter set:temperature, top_p, presence_penalty, frequency_penalty, max_tokens, stop, seed, stream, tools, tool_choice, response_format. Plus model-specific:
top_k— Gemini and some OSS models
Response headers
x-request-idx-model-usedx-fallback-from
credits_used in the JSON response
body, or in the final SSE chunk when streaming. x-credits-used exists only on
binary-body endpoints that have no JSON body to carry it, like text-to-speech.Authorizations
API key in format: Bearer inf_***
Headers
Optional request ID for tracking
Body
Model ID
"gpt-4o"
Show child attributes
Show child attributes
0 <= x <= 20 <= x <= 1Top-K sampling (Google Gemini)
Presence penalty (OpenAI, Google Gemini)
-2 <= x <= 2Frequency penalty (OpenAI, Google Gemini)
-2 <= x <= 2Seed for deterministic output (OpenAI, Google Gemini)
Tool definitions available to the model. The gateway translates ONLY entries shaped {type:"function", function:{name, description?, parameters?}} into each provider's native tool-calling form; any other entry is forwarded upstream byte-identical — provider-native tools (web search, grounding, …) already arrive in their own shape.
- Option 1
- Option 2
Show child attributes
Show child attributes
Controls whether/which tool the model must call: "none", "auto", "required", or {type:"function", function:{name}} to force one specific function tool.
none, auto, required Output format constraint: {type:"text"}, {type:"json_object"}, or {type:"json_schema", json_schema:{...}}.
- Option 1
- Option 2
- Option 3
Show child attributes
Show child attributes
Optional cache-routing key for providers that cache prompt prefixes per-server (xAI, OpenAI). Send the same value across turns of one conversation to improve cache hit rate. Mirrors OpenAI’s own parameter of the same name.
Ground the completion in web search, without having to write a provider-native tool entry by hand. Sending this object is the opt-in; there is no boolean form and its absence means no search.
It is a SHORTHAND over tools, and the two reach the same place: the gateway resolves a backend from web_search.provider (or the model family) and, for the natively-grounded providers, injects the matching entry into tools before forwarding — then removes web_search itself, so the upstream provider never sees this key. Sending the provider-native tool entry in tools yourself is the equivalent long form and needs no web_search; send one or the other rather than both.
BILLED. The brave backend runs as a separate search charge reported as web_search_credits on the response, on top of the completion's own tokens; the natively-grounded backends bill through the upstream provider's own search pricing.
Show child attributes
Show child attributes
Response
stream=false (default) returns application/json — a single chat-completion object, shown below. stream=true returns text/event-stream: a sequence of data: <json>\n\n lines terminated by a literal data: [DONE]. OpenAPI 3.0 has no way to describe a framed event stream, so the text/event-stream schema below describes the JSON payload of a SINGLE data: line (a chat.completion.chunk) — never the whole body. The final chunk before [DONE] carries usage and credits_used alongside an EMPTY choices array; every other chunk carries a non-empty choices with an incremental delta.
"chatcmpl-abc123"
"chat.completion"
1713204900
"gpt-4o"
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Credits deducted from the workspace balance for this request
0.115
Credits charged for the grounded web search this request performed, separate from credits_used, which covers the model call. Present only when a web-search provider actually ran.
0.4
What the grounded search actually did. Present only when a web-search provider ran. The same object rides the final SSE chunk when streaming.
Show child attributes
Show child attributes