Anthropic-compatible API for Claude
Authenticate requests with your API key.
The /v1/messages endpoint accepts the Anthropic Messages API format. To connect the Anthropic SDK or Claude Code, set the GPTunneL base URL and your API key.
Claude Request
Section titled “Claude Request”https://gptunnel.ru/v1/messagesRequest headers
| Parameter | Type | Description |
|---|---|---|
x-api-key* | string | Pass the API key as the value of x-api-key. Alternatively, send the header Authorization: Bearer YOUR_API_KEY. |
anthropic-version | string | API Anthropic version, transmitted as it is |
content-type* | string | application/json |
Send a standard Anthropic request body, including fields such as model, messages, system, tools, tool_choice, and stream. GPTunneL validates the fields it uses and forwards the rest, with the exceptions described below.
Example request
Section titled “Example request”Set the GPTUNNEL_API_KEY environment variable. This example requests claude-5.5-haiku.
import jsonimport osfrom urllib.request import Request, urlopen
body = { 'model': 'claude-5.5-haiku', 'max_tokens': 64, 'messages': [{'role': 'user', 'content': 'Сколько будет 2 + 2? Ответь цифрой.'}],}request = Request( 'https://gptunnel.ru/v1/messages', method='POST', headers={ 'x-api-key': os.environ['GPTUNNEL_API_KEY'], 'anthropic-version': '2023-06-01', 'Content-Type': 'application/json', }, data=json.dumps(body).encode('utf-8'),)with urlopen(request, timeout=30) as response: print(json.load(response)['content'])curl --fail-with-body --silent --show-error \ --url 'https://gptunnel.ru/v1/messages' \ --header "x-api-key: $GPTUNNEL_API_KEY" \ --header 'anthropic-version: 2023-06-01' \ --json '{ "model": "claude-5.5-haiku", "max_tokens": 64, "messages": [{"role": "user", "content": "Сколько будет 2 + 2? Ответь цифрой."}] }'const response = await fetch('https://gptunnel.ru/v1/messages', { method: 'POST', headers: { 'x-api-key': process.env.GPTUNNEL_API_KEY, 'anthropic-version': '2023-06-01', 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'claude-5.5-haiku', max_tokens: 64, messages: [{ role: 'user', content: 'Сколько будет 2 + 2? Ответь цифрой.' }], }),})if (!response.ok) throw new Error(await response.text())console.log((await response.json()).content)Example response
Section titled “Example response”The response text is in the content array. In the model field, Claude may use its own spelling of the model ID. Here is an excerpt from a verified response.
{ "type": "message", "model": "claude-haiku-5-5", "content": [{ "type": "text", "text": "4" }], "stop_reason": "end_turn", "usage": { "input_tokens": 30, "output_tokens": 3 }}Format availability
Section titled “Format availability”The native route serves Claude models. Other models can use the Anthropic-compatible format when it is enabled for that model. If a model is unavailable on /v1/messages, check the catalog for your key and confirm which formats the model supports. For ordinary chat requests, use Chat Completions.
What we change in the body of a request
Section titled “What we change in the body of a request”GPTunneL forwards the request body to Anthropic with these changes:
| Change | Reason |
|---|---|
GPTunneL replaces metadata |
Anthropic accepts only user_id within this object. GPTunneL uses its own hash. |
GPTunneL removes service_tier |
The gateway does not offer Anthropic’s paid priority tier. |
When thinking is disabled, GPTunneL removes clear_thinking_* strategies from context_management.edits and drops context_management if no strategies remain |
Anthropic requires enabled or adaptive thinking for these strategies and rejects an empty edits array. |
For Haiku, GPTunneL removes thinking: {"type": "adaptive"} and output_config |
Haiku returns 400 for these options. |
GPTunneL removes code-execution-* values from anthropic-beta |
The gateway does not support code_execution. |
GPTunneL removes the [1m] suffix from the model ID |
Claude Code adds this suffix for extended context. |
The gateway also removes internal routing fields: provider, route, models, transforms, preset, and plugins.
Other fields are forwarded as supplied. Anthropic may return 400 for an unknown field. The request field allowlist applies only to the OpenAI-compatible /v1/chat/completions endpoint.
Streaming response
Section titled “Streaming response”Set "stream": true in the request body. A stream tested with claude-5.5-haiku returned message_start, then content_block_start, content_block_delta, and content_block_stop, followed by message_delta and message_stop. You may also receive ping events. Read the text from content_block_delta and finish reading the message on message_stop.
Token counting
Section titled “Token counting”https://gptunnel.ru/v1/messages/count_tokensReturns an estimate of the number of input tokens in the request body.
Custom tools defined with name and input_schema are forwarded unchanged. Supported Anthropic tools include web_search, web_fetch, computer, bash, and text_editor.
Requests that include code_execution return HTTP 400. Anthropic bills code execution by container runtime, while the gateway bills by token usage. For the same reason, GPTunneL removes code-execution-* values from the anthropic-beta header and forwards the other beta flags unchanged.
Structured output
Section titled “Structured output”GPTunneL forwards the schema in output_config to Claude unchanged. Supply a schema that meets Anthropic’s requirements, including additionalProperties where required.
Use this format to request strict JSON directly. On the OpenAI-compatible /v1/chat/completions endpoint, GPTunneL translates response_format into Anthropic options. The json_object mode has no native Anthropic equivalent.
For Haiku models, GPTunneL removes output_config because Anthropic would return HTTP 400.
Prompt caching
Section titled “Prompt caching”Your client sets cache breakpoints with cache_control. The response’s usage object includes cache_creation_input_tokens and cache_read_input_tokens. Reading from the cache costs less than standard input. Writing to the cache costs more.
For business-account API keys, the organization owner or administrator can enable Prompt caching in API under Business account → API. The option is off by default. While it is off, the gateway removes cache_control and bills the full prompt at the normal input rate. Caching is always available for personal accounts.
Errors
Section titled “Errors”Errors follow the Anthropic format. The HTTP status is accompanied by an error object containing type and message. Anthropic SDKs handle this format directly.
If you receive HTTP 403, check which models your key is allowed to use.
Both message requests and token-count requests can return HTTP 503 with error.type: "overloaded_error" when the service is temporarily unavailable. Wait before retrying.
See API error troubleshooting for more HTTP statuses and errors from other endpoints.