Streaming

Set stream: true to receive OpenAI-style Server-Sent Events from /v1/chat/completions.

Request

curl https://ozeye.ai/v1/chat/completions \
  -H "Authorization: Bearer $OZEYE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mistral-small-latest",
    "stream": true,
    "messages": [
      {"role": "user", "content": "Stream a short product tagline."}
    ]
  }'

Event stream

data: {"choices":[{"delta":{"role":"assistant"},"index":0}]}
data: {"choices":[{"delta":{"content":"ozeye"},"index":0}]}
data: {"choices":[{"delta":{},"finish_reason":"stop","index":0}]}
data: [DONE]

Usage at the end of the stream

After data: [DONE] ozeye sends one more frame with the usage it billed, including prompt_tokens_details.cached_tokens when part of the prompt was served from a provider cache. Standard OpenAI clients stop reading at [DONE]; read until the connection closes to get it. stream_options.include_usage is not needed.

data: {"choices":[{"delta":{},"finish_reason":"stop","index":0}]}
data: [DONE]
data: {"usage":{"prompt_tokens":18,"completion_tokens":25,"total_tokens":43}}

Billing behavior

Streaming requests reserve an estimated amount before the first event is sent. When the stream finishes, ozeye finalizes actual usage and refunds unused reservation. If the provider fails before data is sent, the reservation is refunded.