Skip to main content
POST
Create chat completion
Drop-in OpenAI-compatible chat endpoint. Supports streaming, tool calls, JSON mode, vision, PDF, audio input and Files API file_id references.

Minimal example

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:
OpenAI SDKs ignore chunks with empty choices, so credits_used is a non-breaking extension.

Multimodal content

Pass arrays in content:
Supported block types:
  • text
  • image_url — HTTP URL or base64 data: URI
  • input_audio — inline base64 audio with format (wav/mp3/pcm16/webm)
  • file — inline data + mime_type or file_id reference (Files API)

Using a Files API reference

The gateway resolves 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

All file_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.
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.
The cap is on decoded bytes, so it is the sum of the file sizes you see in /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

Or with a schema (Structured Outputs):

Vision and PDFs

Models with supportsVision: 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-id
  • x-model-used
  • x-fallback-from
Cost isn’t a header here: chat completions return 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

Authorization
string
header
required

API key in format: Bearer inf_***

Headers

x-request-id
string

Optional request ID for tracking

Body

application/json
model
string
required

Model ID

Example:

"gpt-4o"

messages
object[]
required
temperature
number
Required range: 0 <= x <= 2
max_tokens
integer
top_p
number
Required range: 0 <= x <= 1
top_k
integer

Top-K sampling (Google Gemini)

presence_penalty
number

Presence penalty (OpenAI, Google Gemini)

Required range: -2 <= x <= 2
frequency_penalty
number

Frequency penalty (OpenAI, Google Gemini)

Required range: -2 <= x <= 2
seed
integer

Seed for deterministic output (OpenAI, Google Gemini)

stream
boolean
default:false
stop
tools
object[]

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.

tool_choice

Controls whether/which tool the model must call: "none", "auto", "required", or {type:"function", function:{name}} to force one specific function tool.

Available options:
none,
auto,
required
response_format
object

Output format constraint: {type:"text"}, {type:"json_object"}, or {type:"json_schema", json_schema:{...}}.

prompt_cache_key
string

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.

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.

id
string
Example:

"chatcmpl-abc123"

object
string
Example:

"chat.completion"

created
integer
Example:

1713204900

model
string
Example:

"gpt-4o"

choices
object[]
usage
object
credits_used
number

Credits deducted from the workspace balance for this request

Example:

0.115

web_search_credits
number

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.

Example:

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.