AI Engineer Guide

How to use any OpenRouter AI models in Claude Code

OpenRouter now supports Anthropic API shapes which means now we can use any models (320+) that is available in OpenRouter with Claude Code.

Yeah! even the free ones (39+)

How to get started?

Just set these env variables before starting the Claude Code.

export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY="" # Important: Must be explicitly empty

By having this in ~/.bashrc or ~/.zshrc, you’ll be able to use Claude code with those models anywhere (global config)

If you want to set up project level then you can set it in .claude/settings.local.json

{
	"env": {
		"ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
		"ANTHROPIC_AUTH_TOKEN": "$YOUR_OPENROUTER_API_KEY",
		"ANTHROPIC_API_KEY": ""
	}
}

Note: ANTHROPIC_API_KEY needs to be set as empty string. If not the Claude Code will fallback to login flow.

Using custom models

By default, OpenRouter automatically maps to Anthropic models.

But if you want to use custom model then you can configure it.

export ANTHROPIC_DEFAULT_SONNET_MODEL="openai/gpt-5.2-codex-max"
export ANTHROPIC_DEFAULT_OPUS_MODEL="openai/gpt-5.2-pro"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="minimax/minimax-m2:exacto"

Reference

#Claude-Code #Openrouter

Stay Updated

Get the latest AI engineering insights delivered to your inbox.

No spam. Unsubscribe at any time.