DeepSeek API key setup: prepaid balance, peak pricing and the base URL

Create a DeepSeek API key, store it as DEEPSEEK_API_KEY, call it from your server with the OpenAI SDK, and watch the prepaid balance before it hits zero.

Simon, Founder of Shipyard

By · Founder of Shipyard

6 minute read

The short version

Sign in at platform.deepseek.com, add money to your balance, then open the API keys page at platform.deepseek.com/api_keys and create a key. Store it on your host as DEEPSEEK_API_KEY, the name DeepSeek's own examples read, and call the API only from server code, using the OpenAI SDK pointed at https://api.deepseek.com. The model names to use today are deepseek-flash and deepseek-v4-pro. DeepSeek is prepaid: when the balance reaches zero, every request fails with HTTP 402, and that empty balance is the only hard spending stop DeepSeek offers.

The reason people pick DeepSeek is price. On 1 December 2026, deepseek-flash costs $0.15 per million input tokens and $0.60 per million output tokens at off-peak rates. The trade-offs are just as real: limits are shared by the whole account, there is no per-key cap, prices double at set hours, and the company is based in China, which matters to some customers. Each of those is covered below.

Create the key, step by step

  1. Sign in at platform.deepseek.com and top up a small amount first. A key on an empty account returns 402 on every call, which looks like a broken key but is not.
  2. Open the API keys page and create a key named after the app and the environment, for example myapp-prod, so you know which one to delete if it leaks.
  3. Paste it straight into your host's environment variables as DEEPSEEK_API_KEY. Not into a chat, a commit or a file the browser downloads.
  4. Add a second variable, DEEPSEEK_MODEL, set to deepseek-flash, so moving to another model later is a settings change rather than a code change.
  5. Run the balance check further down from your own terminal. If it answers with your balance, the key works.

What you pay, and when it doubles

DeepSeek charges per million tokens and splits input into cache hits and cache misses. A cache hit is input that repeats the start of something you sent recently, such as a long system prompt that goes out with every request, and on Flash it costs one fiftieth of a miss. Keep the fixed part of your prompt at the very beginning and word for word identical between calls, and put the user's question after it, to collect those hits.

Prices also depend on the clock. DeepSeek's pricing page defines peak hours as 01:00 to 04:00 and 06:00 to 10:00 UTC, Monday to Friday, outside Chinese public holidays, and charges double during them. Every other hour, weekends included, is off-peak. You cannot move a user's request, but you can move background work: a nightly summary job that runs at 11:00 UTC instead of 08:00 costs half as much. If an account holds both a granted balance and money you topped up, DeepSeek spends the granted balance first.

Per million tokensdeepseek-flashdeepseek-v4-pro
Input, cache hit (off-peak / peak)$0.003 / $0.006$0.022 / $0.044
Input, cache miss (off-peak / peak)$0.15 / $0.30$0.66 / $1.32
Output (off-peak / peak)$0.60 / $1.20$1.98 / $3.96
Context length1M tokens1M tokens
Concurrent requests per account2,500500

Call DeepSeek from the server

DeepSeek's API follows the OpenAI format, so the openai npm package works with two changes: the base URL https://api.deepseek.com and your DeepSeek key. Pass the key in explicitly. The OpenAI client looks for OPENAI_API_KEY on its own and will not find DEEPSEEK_API_KEY. If your code was written for Anthropic's SDK instead, DeepSeek also accepts that format at https://api.deepseek.com/anthropic, so you can switch by changing the base URL and key.

Slow requests behave differently from most providers. While a request waits in DeepSeek's queue, the server sends empty lines on a normal request and : keep-alive comments on a stream, and it closes the connection if inference has not started after 10 minutes. A parser you write yourself has to skip those lines. Give the route your own shorter timeout, so a user sees an error after a sensible wait instead of a spinner for ten minutes.

TypeScript
// app/api/ask/route.ts
import OpenAI from 'openai'

const deepseek = new OpenAI({
  baseURL: 'https://api.deepseek.com',
  apiKey: process.env.DEEPSEEK_API_KEY, // not found automatically
  timeout: 60_000,
})

export async function POST(req: Request) {
  // Check the session and a per-user rate limit here.
  const { question } = await req.json()
  const res = await deepseek.chat.completions.create({
    model: process.env.DEEPSEEK_MODEL ?? 'deepseek-flash',
    messages: [{ role: 'user', content: question }],
    max_tokens: 800,
  })
  return Response.json({ text: res.choices[0]?.message?.content ?? '' })
}

Watch the balance, because nothing else stops the spend

DeepSeek's documentation describes no spending cap per key and no monthly budget, so the balance is the number to watch. A GET request to https://api.deepseek.com/user/balance with your key returns is_available, which says whether the balance is enough for API calls, and a balance_infos list with the total, granted and topped-up amounts for each currency. Call it from a daily job or your health check and warn yourself well before zero, because at zero your app stops answering until someone tops up by hand.

Treat the size of the balance as your budget. Topping up a month of expected usage at a time keeps the worst case of a leak or a runaway loop small, at the cost of a reminder to top up. If you need a hard limit on each key, OpenRouter offers one and serves DeepSeek models too, as explained further down.

Terminal
curl https://api.deepseek.com/user/balance \
  -H "Authorization: Bearer $DEEPSEEK_API_KEY"

Limits are per account, not per key

DeepSeek limits how many requests can be in progress at once rather than how many arrive per minute: 2,500 at a time for deepseek-flash and 500 for deepseek-v4-pro. Its rate limit page says these are counted for the whole account, whichever key sends the request. A separate key for staging is still worth having so you can revoke it alone, but it does not protect production's capacity. Requests over the limit get HTTP 429, and DeepSeek accepts requests for more capacity at no extra charge.

There is also an optional user_id field, sent at the top level of the request body, or inside extra_body when you use the OpenAI SDK. DeepSeek uses it to keep your users apart for content safety, cache privacy and scheduling. Send an opaque value such as a hash of your own user ID, never an email address: DeepSeek allows only ASCII letters, digits, underscores and hyphens, up to 512 bytes, and asks that it contain no private user information.

When DeepSeek is the wrong choice

DeepSeek's privacy policy says it collects, processes and stores personal data in the People's Republic of China, and its open platform terms are governed by mainland Chinese law. The policy does not spell out where the content of API requests is processed. If your customers, your contracts or your own judgement need data to stay in the EU or the US, read those documents before you send anything, and expect some business customers to ask.

The models themselves are not only available from DeepSeek. When we checked on 1 December 2026, OpenRouter listed 43 providers serving DeepSeek V4.1 Flash, one of them routed inside the EU, and OpenRouter lets you put a credit limit on each key, which DeepSeek's own console does not describe. You pay OpenRouter's price for whichever provider answers, so compare it with DeepSeek's off-peak rate before you decide. For the cheapest tokens with no extra layer, going direct to DeepSeek still wins.

If the key leaks

Delete it on the API keys page, create a new one and replace DEEPSEEK_API_KEY on your host, then redeploy so the running app picks it up. DeepSeek's terms are blunt about who pays: you are solely responsible for fees and losses caused by sharing or leaking a key. With no per-key cap, the only limit on that bill is whatever is left in your balance, which is the strongest argument for topping up in modest amounts. DeepSeek can refund an unspent balance after a review, minus fees, but never money already spent.

What Shipyard does here

Shipyard's AI step writes Anthropic, OpenAI or OpenRouter keys into your host, not DeepSeek keys. To call DeepSeek directly, add DEEPSEEK_API_KEY and DEEPSEEK_MODEL to your host yourself after launch, as described on this page. If a hard cap per key matters more to you than the lowest price, choose OpenRouter as the provider, pick a DeepSeek model there, and Shipyard writes that key into your host on the server side only.

Sources

Launch in an hour, not a weekend

Shipyard connects your accounts once, then sets up the domain, hosting, database, email and payments for every new product.

Get started See how it works

Read next