While Claude Code has become my coding assistant of choice, I don’t always want to be using a remotely hosted LLM. I recently found out it’s pretty easy to use Claude Code with a non-Anthropic hosted model. This allows you to use an alternative remote host like OpenAI, OpenRouter, or even a locally hosted model.

To point Claude Code at my LM Studio instance, which I use for local models, I can simply run:

ANTHROPIC_BASE_URL=http://localhost:1234 \
ANTHROPIC_AUTH_TOKEN=lmstudio \
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC \
claude --model qwen/qwen-coder-next

The speed on my MacBook Pro M4 Max with 128 GB of ram leaves a bit to be desired when compared to remote hosted options. I’m going to explore running smaller quant models for performance benefits.

Using OpenRouter

I have not used this myself but OpenRouter provides a Claude Code-compatible API that gives you access to. Simply point the base URL to OpenRouter:

OPENROUTER_API_KEY="<your-openrouter-api-key>" \
ANTHROPIC_BASE_URL=https://openrouter.ai/api/ \
# yes, again
ANTHROPIC_AUTH_TOKEN="<your-openrouter-api-key>" \
# Must be empty
ANTHROPIC_API_KEY=""
claude --model desired/model/name

See the official Open Router documentation for more information

Using OpenAI

I have also not used this approach before, but I’ve read that OpenAI requires a proxy/translation layer since Claude Code uses the Anthropic API format. We’d need to run some capablity layer like first claude-code-proxy which translates between the two API formats. Say the proxy ran on port 8080, we’d then run:

ANTHROPIC_BASE_URL=http://localhost:8080 \
ANTHROPIC_AUTH_TOKEN=your-openai-key \
claude --model gpt-4o