Skip to main content
Every text endpoint supports streaming. The format is Server-Sent Events (SSE) — the gateway pipes the model’s native stream 1:1 so your SDK’s existing parser works unchanged.

Per-protocol shape

Pass "stream": true in the body. Event names match Anthropic’s native protocol:

Headers ship before the first SSE frame

Quota + rate-limit headers are sent in the HTTP response headers, before the first event. You can short-circuit a too-expensive stream by closing the connection after reading headers:
Closing the connection mid-stream is a hard abort — the model sees a client disconnect, billing settles on the partial output. For Anthropic / OpenAI text streams, that’s all the output_tokens consumed up to the abort point.

Aborting cleanly

If you have a long-running stream you want to cut off (user clicked stop), just close the HTTP connection — there’s no separate “abort” call. The gateway propagates the disconnect to the model, billing settles on partial output. For video generation (async via /v1/tasks/submit), use POST /v1/tasks/cancel instead — closing the submit response doesn’t cancel the in-flight render.

Mid-stream errors

If the model fails partway through, the gateway emits a final event: error (Anthropic) or terminal frame with error field (OpenAI) and closes the connection. The partial output you’ve already received is yours — but the request does not bill in the mid-stream-error case. Failures don’t bill ever, full stop.

Reconnecting

SSE supports the Last-Event-ID header for reconnects, but ByteSpike does not stage streams server-side — there’s nothing to replay. If your connection drops mid-stream, you’ll need to resend the request from scratch. For long completions where flakiness is a concern, prefer non-streaming mode with a generous client timeout, or use Anthropic’s prompt caching to make retries cheap.

SDK behaviour

All three official SDKs handle streaming automatically:
The base URL override on each SDK (covered in Configure your client) routes all three to ByteSpike transparently.

Common gotchas