Anthropic API Compatibility
LLM API provides a native Anthropic-compatible endpoint at /v1/messages for
Claude-family models and DeepSeek models that expose an Anthropic-compatible
surface. It is especially useful for applications designed for Claude.
Overview
The Anthropic endpoint forwards requests in Anthropic's own Messages format to a
provider that serves it natively, and returns the provider's Anthropic-format
response. Request fields such as cache_control, thinking, and tools reach the
model as you wrote them. This means you can:
- Maintain existing code that uses Anthropic's SDK or API format
- Use Claude models from Anthropic or Bedrock, and compatible DeepSeek models
- Leverage LLM API's routing, fallback, prompt caching, and cost tracking
Models that have no Anthropic-format provider (for example Gemini or GPT models)
are rejected with 400; use /v1/chat/completions for those.
Basic Usage
Configuration for Claude Code
This endpoint is useful for configuring Claude Code to use supported Claude-family
and DeepSeek models through LLM API. For other models, use the OpenAI-compatible
chat endpoint. See the dedicated Claude Code integration guide
for the full walkthrough.
export ANTHROPIC_BASE_URL=https://api.llmapi.ai
# Authenticate with one of these (ANTHROPIC_AUTH_TOKEN preferred)
export ANTHROPIC_AUTH_TOKEN=llmapi_your_api_key_here
# export ANTHROPIC_API_KEY=llmapi_your_api_key_here
# Optional: override the default model for each tier
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-7"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-6"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5"
# now run claude!
claude
INFO
When ANTHROPIC_API_KEY is set, Claude Code prompts you to confirm the custom key on startup —
select Yes. Using ANTHROPIC_AUTH_TOKEN skips this prompt. If you are already logged into
Claude Code with an Anthropic account, run /logout first.
Choosing Models
Use a Claude-family or DeepSeek model from the models page.
To pin a supported model to a specific provider, prefix the model with the
provider name (for example, AWS Bedrock):
# Route the Sonnet tier through AWS Bedrock
export ANTHROPIC_DEFAULT_SONNET_MODEL="aws-bedrock/claude-sonnet-4-6"
# Use a DeepSeek model for the Opus tier
export ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek/deepseek-chat
Environment Variables
When configuring Claude Code or other Anthropic-compatible applications, you can use these environment variables:
ANTHROPIC_BASE_URL
Points Claude Code at LLM API.
- Example:
export ANTHROPIC_BASE_URL=https://api.llmapi.ai
ANTHROPIC_AUTH_TOKEN
Your LLM API key. Preferred over ANTHROPIC_API_KEY because it does not trigger Claude Code's custom-key confirmation prompt.
- Example:
export ANTHROPIC_AUTH_TOKEN=llmapi_your_api_key_here
ANTHROPIC_API_KEY
Alternative authentication variable. Claude Code will ask you to confirm the key on startup; answer Yes to use it. Only set one of ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY.
- Example:
export ANTHROPIC_API_KEY=llmapi_your_api_key_here
ANTHROPIC_DEFAULT_OPUS_MODEL
Model used for the Opus tier (highest capability).
- Example:
export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-4-7
ANTHROPIC_DEFAULT_SONNET_MODEL
Model used for the Sonnet tier (balanced).
- Example:
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-6
ANTHROPIC_DEFAULT_HAIKU_MODEL
Model used for the Haiku tier (small, fast background tasks).
- Example:
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5
# Example configuration
export ANTHROPIC_BASE_URL=https://api.llmapi.ai
export ANTHROPIC_AUTH_TOKEN=llmapi_your_api_key_here
export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-4-7
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-6
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5
Advanced Features
Making a manual request
curl -X POST "https://api.llmapi.ai/v1/messages" \
-H "Authorization: Bearer $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"messages": [
{"role": "user", "content": "Hello, how are you?"}
],
"max_tokens": 100
}'
Prompt caching
Anthropic's prompt caching
works unchanged: put cache_control at the top level, on tools, on system
blocks, or on message content blocks, exactly as in Anthropic's documentation.
Claude Code already does this, so its long system prompt and tool list are
cached automatically through LLM API.
curl -X POST "https://api.llmapi.ai/v1/messages" \
-H "Authorization: Bearer $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 256,
"system": [
{
"type": "text",
"text": "<long, stable instructions>",
"cache_control": { "type": "ephemeral" }
}
],
"messages": [{"role": "user", "content": "Today'"'"'s question"}]
}'
The response reports cache_creation_input_tokens on the first request and
cache_read_input_tokens on the ones that reuse the prefix. On AWS Bedrock, older
Claude models reject the top-level form — see Prompt caching
for the provider details.
Response Format
The endpoint returns responses in Anthropic's message format:
{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-4-6",
"content": [
{
"type": "text",
"text": "Hello! I'm doing well, thank you for asking. How can I help you today?"
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 13,
"output_tokens": 20
}
}