Skip to main content
POST

Authorizations

Authorization
string
header
required

Authenticate with an API key using Bearer authentication. Do not expose real keys in documentation, code, or repositories.

Body

application/json

Messages protocol request body. model, max_tokens, and messages are required.

model
string
required

ID of the model to generate the message. Use GET /models to list models and confirm that the model supports the Messages protocol.

Example:

"deepseek-ai/deepseek-v4.1-flash-1017"

max_tokens
integer
required

Output token limit for this request. Must be at least 1; the model determines the maximum. This field is required by the Messages protocol, which does not use the Chat Completions parameter max_completion_tokens.

Required range: x >= 1
Example:

128

messages
object[]
required

Messages in conversation order, with at least one message. Use user for user messages and assistant for model replies. Return tool results as tool_result content blocks in a user message.

Minimum array length: 1
stream
enum<boolean>

Whether to stream output. When true, receive incremental content through named SSE events.

Available options:
true,
false
thinking
object

Reasoning configuration. Use type=enabled or type=disabled to request reasoning on or off. Support varies by model.

output_config
object

Model output configuration.

tools
object[]

Function tools available to the model. When the model returns a tool_use content block, the client executes the tool and returns its result through tool_result.

tool_choice
object

Controls tool selection. Use {"type":"auto"} to let the model choose, {"type":"any"} to require a tool call, or {"type":"none"} to disable tool calls. Use {"type":"tool","name":"get_weather"} to select a specific tool.

Response

Message response. Streaming examples show only selected events and fields.

For some models, message_start.message may omit type and role. Parse SSE data according to the event type.

id
string
required

Response identifier.

type
enum<string>
required

Response object type, set to message.

Available options:
message
role
enum<string>
required

Response message role, set to assistant.

Available options:
assistant
model
string
required

Identifier of the model that generated the response.

content
object[]
required

Response content blocks, which may include text, reasoning content, and tool calls.

stop_reason
string | null

Reason generation ended. May be null before generation ends.

stop_sequence
string | null

Stop sequence that ended generation. May be null if none was triggered.

usage
object

Token usage for this request.