跳到正文
DEV Community· pai zhang·· 1 小時前AI 評分49

DeepSeek 一次請求的實際成本

What a DeepSeek request actually costs

AI 導讀

DeepSeek 請求費用分別按未命中快取的輸入、命中快取的輸入及輸出計算,並依請求開始時的時段套用費率。每 1M token 的離峯費率依次為 $0.25、$0.006 及 $1.45,繁忙時段則為 $0.50、$0.012 及 $2.90;費用於最後向上取整至整數 micro-dollar。實例中,快取命中令一個請求的費用由 104 micro 降至 42 micro,節省 60%。

正文

A per-million-token price list is not a bill. One request is charged on three separate buckets — input that missed the cache, input that hit it, and output — and the price of the first two is different from the third by a factor of nearly four hundred on our table. Add two time windows and a rounding rule and you get a number you cannot reproduce without the run behind it. This article takes one real request, prints the usage block the upstream returned, prints what the ledger booked for it, and reconciles the two by hand. It then repeats the exercise with a cache hit and with a replayed bill, so you can check any usage statement we send you.

The table, in the units it is actually charged in

Four numbers and two windows decide everything:

Bucket Off-peak, per 1M Peak, per 1M
Input, cache miss $0.25 $0.50
Input, cache hit $0.006 $0.012
Output $1.45 $2.90

Peak is 01:00-04:00 and 06:00-10:00 UTC, Monday to Friday; everything else, including weekends, is off-peak. The full table and the per-model differences are on the pricing page, and the numbers there are rendered from the same source file the billing path reads.

The ratio that matters is between buckets, not between vendors. A cached input token costs 1/41.7 of an uncached one, and an output token costs 241 times a cached input token. So a request is not "priced per token" in any useful sense until you know its split — and the split is reported by the upstream, not chosen by you.

One request, reconciled

This is a real request against the DeepSeek upstream, captured on 2026-11-19 with max_tokens set to 16 and a 409-token prompt repeated once so that the second call would hit the prefix cache. The usage block from the second call:

{"prompt_tokens": 409, "completion_tokens": 1, "total_tokens": 410,
 "prompt_tokens_details": {"cached_tokens": 256},
 "prompt_cache_hit_tokens": 256, "prompt_cache_miss_tokens": 153}

The ledger booked 42 micro-dollars for it. Reconcile by hand, in micro-dollars, remembering that one dollar is 1,000,000 micro:

cache-miss input : 153 × 250,000 / 1,000,000 = 38.25
cache-hit  input : 256 ×   6,000 / 1,000,000 =  1.536
output           :   1 × 1,450,000 / 1,000,000 = 1.45
                                         sum = 41.236
                          ceil to 1 micro    = 42

41.236 rounds up to 42: every request is charged in whole micro-dollars, rounded up, never down and never to a tenth of a cent. The same arithmetic on the first call — same prompt, nothing in cache — gives 409 × 0.25 + 1 × 1.45 = 103.7, booked as 104 micro. The cache hit saved 62 micro-dollars, which is 60% of that request, on a prompt whose only change was being sent twice.

Two smaller requests are worth keeping as unit tests. A 9-token prompt with a 1-token answer reconciles to 9 × 0.25 + 1.45 = 3.7, booked as 4 micro. Ask for nothing (max_tokens: 1, empty content) and the same formula still holds, because the input side is charged whether or not the model produces a word.

Where the numbers come from, and what is not in them

Three facts are easy to assume wrongly:

  1. prompt_tokens includes the cached part. cached_tokens is a subset, not an addition. A naive prompt_tokens × input_rate + cached_tokens × cached_rate double-charges the cache. Subtract first: miss = prompt_tokens − cached_tokens.
  2. There is no per-request fee, minimum, or rounding to the cent. A four-micro request costs four micro. Rounding happens once, at the end, upward.
  3. The peak decision is made when the request arrives, from the UTC hour, not from when the response finished. A request that starts at 03:59 UTC on a Tuesday is billed at the peak rate even if it returns at 04:02.

Estimating before you spend

You cannot know the split before a call, so the platform pre-authorises rather than prices: it estimates prompt tokens from the whole request body, adds your max_tokens, applies a 15% cushion, and freezes that against your balance. The freeze is why an oversized max_tokens returns 402 insufficient_balance on an account that could obviously afford the real call. Set max_tokens to what the answer needs; a request for 384,000 tokens "just in case" reserves output at $1.45 per 1M before a single token is produced.

Three checks that make a usage statement auditable

If you are reconciling our usage statement against your own logs, these three assertions catch nearly everything:

  • Per request: billed_micro == ceil((prompt − cached) × in_rate + cached × cached_rate + completion × out_rate) with the rates for the window the request started in.
  • Per day: the sum of your own logged requests equals the statement total, with no line for "model routing" or "platform fee" — there is none.
  • Cache sanity: any request whose cached_tokens is zero and whose prompt repeats the previous one byte for byte is worth investigating; a prefix cache that stops hitting is a silent cost increase, not an error.

The three reconciled requests above are the whole method. Run the same arithmetic over your own traffic — usage is in every response, and GET /v1/models gives you the rates in machine-readable form — and the bill stops being something you accept and becomes something you check. If you want the shortest path to a first metered call, the five-minute walkthrough is at /start.

Per-model numbers, including the cache and output rates for the reasoning tier, are on the deepseek-chat model page and the deepseek-reasoner model page; the full table with both windows is on the pricing page.

See also: DeepSeek peak vs off-peak pricing, in UTC — the window arithmetic this page depends on.


Modelry is an independent platform operator running a prepaid, metered endpoint for the DeepSeek models — no card to sign up, and a spend cap on every key: https://tokenaimodels.com/signup?utm_source=devto&utm_medium=post&utm_campaign=deepseek_api_pricing

來源:DEV Community · dev.to