// guides

Streaming

Set stream to true to receive the reply token by token as server-sent events, instead of waiting for the whole answer.

Example

curl https://api.litepod.io/v1/chat/completions -N \
  -H "Authorization: Bearer $LITEPOD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nvidia/nemotron-lightning-3.5-30b-a3b",
    "messages": [{"role": "user", "content": "Explain RAG in one sentence."}],
    "max_tokens": 256,
    "stream": true
  }'

Event format

The response has Content-Type: text/event-stream. Each event is a line starting with data: followed by a JSON chunk:

  • Text arrives in choices[0].delta.content.
  • The chunk that ends a choice has a finish_reason, such as stop, length or tool_calls.
  • A final chunk with empty choices carries usage, the tokens you're billed for.
  • The stream ends with data: [DONE].
Stream
data: {"id":"chatcmpl-8f3a2c…","object":"chat.completion.chunk","model":"nvidia/nemotron-lightning-3.5-30b-a3b","choices":[{"index":0,"delta":{"role":"assistant","content":"RAG"}}]}

data: {"id":"chatcmpl-8f3a2c…","object":"chat.completion.chunk","model":"nvidia/nemotron-lightning-3.5-30b-a3b","choices":[{"index":0,"delta":{"content":" retrieves"}}]}

…

data: {"id":"chatcmpl-8f3a2c…","object":"chat.completion.chunk","model":"nvidia/nemotron-lightning-3.5-30b-a3b","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: {"id":"chatcmpl-8f3a2c…","object":"chat.completion.chunk","model":"nvidia/nemotron-lightning-3.5-30b-a3b","choices":[],"usage":{"prompt_tokens":14,"completion_tokens":21,"total_tokens":35}}

data: [DONE]

Errors during a stream

Errors before the stream starts (bad key, unknown model, low balance) come back as a normal JSON error with the matching HTTP status. If the model fails after the stream has started, the status is already 200, so the error arrives as one last event before [DONE]:

Error event
data: {"error":{"message":"The model provider returned an error. Please retry.","type":"api_error","code":"upstream_error"}}

data: [DONE]

Billing

Streamed requests cost the same as regular ones. If you disconnect early, you're billed only for the tokens already sent to you. For reasoning models, the reasoning isn't streamed, but its tokens are still counted in usage and billed.