Notizen / 15
LiteLLM proxy for a DeepSeek-only gateway
LiteLLM already speaks OpenAI, so pointing it at a DeepSeek gateway is one YAML entry — provided the entry has openai/ in front of the model id and /v1 on the api_base. Both are documented and both are easy to miss. This is the config we actually run, the request LiteLLM sends after it resolves, the response body that comes back (with usage on the finish chunk, not on a separate event), and the one thing a single-price tool cannot express: peak and off-peak rates on the same model. Three failures included, each with the fix.
The config, in full
LiteLLM routes to any OpenAI-compatible endpoint through its openai/ provider prefix. The prefix is the whole selection mechanism: it tells LiteLLM to use the OpenAI client against whatever api_base you give it.
model_list:
- model_name: deepseek-chat
litellm_params:
model: openai/deepseek-chat # the prefix selects the OpenAI route
api_base: https://api.tokenaimodels.com/v1
api_key: os.environ/MODELRY_KEY
- model_name: deepseek-chat-lite
litellm_params:
model: openai/deepseek-chat-lite
api_base: https://api.tokenaimodels.com/v1
api_key: os.environ/MODELRY_KEY
Two details from LiteLLM's own documentation matter more than the rest. First, the prefix form is openai/<your-model-name> and the model name after the slash is what travels in the request body — it must be an id your endpoint actually serves. Second, and this is the one that produces a confusing 404: the docs say to make sure api_base carries the /v1 postfix, because LiteLLM appends /chat/completions itself and does not add /v1 for you. Our host is https://api.tokenaimodels.com/v1; drop the /v1 and every call 404s while the same URL works fine in curl.
Then start the proxy as usual:
export MODELRY_KEY="sk-live-..."
litellm --config ./config.yaml
What actually goes over the wire
With that config, a call through LiteLLM to deepseek-chat reaches our endpoint unchanged. Here is the body we got back from a live request against a local instance on 2026-11-19, trimmed to the fields that matter:
{"id":"c37472ef-...","object":"chat.completion","created":1795089632,
"model":"deepseek-flash",
"choices":[{"index":0,"message":{"role":"assistant","content":"Hi! How's it going? Is"},
"logprobs":null,"finish_reason":"length"}],
"usage":{"prompt_tokens":5,"completion_tokens":8,"total_tokens":13,
"prompt_tokens_details":{"cached_tokens":0},
"prompt_cache_hit_tokens":0,"prompt_cache_miss_tokens":5}}
Two things to note before you wire alerting to this. The model field carries the upstream id (deepseek-flash), not the id you sent (deepseek-chat) — do not assert on it. And finish_reason: "length" is honest: the request asked for max_tokens: 8.
The same request, streamed
curl -sN -X POST https://api.tokenaimodels.com/v1/chat/completions \
-H "Authorization: Bearer $MODELRY_KEY" -H "Content-Type: application/json" \
-d '{"model":"deepseek-chat","messages":[{"role":"user","content":"Count 1 to 3."}],
"max_tokens":24,"stream":true,"stream_options":{"include_usage":true}}'
The stream ends like this:
data: {"id":"30dc2833-...","object":"chat.completion.chunk","model":"deepseek-flash",
"choices":[{"index":0,"delta":{"content":""},"finish_reason":"stop"}],
"usage":{"prompt_tokens":11,"completion_tokens":8,"total_tokens":19,
"prompt_tokens_details":{"cached_tokens":0},
"prompt_cache_hit_tokens":0,"prompt_cache_miss_tokens":11}}
data: [DONE]
Usage rode on the chunk that also carries finish_reason, with choices still populated. Some OpenAI-compatible gateways instead send a separate usage-only event with an empty choices array. LiteLLM copes with both, but your own wrapper around the iterator may not: guard the empty array anyway.
The thing a single price cannot express
Rates here come in two windows: off-peak, and peak at exactly 2× during UTC 01:00–04:00 and 06:00–10:00 on weekdays. LiteLLM's cost accounting attaches one price per model id, so a single deepseek-chat entry will report costs that are wrong by up to a factor of two depending on when the request arrived.
Two workable answers. Register the model twice — deepseek-chat-offpeak and deepseek-chat-peak, same api_base, same upstream id — and pick the alias in code according to the hour. Or keep one alias and treat LiteLLM's dollar figures as a relative signal only, reconciling against the gateway's own usage log, which is the authority. Per-token cost registration in LiteLLM is documented separately from the endpoint config; see its "Add Model Pricing & Context Window" page rather than guessing field names.
The published rates, per 1M tokens, are on /pricing and in the /v1/models response:
| Model | Window | Input | Cached input | Output | |---|---|---|---|---| | deepseek-chat | off-peak | $0.25 | $0.006 | $1.45 | | deepseek-chat | peak | $0.50 | $0.012 | $2.90 | | deepseek-chat-lite | off-peak | $0.20 | $0.006 | $0.85 | | deepseek-chat-lite | peak | $0.40 | $0.012 | $1.70 | | deepseek-reasoner | off-peak | $1.10 | $0.044 | $4.75 |
Failure 1: a 404 that is really a missing /v1
Not Found from LiteLLM against an endpoint that answers curl is almost always the base URL. LiteLLM builds <api_base>/chat/completions; if api_base is https://api.tokenaimodels.com the request goes to a path that does not exist. Add /v1. The same class of mistake is leaving the openai/ prefix off — LiteLLM then tries to resolve the provider from the model name, guesses wrong, and either calls a public endpoint or fails before sending anything.
Failure 2: costs that read as zero
A model id LiteLLM's catalogue does not know has no price, so the proxy reports zero spend while the gateway deducts real money. That divergence is silent and it grows. Either register pricing for the ids you use, or stop reading LiteLLM's spend numbers as your ledger — our per-request usage log is the one that reconciles.
Failure 3: retries that turn one 402 into six
LiteLLM's proxy retries by default. A 402 here is a pre-authorisation failure against a prepaid balance, sized from your body and max_tokens; it does not clear on the second attempt, and a large max_tokens on a thin balance is the usual cause. Set retries low for 402 and 4xx, and keep them for 429, which carries retry-after for a fixed one-minute window — honouring that header beats any backoff you invent.
Verify in four calls
curl -s https://api.tokenaimodels.com/v1/models -H "Authorization: Bearer $MODELRY_KEY" | jq -r '.data[].id'
curl -s -o /dev/null -w '%{http_code}\n' https://api.tokenaimodels.com/v1/chat/completions \
-H "Authorization: Bearer $MODELRY_KEY" -H "Content-Type: application/json" \
-d '{"model":"deepseek-chat","messages":[{"role":"user","content":"hi"}],"max_tokens":8}'
The list must contain the id you put after openai/; the second call must be 200. Then repeat through LiteLLM itself with litellm.completion(model="openai/deepseek-chat", ...) and compare the token counts it reports with the ones in the response body above — if they disagree, the cost fields are being applied to a shape you did not expect.
Create a key at /signup — accounts start with $0.50 in credits, no card — and put that one model_list entry in front of the config you already have. Rates are on /pricing; the endpoint reference is in /docs, and the two-line SDK version of this setup is in /blog/point-any-openai-sdk-at-modelry.
Modelry betreibt eine Plattform, die DeepSeek-Modelle hinter einem HTTP-Endpoint bereitstellt; vorausbezahlte Credits und Steuern werden beim Kauf vom Merchant of Record abgewickelt, und die Datenaufbewahrung ist dokumentiert. Starten Sie mit $0.50 Testguthaben: Schlüssel erstellen.