Docs/API

Streaming

How do I get tokens as they are generated, and what does stopping early cost?

Checked against the code on

Send "stream": true and the response is a standard server-sent event stream, the same frames your client already parses. The proxy in front of the API does not buffer, so the first token arrives when the model produces it.

curl -N https://heyaskr.ai/v1/chat/completions \
  -H "Authorization: Bearer $ASKR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-5.6-sol","stream":true,"messages":[{"role":"user","content":"Write a haiku about the sea."}]}'

What the wire looks like

SSE
: askr
data: {"id":"chatcmpl-9c2b...","object":"chat.completion.chunk","created":1789516800,"model":"gpt-5.6-sol","choices":[{"index":0,"delta":{"role":"assistant","content":"Salt"},"finish_reason":null}]}
data: {"id":"chatcmpl-9c2b...","object":"chat.completion.chunk","created":1789516800,"model":"gpt-5.6-sol","choices":[{"index":0,"delta":{"content":" wind"},"finish_reason":null}]}
...
data: {"id":"chatcmpl-9c2b...","object":"chat.completion.chunk","created":1789516800,"model":"gpt-5.6-sol","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-9c2b...","object":"chat.completion.chunk","created":1789516800,"model":"gpt-5.6-sol","choices":[],"usage":{"prompt_tokens":14,"completion_tokens":19,"total_tokens":33},"askr":{"credits_charged":0.23}}
data: [DONE]
  • Lines starting with : are keepalive comments. Ignore them.
  • Frames are re-encoded to the OpenAI chunk shape. Provider-specific fields and reasoning deltas are not passed through.
  • The last data frame before [DONE] carries usage and askr.credits_charged.
  • Pictures from image-capable chat models arrive as delta.images. Images from chat.

Stopping early

Close the connection and the upstream call is cancelled immediately. You are charged for what was generated up to that point and nothing after it. The final usage frame will not arrive, so read the cost from your activity or the next GET /v1.

Headers we send

Response headers
Content-Type: text/event-stream; charset=utf-8
Cache-Control: no-cache, no-transform
Connection: keep-alive
X-Accel-Buffering: no