Anthropic-compatible streaming
Endpoint: POST /api/anthropic/v1/messages
This endpoint accepts Anthropic Messages API payloads and streams Anthropic SSE events (message_start
, content_block_start
, content_block_delta
, message_delta
, message_stop
). It is compatible with tools like Claude Code.
Request schema
model
(string) – requiredmessages
(array) – required, Anthropic-style content blocks are supported (text, image, tool_use, tool_result)stream
(boolean) – optional, must be booleanmax_tokens
(int > 0) – required by Anthropic modelstemperature
(0..1),top_p
(0..1),top_k
(int > 0)stop_sequences
(string[]),metadata
(object)thinking
(object),cache_control
(object)tool_choice
(string | object),tools
(array)parallel_tool_calls
(boolean)
Invalid shapes or incompatible values return HTTP 400 with a descriptive error.
Headers
x-api-key: $API_KEY
orAuthorization: Bearer $API_KEY
anthropic-version: 2023-06-01
(recommended)- Optional:
anthropic-beta
if you are opting into beta features
cURL (streaming)
curl -N -X POST "https://api.kushrouter.com/api/anthropic/v1/messages" \
-H "x-api-key: $API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-5-sonnet-20241022",
"messages": [{"role":"user","content":[{"type":"text","text":"Write a haiku about routers"}]}],
"max_tokens": 256,
"stream": true
}'
Streaming frames
Events are emitted with explicit event:
names per Anthropic spec. Example sequence:
:event: message_start
:data: {"type":"message_start","message":{...}}
:event: content_block_start
:data: {"type":"content_block_start","index":0,"content_block":{"type":"text"}}
:event: content_block_delta
:data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"..."}}
:event: message_delta
:data: {"type":"message_delta","delta":{}}
:event: message_stop
:data: {"type":"message_stop"}
Tool use is reported via content/tool events. If tools are invoked, you'll receive tool ids and JSON arguments in subsequent events; then send a follow-up request with tool_result
blocks to continue the conversation.
Errors
- 400 – invalid JSON or unknown/unsupported parameters
- 401 – missing or invalid API key
- 413 – payload too large
- 429 – rate limit exceeded (key or IP)
- 5xx – transient errors