Streaming

Receive completions incrementally via server-sent events to cut perceived latency and render tokens as they arrive.

Set stream: true on a Chat Completions or Messages request and AnyRouter returns server-sent events instead of one buffered reply. Use an API key (sk-ar-...) from the dashboard.

-N disables curl's buffering.

bash
curl -N https://anyrouter.dev/api/v1/chat/completions \
  -H "Authorization: Bearer sk-ar-your-key" \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/gpt-5.4-mini", "stream": true,
       "messages": [{"role": "user", "content": "Count to 10"}]}'

Events

data: {"id":"chatcmpl-abc","choices":[{"delta":{"content":"Hel"}}]}
data: {"id":"chatcmpl-abc","choices":[{"delta":{"content":"lo"}}]}
data: {"id":"chatcmpl-abc","choices":[{"delta":{"content":"!"},"finish_reason":"stop"}]}
data: [DONE]
  • delta.content: the tokens added in this event.
  • delta.role: set only on the first event.
  • finish_reason: set on the final event.
  • [DONE]: no more events follow.

Cancellation

Close the HTTP connection (for example controller.abort() on an AbortController). AnyRouter propagates the abort upstream, and you pay only for tokens emitted before it.

AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer