---
title: "Claude Code with DeepSeek, GLM or any OpenAI API | BroadRouter"
description: "Claude Code speaks the Anthropic Messages API. How to run it on open models through a LiteLLM proxy or a native endpoint, and what breaks along the way."
url: https://broadrouter.com/blog/claude-code-with-openai-compatible-models/
lang: en
updated: 2026-11-15
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# Claude Code with open models: proxies, native endpoints and limits

By the BroadNet Inference team · 6 min read · Published 2026-11-15

Claude Code sends Anthropic Messages API requests to ANTHROPIC\_BASE\_URL. To use an OpenAI-compatible provider, run a translating proxy such as LiteLLM and point Claude Code at it, or pick a provider with its own Anthropic-format endpoint, such as DeepSeek or Z.ai. Anthropic does not support non-Claude models in Claude Code, so test tools, caching and context limits yourself.

## Key takeaways

-   Claude Code calls /v1/messages in the Anthropic format. An OpenAI-compatible API needs a translating proxy in between; LiteLLM documents this setup.
-   DeepSeek and Z.ai publish Anthropic-format base URLs, so Claude Code can call them without a proxy.
-   Anthropic's docs say it does not support routing Claude Code to non-Claude models through any gateway. You own the testing.
-   On BroadNet, tool calling is documented for GLM 5.3 and Qwen3.8 27B only. Claude Code depends on tools, so use one of those two.
-   Agents that accept an OpenAI-compatible base URL directly, such as opencode, Cline and Aider, need no proxy and are simpler.

**On this page**

1.  Why can’t Claude Code call an OpenAI-compatible API directly?
2.  What are your three options?
3.  How do you run Claude Code through LiteLLM?
4.  Which DeepSeek and GLM endpoints work without a proxy?
5.  What breaks or changes on a non-Claude model?
6.  Which BroadNet model should sit behind Claude Code?
7.  Can you use BroadNet’s flat-rate plan with Claude Code?
8.  When is a different agent the better choice?
9.  Where BroadNet Inference fits

Claude Code sends every request in the Anthropic Messages API format, to `/v1/messages` on whatever `ANTHROPIC_BASE_URL` points at. Most open-model providers, BroadNet Inference included, speak the OpenAI format instead. So you need either a proxy that translates between the two, or a provider that publishes its own Anthropic-format endpoint. This post covers both, plus the limits that decide whether it is worth doing.

## Why can’t Claude Code call an OpenAI-compatible API directly?

Claude Code’s gateway compatibility guide lists the formats a gateway must expose. For a plain base URL, that is Anthropic Messages: `/v1/messages`, with `/v1/messages/count_tokens` optional, and the `anthropic-beta` and `anthropic-version` headers forwarded. An [OpenAI-compatible API](https://broadrouter.com/glossary/openai-compatible-api/) serves `/v1/chat/completions` with a different request and response shape. Point Claude Code straight at one and the requests fail.

One more thing to know before you start. Claude Code’s own docs say Anthropic “doesn’t support routing Claude Code to non-Claude models through any gateway.” Many people do it anyway, but nobody at Anthropic will debug it for you.

## What are your three options?

| Route | How it works | Best for | Trade-off |
| --- | --- | --- | --- |
| Translating proxy (LiteLLM) | Claude Code talks Anthropic format to a local proxy; the proxy calls the OpenAI-compatible provider | Using a specific OpenAI-compatible provider, such as BroadNet | One more process to run and update; translation gaps |
| Native Anthropic-format endpoint | The provider accepts `/v1/messages` itself | DeepSeek or GLM models from their makers | Each maps or ignores some fields |
| A different agent | Use an agent that takes an OpenAI-compatible base URL | Anyone who doesn’t need Claude Code specifically | You give up Claude Code’s interface and features |

## How do you run Claude Code through LiteLLM?

LiteLLM’s tutorial for non-Anthropic models works like this: install the proxy, define models in `config.yaml`, start it, then set two variables in Claude Code. LiteLLM translates between formats, so Claude Code keeps sending Anthropic requests.

Define the BroadNet models the same way as in the [LiteLLM guide](https://broadrouter.com/guides/litellm-proxy-custom-provider/), with the `openai/` prefix and `api_base`:

```yaml
model_list:
  - model_name: glm
    litellm_params:
      model: openai/broadnet/glm-5.3
      api_base: https://inference.broadnet.ai/v1
      api_key: os.environ/BROADNET_API_KEY
      rpm: 30
  - model_name: qwen
    litellm_params:
      model: openai/broadnet/qwen3.8-27b
      api_base: https://inference.broadnet.ai/v1
      api_key: os.environ/BROADNET_API_KEY
      rpm: 30

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
```

Start the proxy:

```bash
uv tool install 'litellm[proxy]'
export BROADNET_API_KEY='your-broadnet-key'
export LITELLM_MASTER_KEY='sk-any-local-secret'
litellm --config config.yaml   # listens on http://0.0.0.0:4000
```

Then point Claude Code at it. `ANTHROPIC_AUTH_TOKEN` goes out as an `Authorization: Bearer` header, which is what LiteLLM reads:

```bash
export ANTHROPIC_BASE_URL=http://0.0.0.0:4000
export ANTHROPIC_AUTH_TOKEN="$LITELLM_MASTER_KEY"
export ANTHROPIC_MODEL=glm                  # main model
export ANTHROPIC_DEFAULT_HAIKU_MODEL=qwen   # background tasks
export ANTHROPIC_DEFAULT_SONNET_MODEL=glm   # the sonnet alias
export ANTHROPIC_DEFAULT_OPUS_MODEL=glm     # the opus alias
export CLAUDE_CODE_SUBAGENT_MODEL=glm       # subagents
claude
```

Run `/status` in Claude Code. The `Anthropic base URL` line should show the proxy address.

The model variables matter. LiteLLM’s Claude Code page warns that picking a built-in Claude name that your config doesn’t define fails with “Invalid model name passed in”. Claude Code’s env-vars reference says `ANTHROPIC_DEFAULT_HAIKU_MODEL` is also used for background functionality, so map it too, or background requests ask for a Haiku name the proxy doesn’t know. `CLAUDE_CODE_SUBAGENT_MODEL` sets the default model for subagents, but a model Claude passes when it spawns one, often an alias such as `sonnet` or `haiku`, takes precedence. Mapping the `sonnet` and `opus` aliases as well means those requests still resolve to a model the proxy knows. Keep your BroadNet key in the proxy’s environment, never in a project’s committed `.claude/settings.json`.

## Which DeepSeek and GLM endpoints work without a proxy?

Two model makers publish Anthropic-format base URLs:

| Provider | Base URL | Model handling (from their docs, checked 2026-11-15) |
| --- | --- | --- |
| DeepSeek | `https://api.deepseek.com/anthropic` | `claude-sonnet*` and `claude-haiku*` names map to `deepseek-flash`; `claude-opus*` maps to `deepseek-v4-pro`; names not starting with `claude` return 400 |
| Z.ai (GLM Coding Plan) | `https://api.z.ai/api/anthropic` | Key in `ANTHROPIC_AUTH_TOKEN`; the manual example maps Opus and Sonnet to `glm-5.3[1m]` and Haiku to `glm-5.3-flash[1m]` |

DeepSeek’s release note of 10 September 2026 says `deepseek-flash` serves DeepSeek-V4.1-Flash. Its Anthropic API page also lists what it ignores: `cache_control`, `budget_tokens`, `disable_parallel_tool_use` and the `anthropic-version` header, among others. On `deepseek-flash`, images in assistant messages return 400, and `deepseek-v4-pro` replaces images with “\[Unsupported Image\]”.

If you only want DeepSeek or GLM in Claude Code, these native endpoints are the shortest path. Prices and plan limits for both are compared in the [Claude API alternatives page](https://broadrouter.com/alternatives/anthropic-api-alternative/).

## What breaks or changes on a non-Claude model?

Translation keeps requests flowing, but several Claude Code features depend on things a proxy or another model may not pass through. Claude Code’s docs name these:

-   **Prompt caching.** Claude Code marks `system` and message blocks with `cache_control`. If the gateway or upstream drops it, there is no error, but every turn bills as uncached input. On an OpenAI-compatible upstream, caching follows that provider’s own rules instead. BroadNet bills [cached input](https://broadrouter.com/glossary/cached-input-tokens/) at a lower price when its usage block reports a cache hit; check `cached_tokens` in your logs.
-   **Token counting.** Without `/v1/messages/count_tokens`, Claude Code falls back to a character-based estimate, so `/context` is approximate.
-   **Context window.** Claude Code applies its own default window to model names it doesn’t recognise. Set `CLAUDE_CODE_AUTO_COMPACT_WINDOW` (100,000 to 1,000,000 tokens) to fit the model. For Qwen3.8 27B, with a 262,144-token context, set it well below that.
-   **Unknown fields.** A `400` naming `Extra inputs are not permitted` or an `anthropic-beta` value means something upstream rejected a pre-release field. The docs suggest `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`.
-   **Thinking.** `MAX_THINKING_TOKENS` and adaptive thinking are Claude features. On BroadNet, DeepSeek V4.1 Flash, GLM 5.3 and Qwen3.8 27B reason before they answer, and those [reasoning tokens](https://broadrouter.com/glossary/reasoning-tokens/) count toward `max_tokens`. If answers come back empty, raise the output limit or send `reasoning_effort` low. See [why reasoning models return empty answers](https://broadrouter.com/guides/reasoning-tokens-empty-response/).
-   **Images.** GLM 5.3 is text-only on BroadNet. Use Qwen3.8 27B if you paste screenshots.

Test a real task end to end, with file edits, shell commands and a long session, before you rely on it.

## Which BroadNet model should sit behind Claude Code?

Claude Code reads files, edits them and runs commands through [tool calls](https://broadrouter.com/glossary/tool-calling/). BroadNet’s API reference documents tools, structured output and reasoning for two models:

| Model | Input / output per 1M tokens | Context | Images | Tools documented |
| --- | --- | --- | --- | --- |
| [GLM 5.3](https://broadrouter.com/models/glm-5.3/) | $0.78 / $3.46 | 1,048,576 | No | Yes |
| [Qwen3.8 27B](https://broadrouter.com/models/qwen3.8-27b/) | $0.175 / $2.17 | 262,144 | Yes | Yes |
| [DeepSeek V4.1 Flash](https://broadrouter.com/models/deepseek-v4.1-flash/) | $0.175 / $0.52 | 1,048,576 | Yes | Not documented |

GLM 5.3 is the natural main model for large repositories. Qwen3.8 27B costs less per input token and works for images and lighter background calls. Both need a top-up; they are not covered by the $5 starting credit. The [GLM 5.3 vs Qwen3.8 27B comparison](https://broadrouter.com/compare/glm-5.3-vs-qwen3.8-27b/) has the side-by-side.

## Can you use BroadNet’s flat-rate plan with Claude Code?

Not as a documented fit, and it’s better to know that before buying. The Full Moon, Orbit and Meteor plans cover DeepSeek V4.1 Flash only, and BroadNet does not document tool calling for it. Each [plan session](https://broadrouter.com/guides/unlimited-llm-api-sessions/) also runs one request at a time. Claude Code can run subagents and background tasks alongside the main loop, and those requests would queue on one session.

If a flat price is what you want, use an agent that BroadNet documents with the plan, such as [Aider](https://broadrouter.com/guides/aider-unlimited-deepseek/). For Claude Code, use pay-as-you-go GLM 5.3 or Qwen3.8 27B, which allow 30 requests a minute and 4 in flight per key. Back off on 429 as in [errors and retries](https://broadrouter.com/guides/errors-and-retries/).

## When is a different agent the better choice?

If you don’t need Claude Code itself, skip the proxy. opencode, Cline, Roo Code, Continue and Aider all take an OpenAI-compatible base URL, a key and a model ID directly. The field names for each are in [use open models in coding agents](https://broadrouter.com/blog/use-open-models-in-coding-agents/), with setup guides for [opencode](https://broadrouter.com/guides/opencode-custom-provider/) and [Cline](https://broadrouter.com/guides/cline-openai-compatible/). Fewer moving parts means fewer translation bugs. To compare models for this work, see [best open model for coding agents](https://broadrouter.com/blog/best-open-model-for-coding-agents/).

Stay on Claude models if your work depends on Claude-specific features such as extended thinking, Anthropic prompt caching or the newest Claude Code betas. In that case, [cut costs inside Claude Code](https://broadrouter.com/blog/cut-coding-agent-llm-costs/) rather than swapping the model.

## Where BroadNet Inference fits

BroadNet Inference is an OpenAI-compatible API, so it reaches Claude Code only through a proxy such as LiteLLM. Behind one, GLM 5.3 and Qwen3.8 27B are the two models with documented tool calling, billed per token with no content retained after the request. If you want a native Anthropic-format endpoint, DeepSeek and Z.ai are simpler. If you want BroadNet’s flat plan, pair it with an agent that speaks the OpenAI format.

Free tools for this

-   [Agent run cost estimator](https://broadrouter.com/tools/agent-run-cost-estimator/) Context growth per step, total tokens and cost of one agent run, with a DeepSeek session comparison.
-   [LLM batch job planner](https://broadrouter.com/tools/llm-batch-job-planner/) Run time, binding limit, cost per model and the flat sessions needed to finish a big job by a deadline.
-   [Flat-rate vs per-token LLM cost calculator](https://broadrouter.com/tools/flat-rate-vs-per-token-calculator/) Break-even between an unlimited plan and paying per token, per agent.
-   [LLM rate limit and concurrency calculator](https://broadrouter.com/tools/llm-rate-limit-calculator/) Which limit binds first: RPM, TPM or concurrency, with Little's law.

[All free tools](https://broadrouter.com/tools/)

## Terms in this article

[Token](https://broadrouter.com/glossary/token/)

A token is the unit of text a language model reads and writes: a word, part of a word, a punctuation mark or a byte sequence produced by the model's tokenizer. LLM APIs count, limit and usually bill usage in tokens.

[Base URL](https://broadrouter.com/glossary/base-url/)

A base URL is the fixed root address of an API, such as https://api.example.com/v1, that a client puts in front of every endpoint path, such as /chat/completions. In OpenAI-compatible SDKs, changing the base URL, together with the API key and model ID, points the same code at a different provider.

[Tool calling](https://broadrouter.com/glossary/tool-calling/)

Tool calling, also called function calling, is an LLM API feature in which the model returns a structured request to run a function the developer has defined, with JSON arguments. The application runs the function and sends the result back; the model never runs code itself.

[OpenAI-compatible API](https://broadrouter.com/glossary/openai-compatible-api/)

An OpenAI-compatible API is an HTTP API that accepts the same request and response formats as the OpenAI API, such as POST /v1/chat/completions, so OpenAI SDKs and tools can use it by changing only the base URL, the API key and the model name.

[Pay-as-you-go](https://broadrouter.com/glossary/pay-as-you-go/)

Pay-as-you-go is a pricing model in which you pay only for what you use, metered per unit such as tokens, requests or audio minutes, with no subscription or minimum commitment. Most LLM APIs bill this way, from a prepaid balance or a periodic invoice.

[AI coding agent](https://broadrouter.com/glossary/coding-agent/)

An AI coding agent is a software tool in which a language model works on a codebase in a loop: it reads files, edits them, runs commands such as tests, reads the output and decides the next step until the task is done or a limit is reached.

[Cached input tokens](https://broadrouter.com/glossary/cached-input-tokens/)

Cached input tokens are prompt tokens that an LLM provider has recently processed and can reuse from a cache instead of computing again, usually a repeated prefix such as a system prompt or document. Providers bill them at a lower rate than new input tokens.

[Open-weight model](https://broadrouter.com/glossary/open-weight-model/)

An open-weight model is a machine learning model whose trained weights are published for anyone to download and run, usually under a licence with conditions. It differs from fully open-source AI, which also releases the training code and detailed information about the training data, so others can study and reproduce the model.

## Questions

### Can Claude Code use DeepSeek?

Yes, in two ways. DeepSeek publishes an Anthropic-format base URL, https://api.deepseek.com/anthropic, that maps claude-sonnet and claude-haiku names to deepseek-flash and claude-opus names to deepseek-v4-pro. Or you put a translating proxy such as LiteLLM in front of any OpenAI-compatible host of DeepSeek models.

### Does Claude Code work with an OpenAI-compatible API?

Not directly. Claude Code sends Anthropic Messages API requests to /v1/messages. A proxy such as LiteLLM accepts those requests and forwards them to an OpenAI-style /chat/completions endpoint, then translates the reply back.

### Is using Claude Code with other models supported by Anthropic?

No. Claude Code's gateway docs say Anthropic does not support routing Claude Code to non-Claude models through any gateway. It works in practice for many people, but bugs on that path are yours to debug.

### Which BroadNet model should I use behind Claude Code?

GLM 5.3 or Qwen3.8 27B. BroadNet documents tool calling for those two only, and Claude Code edits files and runs commands through tools. GLM 5.3 has a 1,048,576-token context; Qwen3.8 27B has 262,144 and accepts images.

### Can I run Claude Code on BroadNet's unlimited plan?

Not as a documented fit. The flat plans cover DeepSeek V4.1 Flash only, and BroadNet does not document tool calling for that model. A plan session also runs one request at a time, while Claude Code can run subagents in parallel.

### Why does Claude Code say Invalid model name through LiteLLM?

Claude Code asked for a model name your config.yaml does not define, often a built-in Claude alias or the background Haiku model. Set ANTHROPIC\_MODEL and ANTHROPIC\_DEFAULT\_HAIKU\_MODEL to names from your model\_list.

## Keep reading

-   [Use open models in coding agents: Aider, Cline, opencode, Codex](https://broadrouter.com/blog/use-open-models-in-coding-agents/)
-   [Tool calling with open models: schemas, parallel calls, retries](https://broadrouter.com/blog/tool-calling-open-models/)
-   [Best open model for coding agents: pick by tools, context and cost](https://broadrouter.com/blog/best-open-model-for-coding-agents/)
-   [10 ways to cut coding agent LLM costs, with estimated savings](https://broadrouter.com/blog/cut-coding-agent-llm-costs/)
-   [How to run parallel coding agents on a flat-rate LLM API](https://broadrouter.com/blog/run-parallel-coding-agents-flat-rate/)
-   [OpenClaw and Hermes Agent on a cheap model: setup and token math](https://broadrouter.com/blog/openclaw-hermes-agent-cheap-model/)
-   [Prompt injection in coding agents: defences that actually hold](https://broadrouter.com/blog/prompt-injection-coding-agents/)
-   [Guide: Route LiteLLM to BroadNet Inference (SDK and proxy)](https://broadrouter.com/guides/litellm-proxy-custom-provider/)
-   [Guide: Add BroadNet Inference to opencode as a custom provider](https://broadrouter.com/guides/opencode-custom-provider/)
-   [Guide: Use Cline with BroadNet Inference (OpenAI Compatible provider)](https://broadrouter.com/guides/cline-openai-compatible/)
-   [Guide: Run Aider on unlimited DeepSeek V4.1 Flash](https://broadrouter.com/guides/aider-unlimited-deepseek/)
-   [Guide: Why a reasoning model returns an empty answer](https://broadrouter.com/guides/reasoning-tokens-empty-response/)

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=blog-claude-code-with-openai-compatible-models&utm_content=page-cta) ·

**Sources**

-   [Claude Code docs, other LLM gateways: no support for non-Claude models (checked 2026-11-15)](https://code.claude.com/docs/en/llm-gateway)
-   [Claude Code docs, connect to an LLM gateway: ANTHROPIC\_BASE\_URL, ANTHROPIC\_AUTH\_TOKEN, troubleshooting (checked 2026-11-15)](https://code.claude.com/docs/en/llm-gateway-connect)
-   [Claude Code docs, gateway compatibility guide: /v1/messages, cache\_control pass-through (checked 2026-11-15)](https://code.claude.com/docs/en/llm-gateway-protocol)
-   [Claude Code docs, environment variables (checked 2026-11-15)](https://code.claude.com/docs/en/env-vars)
-   [LiteLLM docs, use Claude Code with non-Anthropic models (checked 2026-11-15)](https://docs.litellm.ai/docs/tutorials/claude_non_anthropic_models)
-   [LiteLLM docs, Claude Code client setup: ANTHROPIC\_MODEL and Invalid model name (checked 2026-11-15)](https://docs.litellm.ai/docs/proxy/client_setup/claude_code)
-   [DeepSeek API docs, Anthropic API: base URL, model mapping, ignored fields (checked 2026-11-15)](https://api-docs.deepseek.com/guides/anthropic_api)
-   [DeepSeek news, DeepSeek-V4.1-Flash release, model name deepseek-flash (September 10, 2026; checked 2026-11-15)](https://api-docs.deepseek.com/news/news260910)
-   [Z.ai docs, GLM Coding Plan in Claude Code (checked 2026-11-15)](https://docs.z.ai/devpack/tool/claude)
-   [BroadNet Inference API reference: models, tools, reasoning, limits (checked 2026-11-15)](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=blog-claude-code-with-openai-compatible-models&utm_content=sources)
