Guides
Streaming
Add "stream": true to the body and the reply arrives as Server-Sent Events while it is generated. The events follow the format of the path you called, whatever the model.
Events by endpoint
| Path | Text arrives in | Stream ends with |
|---|---|---|
/v1/chat/completions | choices[0].delta.content | data: [DONE] |
/v1/responses | response.output_text.delta events | response.completed |
/v1/messages | content_block_delta events | message_stop |
Chat Completions
With the SDK, reuse the client from the reference page.
curl -N https://api.oneapi.id/v1/chat/completions \
-H "Authorization: Bearer $ONEAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-fable-5.1",
"stream": true,
"messages": [{"role": "user", "content": "Count from one to five."}]
}'The last data chunk before [DONE] has an empty choices list and a usage object. The gateway always asks for it, so you get token counts without setting stream_options. Guard for the empty list, as the examples do.
Responses
curl -N https://api.oneapi.id/v1/responses \
-H "Authorization: Bearer $ONEAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-fable-5.1",
"stream": true,
"input": "Count from one to five."
}'Each event has a type. Text comes in response.output_text.delta, tool arguments in response.function_call_arguments.delta, and the final response.completed event carries the whole response with usage. A reply cut short by the token limit ends with response.incomplete instead.
Messages
curl -N https://api.oneapi.id/v1/messages \
-H "x-api-key: $ONEAPI_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-fable-5.1",
"max_tokens": 1024,
"stream": true,
"messages": [{"role": "user", "content": "Count from one to five."}]
}'The standard Anthropic sequence: message_start, then content_block_start, content_block_delta and content_block_stop for each block, then message_delta with the stop reason and output token count, and message_stop.
Errors during a stream
Errors found before the first byte, such as a bad key or no credit, come back as a normal JSON error with its status code. Once events have started the status is already 200, so a provider failure arrives as an error inside the stream:
# /v1/responses and /v1/messages
event: error
data: {"type": "error", "error": {"type": "upstream_error", "code": "upstream_error", "message": "..."}}
# /v1/chat/completions
data: {"error": {"type": "upstream_error", "code": "upstream_error", "message": "..."}}Testing with cURL
Pass -N so cURL prints events as they arrive instead of buffering them. Proxies in front of your own server need buffering turned off for the same reason.