Streaming

Set stream: true on /v1/chat/completions and the reply arrives as server-sent events, token by token, in the OpenAI chunk format.

Request a stream

curl

curl https://api.airuntime.dev/v1/chat/completions \
  -H "Authorization: Bearer $TOKENS_PAY_KEY" \
  -H "Content-Type: application/json" \
  -N -d '{
    "model": "deepseek-flash",
    "stream": true,
    "stream_options": {"include_usage": true},
    "messages": [{"role": "user", "content": "Write a haiku about prepaid credit."}]
  }'

What arrives

  • Each event is data: {…} with "object": "chat.completion.chunk"; text is in choices[0].delta.content, and thinking (on reasoning models) in choices[0].delta.reasoning_content.
  • Lines that start with a colon (: keep-alive) keep the connection open while the model thinks. SDKs skip them.
  • The stream ends with data: [DONE].

Usage and cost in the stream

Usage is sent only when you ask for it: add "stream_options": {"include_usage": true}. The last chunk before [DONE] then has usage with prompt_tokens, completion_tokens, prompt_tokens_details.cached_tokens, completion_tokens_details.reasoning_tokens when the provider reports it, and airuntime.cost_usd_micros. stream_options is allowed only with stream: true.

If the provider stops mid-stream

The stream ends with an error event and no [DONE]:

SSE

data: {"error":{"message":"The model provider interrupted the stream.","type":"server_error","code":"stream_interrupted"}}

A stream waits up to 10 minutes between pieces of output, and that clock restarts whenever the provider makes progress; there is no limit on total length. See what a failed request costs.

Get a key, then make your first call.

From $5, plus a 5% top-up fee (minimum $0.79). No subscription; paid credit never expires.

Add credit