DeepSeek V4.1 in LiteLLM: Proxy, Python SDK and Real Spend Numbers

Add DeepSeek V4.1 from API Store to the LiteLLM proxy or Python SDK with one config entry, and give LiteLLM the prices so its spend logs and budgets are right.

4 min read

deepseeklitellmpythongateway

A LiteLLM config entry that sends DeepSeek V4.1 requests to API Store

LiteLLM is an open-source gateway that puts many model providers behind one OpenAI-style API. Teams run it to give every app the same endpoint, hand out virtual keys, and set budgets per team. This post shows how to add DeepSeek V4.1 from API Store to it, through the proxy or straight from Python, and how to make LiteLLM count the cost correctly.

Why route DeepSeek through API Store

API Store follows the OpenAI format, so LiteLLM talks to it the way it talks to OpenAI. You get DeepSeek V4.1 at $0.21 per million input tokens and $0.84 per million output tokens, less outside peak hours, paid from a prepaid balance with no subscription. The same key also reaches Seedance video and Seedream image models if you need them later.

The proxy: one entry in config.yaml

yaml
model_list:
  - model_name: deepseek-v4-1-flash
    litellm_params:
      model: openai/deepseek-v4-1-flash
      api_base: https://api.apistore.cloud/v1
      api_key: os.environ/APISTORE_API_KEY
      use_chat_completions_api: true
      input_cost_per_token: 0.00000021
      output_cost_per_token: 0.00000084
      cache_read_input_token_cost: 0.0000000042

Four parts do the work:

  • openai/ tells LiteLLM the model speaks the OpenAI API. The name after it is the API Store model name.
  • api_base sends the requests to API Store instead of OpenAI.
  • use_chat_completions_api makes LiteLLM send Responses API and Anthropic Messages requests as chat completions. More on that below.
  • The cost lines are the prices per token. Without them LiteLLM knows nothing about the model and records every request at $0.

Start the proxy with your key in the environment, then call it with the model_name from the config:

bash
export APISTORE_API_KEY=sk-...
litellm --config config.yaml

curl http://localhost:4000/v1/chat/completions \
  -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "deepseek-v4-1-flash", "messages": [{"role": "user", "content": "Say hello"}]}'

The response carries an x-litellm-response-cost header. For a short "Say hello" it is about $0.00001, which is what API Store charges for those tokens at the standard price.

The prices above are today's. The LiteLLM setup guide builds the same config with the current prices filled in.

The Python SDK, without a proxy

python
import os
from litellm import completion

response = completion(
    model="openai/deepseek-v4-1-flash",
    api_base="https://api.apistore.cloud/v1",
    api_key=os.environ["APISTORE_API_KEY"],
    messages=[{"role": "user", "content": "Say hello"}],
)
print(response.choices[0].message.content)

Add stream=True to stream the answer. Tool calls work the same way as with OpenAI models: pass tools, and the response has tool_calls with the function name and arguments. There is a full example of both on this blog.

Responses API and Anthropic Messages clients

LiteLLM translates between API formats, so a model behind the proxy can also answer on its /v1/responses and /v1/messages endpoints. A tool built for the Responses API or the Anthropic Messages API can then use DeepSeek V4.1 without changes.

This is what use_chat_completions_api: true is for. An openai/ model is treated as OpenAI itself, so without the line LiteLLM forwards those requests to an OpenAI Responses endpoint, and API Store answers 404 Unknown path /v1/responses. With it, LiteLLM turns them into chat completions first, and the cost is counted the same way.

Two models, two entries

deepseek-v4-1-flash-economy costs $0.168 per million input tokens and $0.672 per million output tokens. To offer both, copy the entry, change the two model names, and use the economy prices. Apps then pick a model by its model_name, and LiteLLM's budgets cover both.

Keep the two budgets in line

LiteLLM and API Store each have spending limits, and they do different jobs:

  • In LiteLLM, give each team or app a virtual key with a budget. That splits the spend inside your company.
  • In API Store, give the LiteLLM proxy its own key with a daily spending cap. That is the hard limit if something loops.

The cost lines use the peak-hour price. Off-peak prices are half, so at those times LiteLLM records up to twice what you pay. The Usage page in your API Store dashboard has the exact charge of every request.

Troubleshooting

  • 401 invalid_api_key: APISTORE_API_KEY is not set where the proxy runs, only in your own shell.
  • 404 model_not_found: the name after openai/ must be an API Store model name, exactly as on the pricing page.
  • Spend shows $0: the cost lines are missing from litellm_params.
  • 404 Unknown path /v1/responses on /v1/responses or /v1/messages: add use_chat_completions_api: true to litellm_params.
  • 402 insufficient_balance: top up, or raise the key's daily cap.

What it costs

LiteLLM is free and adds no fee of its own. Each request is billed to your API Store balance at the model's price per token: $0.21 input and $0.84 output per million tokens for deepseek-v4-1-flash, with cached input at $0.0042. The pricing page has every model.

Also in Tiếng Việt, Español, Português