Use DeepInfra models with the Anthropic Messages API, Claude Code, and the Anthropic SDK.
DeepInfra exposes an Anthropic-compatible Messages API. This means tools that target the Anthropic API — Claude Code, the Anthropic Python and TypeScript SDKs, and any framework with an Anthropic adapter — can point at DeepInfra and use open-source models.
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:
ANTHROPIC_DEFAULT_HAIKU_MODEL is used for lightweight background tasks like tab completions and commit messages. Pick a fast, cheap model here to keep costs low. The older ANTHROPIC_SMALL_FAST_MODEL variable is deprecated — use ANTHROPIC_DEFAULT_HAIKU_MODEL instead.
Streaming works the same as the Anthropic API — use stream=True (Python) or stream: true (JS/cURL):
with client.messages.stream( model="deepseek-ai/DeepSeek-V3", max_tokens=1024, messages=[{"role": "user", "content": "Write a short poem about open source."}],) as stream: for text in stream.text_stream: print(text, end="", flush=True)