Skip to main content
POST
cURL

Streaming

With stream: true the response is text/event-stream: one data: event per chunk, terminated by data: [DONE]. The last data event carries usage whether or not you sent stream_options.include_usage — you never have to choose between streaming and knowing what you were billed. If a stream fails partway, chunks already sent are not withdrawn. You get one more event carrying an error object, then [DONE]. Treat a stream that ended without [DONE] as incomplete.

Token accounting

The usage object is the number you are billed on, not an estimate of it. When a stream is cancelled after the model has begun producing output, those tokens are still billed — see Errors for the two codes where that happens.

Authorizations

Authorization
string
header
required

Authorization: Bearer <your API key>. On /v1/messages, the Anthropic-style x-api-key: <your API key> header is accepted instead.

Headers

Idempotency-Key
string

Your own key for making a retry safe (up to 255 characters). It is accepted and echoed back today; de-duplication of replays arrives in a later release, so a retry is currently a second billable call.

Maximum string length: 255

Body

application/json
model
string
required

Which model answers the call. A bare slug for platform models (deepseek-v4.1-flash), or a full resource name for something your account owns (accounts/{account}/models/{model}, or a deployment). Never an upstream vendor's own name.

Maximum string length: 256
messages
object[]
required

The conversation so far, oldest first. Each turn carries a role (system, user, assistant or tool) and its content.

Minimum array length: 1
stream
boolean
default:false

Return the answer as server-sent events as it is generated, instead of one response at the end. The last data event carries the usage numbers either way.

stream_options
object

Streaming options. include_usage is accepted for compatibility; usage arrives on the final event whether or not you ask for it.

max_tokens
integer

Ceiling on how many tokens may be generated. Omit it to use the model's own default.

Required range: x >= 1
max_completion_tokens
integer

Ceiling on generated tokens. Wins over max_tokens when both are sent.

Required range: x >= 1
temperature
number
default:1

How much randomness to allow when picking each token. Lower is more repeatable, higher is more varied.

Required range: 0 <= x <= 2
top_p
number
default:1

Nucleus sampling: only consider the most likely tokens up to this share of the probability mass. Tune this or temperature, not both.

Required range: 0 <= x <= 1
stop

Up to 4 strings that end generation as soon as the model produces one. The matched string is not included in the output.

seed
integer

Best effort repeatability: the same seed with the same parameters returns the same answer on models that support it.

frequency_penalty
number
default:0

Pushes the model away from tokens it has already used often in this answer. Negative values do the opposite.

Required range: -2 <= x <= 2
presence_penalty
number
default:0

Pushes the model away from tokens that have appeared at all in this answer, which tends to move it on to new ground.

Required range: -2 <= x <= 2
user
string

Your own identifier for the end user behind the call. It is echoed back in this request's log line so you can correlate the two; it is not kept on the usage record.

Maximum string length: 256
tools
object[]

Function definitions the model may call. If none of the providers that can serve this model support tools, the call is rejected rather than answered as though you had not asked.

tool_choice

Whether the model may, must, or must not call a tool: none, auto, required, or one named function.

Available options:
none,
auto,
required
response_format
object

Ask for free text, a JSON object, or JSON matching a schema. Rejected if no provider behind this model can honour it.

service_tier
enum<string>
default:standard

Which service tier serves the call. Only standard is accepted today.

Available options:
standard,
priority,
fast
n
integer

How many completions to return.

Only 1 is accepted. Any other value returns INVALID_REQUEST.

logprobs
boolean

Per-token log probabilities.

Only false is accepted. true returns INVALID_REQUEST.

Response

OK. With stream: true the same call answers text/event-stream instead, one chunk per event, terminated by data: [DONE]; the last data event carries usage whether or not you asked for it.

id
string
required
object
string
required
Allowed value: "chat.completion"
created
integer
required
model
string
required
choices
object[]
required
usage
object
required
system_fingerprint
string