GOPURAM

Streaming

The SSE wire format, chunk by chunk.

Set "stream": true and the response is text/event-stream, OpenAI wire format: each event is data: {json}, the stream ends with data: [DONE].

data: {"id":"gen-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

data: {"id":"gen-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"gen-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: {"id":"gen-…","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":9,"completion_tokens":12,"total_tokens":21,"cost":0.0000117}}

data: [DONE]

Any OpenAI SDK consumes this unchanged. Deltas you may receive:

FieldMeaning
delta.contentassistant text
delta.reasoningthinking text, when requested — see Reasoning
delta.tool_callsincremental tool-call fragments (index-stable; concatenate function.arguments)
finish_reasonstop, length, tool_calls, content_filter, or error

The final usage chunk

Exactly one chunk near the end has empty choices and a usage object — including cost, the actual USD charge for the request. This is always sent; you don't need to opt in with stream_options.

Mid-stream errors

If an upstream provider fails after streaming has begun, HTTP status can no longer change — the failure arrives in-band as a final event with finish_reason: "error" and an error object, followed by [DONE]:

{ "choices": [{ "index": 0, "delta": {}, "finish_reason": "error" }],
  "error": { "message": "Upstream provider connection failed mid-stream", "type": "api_error", "code": "provider_error" } }

Treat a chunk with error as terminal for the generation. Partial output you already received is yours; you are billed only for what was actually generated.

Disconnecting

Close the connection whenever you want — we cancel the upstream generation immediately. Usage is settled from what was generated up to that point.

Request id

Every response carries X-Gopuram-Request-Id (also the id on every chunk). Include it when reporting an issue and we can trace the exact request.