The API is the right tool when DeepSeek needs to run without a person in the loop, when you want to plug it into an editor or app, or when you need to process more text than you could ever paste by hand. It is the wrong tool for interactive chat, which the free app already does for nothing. If you are unsure, you do not need it yet.
Get a key
Sign in at platform.deepseek.com, add a small top-up, and create an API key. Store it in an environment variable, never in code. The official quick start covers the console; the pricing page is the source of truth for rates, cache-hit pricing and off-peak windows.
The endpoint is OpenAI-compatible
DeepSeek's API speaks the same chat-completions format as OpenAI. The base URL is https://api.deepseek.com, and the two model names are deepseek-chat and deepseek-reasoner. Any OpenAI SDK works by changing the base URL and key, which also means switching an existing app to DeepSeek is usually a two-line change.
curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Summarise the difference between input and output tokens in two sentences."}
],
"max_tokens": 200
}'import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.deepseek.com",
api_key=os.environ["DEEPSEEK_API_KEY"],
)
resp = client.chat.completions.create(
model="deepseek-chat", # or "deepseek-reasoner"
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Summarise the difference between input and output tokens in two sentences."},
],
max_tokens=200,
)
print(resp.choices[0].message.content)
print(resp.usage) # prompt_tokens, completion_tokens, cache hit/miss detailsReading the bill
Every response includes a usage object with prompt and completion token counts. DeepSeek's version also breaks the prompt tokens into cache-hit and cache-miss counts. Multiply each by the matching rate from the pricing page and you have the cost of that call. Log these three numbers from day one; they are the difference between knowing your bill and guessing it.
Worked example using catalogue prices at the time of writing: a call to deepseek-chat (V3.2 in our catalogue) with 3,000 prompt tokens and 500 completion tokens costs about 3,000 × $0.00000027 + 500 × $0.0000004 ≈ $0.001. A thousand such calls is about a dollar. The same call to the reasoner might generate 3,000 reasoning tokens plus the 500-token answer, so completion tokens become 3,500 at R1 output rates — several times the cost.
Context caching
DeepSeek's context caching is automatic on the official API — there is nothing to enable. If the beginning of a new request is identical to the beginning of a recent one, those tokens are billed at the cache-hit input rate, which is far below the standard rate. The exact discount is on the pricing page. To benefit, keep the system prompt, instructions and any reference documents at the very start of the messages, and keep them byte-identical between calls.
Off-peak pricing
The official API also publishes off-peak discount windows during which both models are billed at reduced rates. The hours and percentages are on the pricing page and have changed before, so do not hard-code them. If you have batch work that is not time-sensitive — nightly summaries, backfills, evaluation runs — schedule it in the window. It is one of the few AI discounts that requires no engineering.
Knowledge check
You send the same 6,000-token system prompt plus reference document on every call, followed by a different user question each time. What is the cheapest change?