Streaming Behavior
Streaming Behavior
Section titled “Streaming Behavior”When a client asks ProxAI for a streamed response, ProxAI preserves the upstream Server-Sent Events (SSE) byte stream while observing protocol events. From a user perspective, three things matter: the stream eventually ends, errors arrive in a readable shape, and stalled tool calls do not hang forever.
What a healthy stream looks like
Section titled “What a healthy stream looks like”Each provider protocol has its own terminal event. ProxAI considers a stream complete only when the expected terminal event arrives. This implements Behavior Contract C19.
OpenAI Responses
Section titled “OpenAI Responses”- 1
response.createdStream starts.
- 2
response.output_item.addedA new output item begins (message, reasoning, function_call, etc.).
- 3
response.output_text.delta / response.function_call_arguments.deltaIncremental text or tool-call argument bytes.
- 4
response.output_item.doneOutput item is complete.
- 5
response.completedTerminal event. The stream is complete.
OpenAI Chat Completions
Section titled “OpenAI Chat Completions”- 1
chat.completion.chunkDelta chunks for content, tool calls, and finish_reason.
- 2
[DONE]Terminal sentinel. Without it, EOF is treated as an incomplete stream.
Anthropic Messages
Section titled “Anthropic Messages”- 1
message_startStream starts.
- 2
content_block_start / content_block_delta / content_block_stopA content block (text, thinking, tool_use, etc.) is produced incrementally.
- 3
message_deltaCarries stop_reason, stop_sequence, usage, and other message-level deltas.
- 4
message_stopTerminal event. The stream is complete.
Stalled tool calls
Section titled “Stalled tool calls”If a provider starts streaming function/tool arguments but never finishes them, ProxAI can close the stream with a protocol-shaped error instead of hanging the client forever. This is controlled by:
[tool_calls]timeout_secs = 120The timeout is semantic, not a total request timeout. It only applies after tool-call argument streaming has started. This implements Behavior Contract C20.
Common symptoms
Section titled “Common symptoms”- Upstream started tool arguments but did not send the matching done event.
- Provider stalled while the raw HTTP stream stayed open.
- Lower or tune `[tool_calls].timeout_secs`.
- Enable `upstream_response` capture for one request.
- Check the recent SSE tail in diagnostics.
- Missing terminal event such as `[DONE]`, `response.completed`, or `message_stop`.
- Upstream connection closed before the protocol state was complete.
- Check stream outcome logs.
- Compare the provider event timeline with the expected terminal event.
- Capture the upstream response bytes.
- You are interpreting partial byte chunks as complete UTF-8 text.
- A tool is slicing raw bytes as a string.
- Decode only complete SSE event data.
- Keep scanning byte-oriented.
- Avoid direct string slicing on arbitrary chunks.