claude-code-api-streaming

Implement server-side Anthropic SSE streaming events for Claude Code gateway endpoints.

4|1|Updated Apr 29, 2026
One-click install
npx skills add https://github.com/ZipperCode/lingma2api --skill claude-code-api-streaming-zippercode
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: claude-code-api-streaming
Source: https://github.com/ZipperCode/lingma2api/tree/main/.claude/skills/claude-code-api-streaming
Command: npx skills add https://github.com/ZipperCode/lingma2api --skill claude-code-api-streaming-zippercode

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building an Anthropic-compatible gateway for Claude Code requires emitting the exact SSE event sequence (message_start, content_block_delta, message_delta, message_stop) that the client expects; missing or malformed events cause Claude Code to treat the stream as broken and fall back or fail. ## Core Features & Use Cases - Canonical Event Sequencing: Defines the required order of message_start, content_block_start/delta/stop, message_delta, and message_stop frames for text, tool_use, and thinking blocks. - Tool Use Streaming: Specifies how to stream tool calls via input_json_delta partial_json chunks and set stop_reason to tool_use so the client can execute tools and continue the loop. - Fallback & Bad-Stream Rules: Documents when Claude Code falls back to stream:false and which conditions (empty streams, missing message_start, timeouts, 404s) are treated as broken streams. - Use Case: You are adding a /v1/messages endpoint to an OpenAI-compatible proxy and need it to work with Claude Code; follow this Skill to emit correct Anthropic wire-format events and a consistent non-streaming JSON fallback. ## Quick Start Ask the AI to implement the /v1/messages streaming endpoint for the gateway following the claude-code-api-streaming event sequence and wire format reference.

Frequently Asked Questions about claude-code-api-streaming

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement Anthropic SSE streaming for a /v1/messages endpoint?

Emit SSE frames with Content-Type text/event-stream in this order: message_start, content_block_start, one or more content_block_delta events, content_block_stop, message_delta with final stop_reason and usage, then message_stop. Each frame needs both an event: line and a JSON data: payload.

How to stream tool_use blocks in the Anthropic Messages API?

Start with content_block_start containing a tool_use block with id, name, and empty input, then stream arguments as input_json_delta partial_json chunks that concatenate into valid JSON. Set message_delta stop_reason to tool_use so the client executes the tool and returns a tool_result.

Why does Claude Code treat my stream as broken and fall back?

Claude Code flags streams with zero events, missing message_start, incomplete content blocks without a stop reason, SSE creation returning 404, mid-stream disconnects, timeouts, or non-Anthropic JSON payloads. Ensure the full event sequence completes and errors return HTTP status codes instead of partial SSE.

Does the gateway need to support stream:false for Claude Code?

Yes, Claude Code may issue non-streaming requests after stream failures or for background tasks. The stream:false response must return a complete message JSON whose structure matches the aggregated final message from the streaming path.

What stop_reason values should message_delta include?

Common values are end_turn for normal completion, tool_use when the client must run a tool, max_tokens for truncation, stop_sequence when a stop sequence is hit, refusal, and model_context_window_exceeded. Omitting message_delta breaks final usage and stop_reason reporting.