Anthropic-compatible API
CodeGate exposes Anthropic's Messages protocol natively at /v1/messages. Request and response shapes match the Anthropic reference, so any client that speaks the Messages format (including Claude Code and the official Anthropic SDKs) will work by pointing at a different base URL.
- Base URL:
https://codegate.dev - Endpoint:
POST /v1/messages - Auth:
x-api-key: sk-...plusanthropic-version: 2023-06-01 - Content-Type:
application/json
POST /v1/messages
Minimal request:
curl https://codegate.dev/v1/messages \
-H "x-api-key: sk-..." \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4-8",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Say hello."}
]
}'Response:
{
"id": "msg_01ABC...",
"type": "message",
"role": "assistant",
"model": "claude-opus-4-8",
"content": [
{"type": "text", "text": "Hello."}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 8,
"output_tokens": 2
}
}Required headers
| Header | Value | Purpose |
|---|---|---|
x-api-key | sk-... | Your CodeGate key |
anthropic-version | 2023-06-01 | Protocol version pinning |
content-type | application/json | Request body format |
If you forget anthropic-version, some SDKs will still work but the upstream may reject the request. Always send it.
Request shape
Key fields:
model, a Claude model ID. See Models and Pricing.messages, an array of{role, content}pairs.roleisuserorassistant.contentis a string or a rich content array.max_tokens, the maximum number of tokens in the response. Required.system, optional. A system prompt string or content array.temperature,top_p,top_k, optional sampling controls.stop_sequences, optional array of strings to stop generation on.stream, set totrueto receive Server-Sent Events.tools, optional array of tool definitions for tool use.
Streaming (SSE)
curl -N https://codegate.dev/v1/messages \
-H "x-api-key: sk-..." \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4-8",
"max_tokens": 512,
"stream": true,
"messages": [{"role": "user", "content": "Count to five slowly."}]
}'The stream emits Anthropic's native SSE event types in order:
message_start, an empty message envelope with usage counters.content_block_start, a new content block is beginning.content_block_delta, a chunk of text or partial tool input.content_block_stop, the block is finished.message_delta, updates tostop_reason,usage, and other message-level fields.message_stop, end of stream.
Any client that already parses this stream format works unchanged.
Tool use
Tool use is passed through end-to-end. Define tools as usual:
{
"model": "claude-opus-4-8",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Get the current weather for a city.",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
],
"messages": [
{"role": "user", "content": "What is the weather in Amsterdam?"}
]
}The model returns a tool_use content block. Send the tool result back in the next turn as a tool_result block. Full round-trip semantics are identical to Anthropic's direct API.
Errors
Errors are returned in Anthropic's shape:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "messages: at least one message is required"
}
}See the API overview for a status code cheat sheet.
Notes
- Use the bare host
https://codegate.dev. There is no separateapi.subdomain. - CodeGate does not modify the request body before forwarding to the upstream provider (beyond routing and auth). What you send is what Claude sees.
- Response shape matches Anthropic verbatim, including
stop_reasonvalues and streaming event types.
Next
- Claude Code walkthrough for the canonical client.
- Models and Pricing for Claude per-token cost.