LiteLLM Proxy with QCode: One Gateway for Claude, GPT and Chinese Models, with Virtual Keys and Budgets
As of 2026-11-25 (LiteLLM 1.111.0), you can put the open-source LiteLLM proxy in front of QCode with one config.yaml. Claude models use model: anthropic/<id> with api_base: https://api.qcode.cc/api. GPT and the Chinese models (GLM, Kimi, DeepSeek, Qwen) use model: openai/<id> with api_base: https://api.qcode.cc/openai/v1. Add Postgres and a master key, and the proxy can issue virtual keys with their own model lists, budgets and rate limits. Claude Code, Codex CLI and any OpenAI-compatible tool can then talk to the proxy instead of to QCode directly. A proxy is worth running when you need per-person model rules, fallbacks or your own logging. If all you need is separate keys, quotas and one bill for a small team, QCode's team plan sub-keys already do that without a server to maintain.
QCode is an independent third-party API service. It is not an official service of, or affiliated with, Anthropic, OpenAI, BerriAI (the LiteLLM maintainers), Zhipu, Moonshot, DeepSeek or Alibaba. LiteLLM option names below were checked against the 1.111.0 source and the LiteLLM docs.
Updated 2026-11-26
Key facts
- Claude upstream:
api_base: https://api.qcode.cc/api, without/v1. LiteLLM appends/v1/messagesitself, so.../api/v1ends up as/api/v1/v1/messagesand returns 404. - GPT and Chinese models upstream:
api_base: https://api.qcode.cc/openai/v1. LiteLLM appends/chat/completionsor/responses. - Endpoint rule at QCode: Claude only on the Anthropic endpoint, GPT only on the OpenAI endpoint, Chinese models on both. This guide sends the Chinese models through Chat Completions (the
openai/prefix). LiteLLM translates formats for the client, but the upstream route still has to match. - Virtual keys need a database:
DATABASE_URL=postgresql://...plus a master key (general_settings.master_keyorLITELLM_MASTER_KEY). Keys are created withPOST /key/generate, teams withPOST /team/new. - Cost tracking: LiteLLM's price map includes the Claude 5.5 models and Fable 5.2, but not
gpt-6.2-sol,glm-5.3,kimi-k3.1-proorqwen3.8-max. Setinput_cost_per_tokenandoutput_cost_per_tokenyourself, or those requests show zero spend and budgets never trigger. - Clients: Claude Code uses
ANTHROPIC_BASE_URL=http://<proxy>:4000andANTHROPIC_AUTH_TOKEN=<virtual key>. Codex uses a custom provider withbase_url = "http://<proxy>:4000/v1"andwire_api = "responses".
SDK or proxy: which part of LiteLLM you need
LiteLLM ships two things in one package. The Python SDK (litellm.completion, litellm.acompletion) is a library: one function call shape for many providers, run inside your own process. The proxy (litellm --config config.yaml) is a server that exposes OpenAI-style routes (/v1/chat/completions, /v1/responses, /v1/models) and Anthropic-style /v1/messages, with keys, budgets, logging and routing on top.
| You want | Use | Why |
|---|---|---|
| One Python script calling Claude and GPT with the same code | LiteLLM SDK | No server, no database |
| Several people or tools sharing one upstream account with separate limits | LiteLLM proxy + Postgres | Virtual keys, budgets, spend logs |
| Fallback from one model to another when a call fails | Proxy (router_settings.fallbacks) or SDK Router |
Built-in retries and fallbacks |
| Separate keys and quotas for a small team, one bill, no server | QCode team plan sub-keys | Managed admin panel, nothing to host |
LiteLLM SDK quick start
pip install "litellm==1.111.0"
export QCODE_API_KEY=cr_your_key
import os
import litellm
key = os.environ["QCODE_API_KEY"]
# Claude over the Anthropic Messages endpoint. LiteLLM adds /v1/messages.
claude = litellm.completion(
model="anthropic/claude-sonnet-5-5",
api_base="https://api.qcode.cc/api",
api_key=key,
messages=[{"role": "user", "content": "Explain idempotency in one sentence."}],
max_tokens=512,
)
print(claude.choices[0].message.content)
# GPT and Chinese models over the OpenAI-compatible endpoint.
for model in ["openai/gpt-6.2-sol", "openai/glm-5.3", "openai/kimi-k3.1-pro"]:
r = litellm.completion(
model=model,
api_base="https://api.qcode.cc/openai/v1",
api_key=key,
messages=[{"role": "user", "content": "Explain idempotency in one sentence."}],
)
print(model, r.choices[0].message.content, r.usage.total_tokens)
Responses are returned in OpenAI's Chat Completions shape whatever the upstream format. The anthropic/ prefix is what makes LiteLLM speak the Anthropic Messages protocol to QCode. The openai/ prefix tells LiteLLM to treat the model ID as an opaque name on an OpenAI-compatible server, which is exactly what QCode's /openai/v1 is.
Instead of api_base you can set ANTHROPIC_API_BASE (or ANTHROPIC_BASE_URL) and OPENAI_BASE_URL, but explicit arguments avoid picking up a value meant for another tool.
Proxy install and config.yaml
pip install "litellm[proxy]==1.111.0"
# config.yaml
model_list:
# ---- Claude: Anthropic Messages endpoint (no /v1 in api_base) ----
- model_name: claude-sonnet-5-5
litellm_params:
model: anthropic/claude-sonnet-5-5
api_base: https://api.qcode.cc/api
api_key: os.environ/QCODE_API_KEY
- model_name: claude-opus-5-5
litellm_params:
model: anthropic/claude-opus-5-5
api_base: https://api.qcode.cc/api
api_key: os.environ/QCODE_API_KEY
- model_name: claude-haiku-5-5
litellm_params:
model: anthropic/claude-haiku-5-5
api_base: https://api.qcode.cc/api
api_key: os.environ/QCODE_API_KEY
# ---- GPT: OpenAI endpoint (Chat Completions and Responses) ----
- model_name: gpt-6.2-sol
litellm_params:
model: openai/gpt-6.2-sol
api_base: https://api.qcode.cc/openai/v1
api_key: os.environ/QCODE_API_KEY
input_cost_per_token: 0.000002 # $2 per 1M input tokens (qcode.cc/models)
output_cost_per_token: 0.00001 # $10 per 1M output tokens
# ---- Chinese models: OpenAI-compatible Chat Completions ----
- model_name: glm-5.3
litellm_params:
model: openai/glm-5.3
api_base: https://api.qcode.cc/openai/v1
api_key: os.environ/QCODE_API_KEY
input_cost_per_token: 0.0 # replace with the price from qcode.cc/models
output_cost_per_token: 0.0
- model_name: kimi-k3.1-pro
litellm_params:
model: openai/kimi-k3.1-pro
api_base: https://api.qcode.cc/openai/v1
api_key: os.environ/QCODE_API_KEY
input_cost_per_token: 0.0 # replace with the price from qcode.cc/models
output_cost_per_token: 0.0
- model_name: deepseek-v4.1-flash
litellm_params:
model: openai/deepseek-v4.1-flash
api_base: https://api.qcode.cc/openai/v1
api_key: os.environ/QCODE_API_KEY
input_cost_per_token: 0.0 # replace with the price from qcode.cc/models
output_cost_per_token: 0.0
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
database_url: os.environ/DATABASE_URL
Three details matter here:
model_nameis what clients send. Using the real model IDs asmodel_namemeans Claude Code, Codex and SDKs work without a mapping table. You can add friendly aliases later (for examplemodel_name: fastpointing atdeepseek-v4.1-flash).os.environ/QCODE_API_KEYkeeps the upstream key out of the file. Only the proxy host holds the QCode key; users only ever see virtual keys.- Prices of
0.0are placeholders, not real prices. Fill them in before you rely on budgets. Claude models need no price lines because LiteLLM's built-in map already lists them at Anthropic's list prices ($4 / $20 for Opus 5.5, $2 / $10 for Sonnet 5.5 per 1M tokens), which match QCode's current ×1.0 multiplier.
Start and test the proxy
export QCODE_API_KEY=cr_your_key
export LITELLM_MASTER_KEY=sk-change-me-long-random
export DATABASE_URL=postgresql://litellm:password@localhost:5432/litellm
litellm --config config.yaml --validate_config # parse the YAML and stop
litellm --config config.yaml # listens on port 4000 by default
Test both route families with the master key:
# OpenAI-style route, Claude behind it (LiteLLM translates to Anthropic Messages)
curl -s http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "ping"}]}'
# Anthropic-style route, which is what Claude Code calls
curl -s http://localhost:4000/v1/messages \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "claude-sonnet-5-5", "max_tokens": 256, "messages": [{"role": "user", "content": "ping"}]}'
# Which models does this key see?
curl -s http://localhost:4000/v1/models -H "Authorization: Bearer $LITELLM_MASTER_KEY"
If the first call works and the second fails, the problem is usually the client side of /v1/messages, not QCode. If both fail with 404, check api_base for an extra /v1.
Virtual keys, teams and budgets
With DATABASE_URL set, the proxy stores keys, teams and spend in Postgres. Create a team with a monthly budget, then give each member a key inside it:
# A team with a $300 budget that resets every 30 days
curl -s http://localhost:4000/team/new \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"team_alias": "backend", "max_budget": 300, "budget_duration": "30d",
"models": ["claude-sonnet-5-5", "claude-haiku-5-5", "glm-5.3", "deepseek-v4.1-flash"]}'
# A key for one developer: own budget, own limits, only some models
curl -s http://localhost:4000/key/generate \
-H "Authorization: Bearer $LITELLM_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"team_id": "<team_id from the previous call>",
"models": ["claude-sonnet-5-5", "claude-haiku-5-5"],
"max_budget": 60, "budget_duration": "30d",
"rpm_limit": 60, "max_parallel_requests": 2,
"metadata": {"owner": "dev-a"}}'
The response contains "key": "sk-...". That is the only key the developer gets. Useful fields on /key/generate:
| Field | What it does |
|---|---|
models |
Allow-list of model_name values for this key |
max_budget / budget_duration |
Spend cap in USD and its reset window ("30s", "30m", "30h", "30d", "1mo") |
duration |
Key expiry, same format |
rpm_limit / tpm_limit |
Requests or tokens per minute |
max_parallel_requests |
Concurrent requests for this key |
team_id |
Puts the key under a team budget |
metadata |
Free-form labels that show up in spend logs |
Spend is visible through GET /key/info, /team/info and /user/info, and in the admin UI the proxy serves. A key over its budget is refused before any upstream call. The status code for that refusal is configurable through litellm.budget_exceeded_status_code; check what your LiteLLM version returns.
Remember that budgets are only as good as the prices behind them: a model with no price line counts as $0 and never uses up a budget.
Pointing Claude Code, Codex and other clients at the proxy
Claude Code calls the Anthropic Messages route. Point it at the proxy and use a virtual key as a bearer token:
unset ANTHROPIC_API_KEY
export ANTHROPIC_BASE_URL=http://litellm.internal:4000
export ANTHROPIC_AUTH_TOKEN=sk-virtual-key-for-dev-a
claude
Every model ID Claude Code asks for must exist as a model_name in config.yaml and be allowed for the key. If it is not, the proxy log shows Invalid model name passed in model=.... Listing the real Claude IDs as model_name, as above, avoids most of those.
Codex CLI speaks the Responses protocol. Add a provider for the proxy in ~/.codex/config.toml:
model_provider = "litellm"
model = "gpt-6.2-sol"
[model_providers.litellm]
name = "LiteLLM"
base_url = "http://litellm.internal:4000/v1"
env_key = "LITELLM_API_KEY"
wire_api = "responses"
export LITELLM_API_KEY=sk-virtual-key-for-dev-a
codex
The proxy forwards Responses calls for gpt-6.2-sol to https://api.qcode.cc/openai/v1/responses; test tool calls end to end with a small request before relying on them through the proxy. Keep Codex on GPT models. The Chinese models in this guide are set up for Chat Completions; if you want one behind a Responses client, test it with a small request first. For comparison, a direct Codex setup without a proxy uses base_url = "https://api.qcode.cc/openai"; see one OpenAI SDK client for several models.
Other tools (Cline, Aider, OpenCode, your own OpenAI SDK code) use the proxy as an OpenAI-compatible server: base URL http://litellm.internal:4000/v1, API key = a virtual key, model = any model_name the key allows. Because the proxy translates formats, these tools can also call claude-sonnet-5-5 through /v1/chat/completions, which QCode itself does not allow on its OpenAI endpoint. If a feature is Anthropic-specific (thinking blocks, effort, cache control) and must survive the proxy, test it with a small request first; the /v1/messages route or the official Anthropic SDK is the safer path. See Anthropic SDK with a custom base_url.
Load spreading and fallbacks
You can list the same model_name more than once with different QCode keys. LiteLLM's default simple-shuffle routing spreads requests across them, and rpm on each deployment keeps it inside that key's limits:
model_list:
- model_name: claude-sonnet-5-5
litellm_params:
model: anthropic/claude-sonnet-5-5
api_base: https://api.qcode.cc/api
api_key: os.environ/QCODE_KEY_A
rpm: 60
- model_name: claude-sonnet-5-5
litellm_params:
model: anthropic/claude-sonnet-5-5
api_base: https://asia.qcode.cc/api
api_key: os.environ/QCODE_KEY_B
rpm: 60
router_settings:
routing_strategy: simple-shuffle
num_retries: 2
fallbacks:
- claude-sonnet-5-5: ["glm-5.3"]
This matters because a proxy that sends a whole team through one subscription key puts everyone behind that single key. A team plan unit gives 35 concurrent requests, so one team key usually removes that bottleneck.
A fallback to a different vendor changes answer quality and pricing. Use it for availability, not as silent cost cutting, and log when it fires.
Errors you will see
| Symptom | Usual cause | Fix |
|---|---|---|
404, URL contains /v1/v1/messages |
Claude api_base set to https://api.qcode.cc/api/v1 |
Use https://api.qcode.cc/api |
| 404 on GPT or GLM | api_base set to https://api.qcode.cc/openai (missing /v1) |
Use https://api.qcode.cc/openai/v1 |
model_not_available_on_endpoint |
A Claude deployment uses openai/ with the OpenAI base |
Claude must use anthropic/ and /api |
Invalid model name passed in model=... |
Client sent an ID that is not a model_name, or not allowed for the key |
Add the model_name or add it to the key's models |
| 401 from the proxy | Wrong or expired virtual key, or master key missing | Check /key/info; set LITELLM_MASTER_KEY |
401 Invalid API key passed through from upstream |
QCODE_API_KEY missing on the proxy host |
Export it where the proxy runs |
| Budget-exceeded error from the proxy | Key or team spend reached max_budget |
Raise the budget or wait for budget_duration |
| Spend stays at $0 for GPT or GLM | No price in LiteLLM's map and none set | Add input_cost_per_token / output_cost_per_token |
402 daily_cost_limit_exceeded passed through |
The QCode key's daily quota is used up | Resets 00:00 Beijing time; add a pack or a key |
| Responses call for a Chinese model fails | The Responses path for Chinese models is not covered in this guide | Use /v1/chat/completions for those models, or test Responses with a small request first |
LiteLLM proxy or QCode team sub-keys?
Both give each person their own key and a spending limit. They differ in who runs it and how fine-grained the rules are.
| QCode team plan sub-keys | Self-hosted LiteLLM proxy | |
|---|---|---|
| Hosting | Nothing to host; admin panel at your team's own subdomain | You run the proxy and Postgres, patch and monitor them |
| Per-person quota | Yes, each sub-key has its own quota and rate limit | Yes, max_budget, rpm_limit, max_parallel_requests |
| Per-key model allow-list | Per-sub-key quota and rate limit are described; a model allow-list is not described as of 2026-11-26 (check /enterprise) | Yes, models on the key or team |
| Billing | One QCode bill for the team | Still one QCode bill upstream; the proxy only tracks spend |
| Cost accuracy | QCode's own billing | Depends on the prices you configure |
| Fallbacks, aliases, custom logging, other upstreams | No | Yes |
| Concurrency | 35 per team unit | Whatever the upstream keys behind it allow |
| Works with Claude Code, Codex, Cline, Aider, OpenCode | Yes, directly | Yes, through the proxy URL |
A practical rule: start with team sub-keys if your goal is "everyone gets a key, nobody overspends, one bill". Read shared keys for Claude Code teams and the team deployment guide for that path. Add LiteLLM when you need something sub-keys don't do: model allow-lists per person, aliases that let you switch models without touching every laptop, fallbacks, routing to other upstreams as well, or request logs in your own systems. The two also combine well: give the proxy one team key and let LiteLLM handle the finer rules.
Running it in production
- Network: keep the proxy on a private network or behind TLS and your own auth. It holds the upstream key and serves an admin UI.
- Secrets: generate a long random master key and set
LITELLM_SALT_KEYbefore creating keys. LiteLLM uses it to encrypt stored credentials, and changing it later makes those unreadable. - Pinning: pin the LiteLLM version (
litellm[proxy]==1.111.0) and read the changelog before upgrading. Routing, price maps and error codes change between releases. - Region: if the proxy runs outside mainland China, compare
asia.qcode.ccandus.qcode.ccagainstapi.qcode.ccfrom the proxy host itself, not from a laptop. - Reconcile: once a month, compare LiteLLM spend per team with the QCode dashboard. A large gap usually means a missing price line or cached-token pricing that differs from your numbers. QCode's bill is the source of truth.
FAQ
What api_base do I use for Claude in LiteLLM?
https://api.qcode.cc/api, with the anthropic/ model prefix. LiteLLM appends /v1/messages. Setting https://api.qcode.cc/api/v1 produces /api/v1/v1/messages and a 404.
Can I call Claude through the proxy's OpenAI-style route?
Yes. A client can send claude-sonnet-5-5 to the proxy's /v1/chat/completions, and LiteLLM converts it to an Anthropic Messages call upstream. What you cannot do is configure a Claude deployment with openai/ and the /openai/v1 base, because QCode does not serve Claude there.
Why does spend show $0 for GPT or GLM requests?
LiteLLM 1.111.0's price map has no entries for gpt-6.2-sol, glm-5.3, kimi-k3.1-pro or qwen3.8-max. Add input_cost_per_token and output_cost_per_token to those deployments, using the prices on QCode's /models page.
Do I need Postgres?
Only for virtual keys, teams, budgets and spend logs. A proxy with just a master key and model_list runs without a database, but then everyone shares the master key.
Does Claude Code work through LiteLLM?
Yes. Set ANTHROPIC_BASE_URL to the proxy, put a virtual key in ANTHROPIC_AUTH_TOKEN, unset ANTHROPIC_API_KEY, and make sure each model ID Claude Code requests is a model_name in the config.
Can Codex use Chinese models through the proxy?
Codex sends Responses requests, and the Chinese models in this guide are set up for Chat Completions. Use Codex with GPT models; if you want a Chinese model behind a Responses client, test it with a small request first.
Is a proxy cheaper than calling QCode directly?
No. The proxy adds no discount; every request is still billed by QCode at its normal rate. It adds control and visibility, at the cost of a server to run.
Which QCode plan fits a LiteLLM setup
A shared proxy for several people needs concurrency more than anything else. The team plan is built for that: each unit gives a $4,000 monthly quota and 35 concurrent requests, a separate admin panel with per-sub-key quotas, and one bill; see /enterprise and /pricing for current terms. Point the proxy at one team key, or skip the proxy and hand out sub-keys directly.