Endpoint
| Endpoint | Description |
|---|---|
POST /anthropic/v1/messages | Create a message (chat completion) |
POST /anthropic/v1/messages/count_tokens | Count tokens for a message request |
Authentication
Both standard Anthropic authentication methods are supported:| Header | Example |
|---|---|
Authorization | Bearer $DEEPINFRA_TOKEN |
x-api-key | $DEEPINFRA_TOKEN |
anthropic-version and anthropic-beta headers as needed.
Using the Anthropic SDK
Using with Claude Code
Claude Code can use DeepInfra as its backend. To keep your normal Claude Code setup untouched, add a dedicated shell function to your~/.bashrc or ~/.zshrc:
deepinfra instead of claude to launch Claude Code via DeepInfra. Your regular claude command stays unchanged.
ANTHROPIC_SMALL_FAST_MODEL is used for lightweight tasks like tab completions and commit messages. Pick a fast, cheap model here to keep costs low.Streaming
Streaming works the same as the Anthropic API — usestream=True (Python) or stream: true (JS/cURL):
Token counting
Count the tokens in a message request before sending it:Notes
- You are running open-source models via the Anthropic protocol, not Anthropic’s Claude models.
- Model names use DeepInfra identifiers (e.g.
deepseek-ai/DeepSeek-V3), not Anthropic model names. - Not all Anthropic-specific features may be supported. Standard message creation, streaming, and token counting work as expected.
Chat Completions
Use the OpenAI-compatible API instead.
Authentication
API keys and scoped JWTs.