Streaming LLM Responses: Event Schemas for Claude, GPT, and Gemini

Compare server-sent event protocols, payload lifecycles, thinking deltas, and SDK handling across Claude, GPT-6, and Gemini APIs.

By ailog · Published Oct 3, 2026 · 6 min read · How we work
In short
  • All three major provider APIs rely on server-sent events over HTTP by setting stream parameters to true.
  • Claude organizes streaming responses into hierarchical content block stages with cumulative token tallies emitted in message deltas.
  • The OpenAI Responses API uses flat semantic events such as response.output_text.delta and defers moderation checks until generation ends.
  • Google’s Gemini Interactions API delivers incremental token fragments through step.delta payloads while exposing interaction convenience helpers.
  • Client SDKs provide accumulation methods to prevent HTTP timeouts when processing large output thresholds like 128000 tokens.

Streaming Architecture and Protocol Essentials

By default, standard generative language endpoints buffer the entire output sequence on the host infrastructure before dispatching a complete HTTP payload. For extended generations—especially requests allowing large generation budgets such as 128000 tokens—waiting for a finished message introduces notable user-facing latency and increases the risk of client connection timeouts. Enabling streaming shifts the delivery model to incremental push updates via standard server-sent events (SSE).

While each vendor exposes a parameter named stream set to true, the internal mechanics diverge across payload structure, state lifecycles, and delta granularity. Claude organizes outputs into structured content blocks bracketed by start, delta, and stop events. OpenAI’s Responses endpoint emits strongly typed semantic events that cover lifecycle state, tool calls, and text deltas. Google’s GenAI Interactions API processes tokens through step-level updates. Choosing an integration path requires understanding these event schemas, SDK accumulation behaviors, and how token accounting integrates with backend tracking. For calculating estimated cost impacts across high-volume streaming configurations, see the /tools/llm-api-cost-calculator/.

  • Transport protocol: Standard HTTP connections kept open via server-sent event (SSE) streams, alongside WebSocket alternatives where supported.
  • Activation trigger: Passing stream=true in the request payload or using dedicated client streaming helpers.
  • Delta handling: Parsing incoming fragments incrementally for immediate rendering or routing partial data to local validation logic.
  • Timeout prevention: Using streaming helpers internally during batch runs to avoid dropping connections on deep reasoning or lengthy text jobs.

Claude Messages API: Content Blocks and Cumulative Usage

Anthropic implements streaming within the Messages API via a strict sequence of SSE event types. The lifecycle initiates with message_start, which transmits an empty assistant message wrapper alongside initial token counts. Following the initiation event, Claude generates one or more discrete content blocks. Each block begins with content_block_start, delivers chunks through multiple content_block_delta occurrences, and concludes with content_block_stop. The transmission completes after emitting message_delta and message_stop.

curl https://api.anthropic.com/v1/messages \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -d '{
    "model": "claude-opus-5-5",
    "messages": [{"role": "user", "content": "Hello"}],
    "max_tokens": 256,
    "stream": true
  }'

Every content block carries an index integer matching its location in the final message array. Text updates arrive inside delta payloads labeled text_delta. When tool invocation occurs, deltas arrive as input_json_delta containing partial JSON string fragments. Current models emit complete key-value entries sequentially; these arrive in chunked fragments so parser libraries can ingest partial JSON before completion. Additionally, streaming thinking blocks deliver reasoning text through thinking_delta events, followed by an integrity verification signature_delta right before the content block finishes. If display: "omitted" is configured, thinking text is suppressed entirely, transmitting only an empty delta followed by the verification signature.

Token accounting requires explicit attention: the token metrics returned inside the usage property of message_delta events are cumulative rather than differential. For developers desiring complete message objects without handling manual event parsing, SDKs provide accumulation utilities—such as stream.get_final_message() in Python or stream.finalMessage() in TypeScript. These maintain open HTTP connections while assembling parsed objects identical to synchronous responses.

OpenAI Responses API: Semantic Event Lifecycles

OpenAI processes HTTP streaming on its Responses endpoint by emitting strongly typed semantic events across the stream lifecycle. Setting stream=true on a request using models like gpt-6-astra opens a stream that delivers structured notifications for every state transition instead of raw string chunks.

import { OpenAI } from "openai";
const client = new OpenAI();

const stream = await client.responses.create({
  model: "gpt-6-astra",
  input: [{ role: "user", content: "Say 'double bubble bath' ten times fast." }],
  stream: true,
});

for await (const event of stream) {
  if (event.type === "response.output_text.delta") {
    process.stdout.write(event.delta);
  } else if (event.type === "response.completed") {
    console.log("\nResponse completed.");
  }
}

The Responses API distinguishes lifecycle boundaries with granular event names. Essential events emitted during common text streaming pipelines include response.created, response.output_text.delta, and response.completed. Advanced execution paths emit specialized unions, such as response.function_call_arguments.delta for tool executions, as well as code interpreter and file search status updates.

An important operational consideration in production is content moderation. Partial output deltas streamed to end users cannot be evaluated comprehensively in flight. When automated moderation scores are requested as part of a generation call, the evaluation scores arrive only after the full model generation has completed. Teams handling sensitive workloads must account for this boundary when serving unbuffered tokens directly to client interfaces.

Gemini Interactions API: Step Deltas and Thinking Controls

The Google GenAI SDK and Interactions API architecture introduce a simplified structure for text and multimodal streaming. Using models like gemini-3.8-flash, passing stream=True in the interactions request yields an iterable stream where updates are surfaced inside step.delta events.

from google import genai

client = genai.Client()

stream = client.interactions.create(
    model="gemini-3.8-flash",
    input="Explain how AI works",
    stream=True
)
for event in stream:
    if event.event_type == "step.delta":
        if event.delta.type == "text":
            print(event.delta.text, end="")

On standard synchronous calls, developers often rely on the convenience property interaction.output_text, which concatenates trailing text blocks automatically. However, this convenience property omits preliminary text blocks separated by thoughts, tool calls, or media items. In streaming mode, handling multimodal or interleaved reasoning requires processing incoming step.delta events explicitly.

Gemini models frequently enable reasoning features by default. Developers can adjust latency and processing overhead using the generation_config map, setting thinking_level to values like low or adjusting max_output_tokens limits (for instance, setting a limit to 500). System instructions can be configured simultaneously using system_instruction to constrain output persona and structure before tokens begin streaming.

Cross-Provider Architectural and Protocol Comparison

While Claude, OpenAI, and Gemini all provide SSE streams over standard HTTP ports, their event schemas and payload mechanics vary significantly. Understanding these differences prevents integration errors when routing events through multi-model gateways or shared client frontends.

Feature / Dimension Claude (Messages API) OpenAI (Responses API) Gemini (Interactions API)
Primary Activation stream: true in JSON body stream: true in JSON body stream: true in JSON body
Text Delta Event content_block_delta (text_delta) response.output_text.delta step.delta (type: text)
Lifecycle Boundaries message_start / message_stop response.created / response.completed Stream initialization / completion
Tool Call Streaming input_json_delta (partial JSON chunks) response.function_call_arguments.delta Supported via step updates
Reasoning Deltas thinking_delta + signature_delta Supported via typed stream unions Configured via thinking_level
Token Usage Reporting Cumulative in message_delta Provided across terminal events Interactions metadata

Cost efficiency also varies widely across the model spectrum. For example, Claude Opus 5.5 lists at $4 per 1M input tokens and $20 per 1M output tokens, whereas Claude Sonnet 5.5 is priced at $2 for inputs and $10 for outputs. Within OpenAI’s offerings, GPT-6 Astra carries rates of $10 input and $50 output per 1M tokens, while GPT-6.1 Sol costs $2 input and $10 output. In the Gemini catalog, Gemini 3.8 Flash operates at $0.75 input and $3.75 output per 1M tokens, with Gemini 3.5 Flash at $1.5 input and $9 output. Detailed rate cards can be referenced at /tools/llm-api-pricing/.

Production Implementation Checklist for Streaming

Deploying streaming pipelines into user-facing production systems requires safeguards beyond simple text printing. Because streams maintain persistent HTTP sessions, connection resiliency and event parsing must be hardened against transient network faults.

  • Handle protocol-level error events: Listen explicitly for mid-stream error payloads, such as Claude’s overloaded_error (which mirrors an HTTP 529 non-streaming status).
  • Implement ping handlers: Ensure intermediary load balancers and reverse proxies do not drop idle streaming connections by processing keep-alive ping events.
  • Parse tool fragments safely: When aggregating tool parameters using input_json_delta or function arguments, utilize streaming JSON parsers or accumulate complete blocks prior to execution.
  • Defer moderation decisions: Remember that OpenAI moderation scores are returned only after the final generation step, requiring secondary safeguards if displaying real-time output.
  • Leverage SDK accumulators for long jobs: When executing large generation spans (such as max_tokens set to 128000), use built-in SDK aggregation helpers to avoid read timeouts while preserving complete message structures.
  • Account for cumulative usage fields: When tracking expenditure across Claude streams, take the final usage figure from message_delta rather than summing individual delta events.

For guidance on managing structured output constraints during generation tasks, review /posts/structured-outputs-across-claude-gpt-and-gemini-apis/, or examine /posts/function-and-tool-calling-across-claude-gpt-and-gemini/ to coordinate multi-turn tool calling workflows.

Sources
  1. Streaming messages
  2. Streaming API responses
  3. https://ai.google.dev/gemini-api/docs/text-generation

Related