Documentation
API Reference
POST
Chat Completion
/v1/chat/completions
Send a chat completion request to a selected model. This endpoint is OpenAI-compatible and supports streaming.
Interactive Example
Request & Response Example
Headers
Authorization
stringRequired
Bearer token for authentication. Your A4F API key. Example:
Bearer ddc-a4f-xxxxxxxx
. See Authentication.Content-Type
stringRequired
The content type of the request body.
Default: application/json
Request Body
This endpoint expects a JSON object in the request body with the following fields:
model
stringRequired
ID of the model to use. Must include provider prefix, e.g.,
provider-1/chatgpt-4o-latest
. See Models and Provider Routing.messages
array of objectsRequired
A list of messages comprising the conversation so far.
role
stringRequired
The role of the message author. One of 'system', 'user', 'assistant', or 'tool'.
content
string | arrayRequired
The content of the message. Can be a string or an array of content parts (for multimodal).
name
stringOptional. The name of the author of this message if role is 'user' or 'assistant'. Can be used to identify speakers.
tool_calls
array of objectsOptional. The tool calls generated by the model, if any.
tool_call_id
stringRequired if role is 'tool'. The ID of the tool call being responded to.
stream
booleanIf set, partial message deltas will be sent as server-sent events. See Streaming.
Default: false
temperature
numberSampling temperature (0-2). Higher values mean more randomness.
Default: 1
max_tokens
integerMaximum number of tokens to generate. Defaults to model's maximum if not set.
For a full list of all supported OpenAI-compatible parameters (like top_p
, n
, stop
, tools
, etc.), please refer to the Parameters documentation.
Response Body (200 OK)
A successful request returns a JSON object with the following structure:
id
stringA unique identifier for the chat completion.
object
stringThe object type, which is always 'chat.completion'.
created
integerThe Unix timestamp (in seconds) of when the chat completion was created.
model
stringThe model ID used for the chat completion (e.g., 'provider-1/chatgpt-4o-latest').
choices
array of objectsA list of chat completion choices.
index
integerThe index of the choice in the list.
message
objectA chat completion message object.
role
stringThe role of the author of this message (usually 'assistant').
content
string | nullThe content of the message.
tool_calls
array of objects | nullThe tool calls generated by the model, if any.
finish_reason
stringThe reason the model stopped generating tokens (e.g., 'stop', 'length', 'tool_calls').
usage
objectUsage statistics for the completion request.
prompt_tokens
integerNumber of tokens in the prompt.
completion_tokens
integerNumber of tokens in the generated completion.
total_tokens
integerTotal number of tokens used in the request (prompt + completion).
system_fingerprint
string | nullThis fingerprint represents the backend configuration that the model runs with. Can be used to track changes in the backend.
Was this page helpful?