A working DeepSeek call needs three values: an API key from the DeepSeek platform, the base URL https://api.deepseek.com, and the model name deepseek-flash. DeepSeek’s API changelog says that name is now served by V4.1-Flash-1017 with the calling method and pricing unchanged (changelog read on 12 November 2026). Leave deepseek-chat and deepseek-reasoner out of a new first call: older tutorials still print them, and the same changelog set 24 July 2026 as the date both names would be discontinued, a date that has already passed. The 13 steps below are grouped around the places where a first call fails or costs money.
Don't miss new tech stories on Google
Add Tech Insider once in the Google app and our stories appear in your news suggestions.
Steps 1 to 4: account, key, balance, and a key kept out of your code
Requirements are short: curl, or the standard openai package for Python or Node.js. The openai Python library’s README says it works with Python 3.10 or higher (checked on 12 November 2026), so a guide that still says Python 3.9 is out of date. DeepSeek’s API docs say the API format is compatible with OpenAI and Anthropic, so the SDKs only need a configuration change.
Step 1: sign up on the platform
Sign up at platform.deepseek.com. This route comes from the independent guide at deepseek.ai/docs, which says it is not affiliated with DeepSeek: sign up, open the API Keys section, create a new key.
Step 2: create the API key
Create the key in the API Keys section. DeepSeek’s connection table lists it as “apply for an API key” beside the base URL and model name. Copy it into a password manager or secrets store when it appears, and keep it out of source files.
Step 3: add balance before the first call
A correct request still fails on an empty balance. DeepSeek’s error-code page lists 402 Insufficient Balance, with the cause “You have run out of balance” and the fix “go to the Top up page to add funds.” Step 13 prices a 10,000-request job so you can size the top-up.
Step 4: put the key in DEEPSEEK_API_KEY
DeepSeek’s first-call quickstart tells readers to set the DEEPSEEK_API_KEY environment variable before running its examples, and every snippet below reads that variable. On bash or zsh:
export DEEPSEEK_API_KEY="sk-your-key-here"
On Windows PowerShell, this sets it for the current session only:
$env:DEEPSEEK_API_KEY = "sk-your-key-here"
In a team repository, commit a .env.example with an empty value and list the real .env in .gitignore. Step 7 shows how Python can load that file.
Step 5: type deepseek-flash, and leave deepseek-chat and deepseek-reasoner in old tutorials
The table lists every value a first call touches and the status DeepSeek gives each model string. The values come from the DeepSeek API docs and the changelog.
| Setting | Value | Status |
|---|---|---|
| base_url, OpenAI format | https://api.deepseek.com | Current |
| base_url, Anthropic format | https://api.deepseek.com/anthropic | Current, for Claude-style tools |
| api_key | Your platform key | Current |
| model | deepseek-flash | Current, served by V4.1-Flash-1017 |
| model | deepseek-v4-pro | Listed in the docs table; DeepSeek kept serving it after 14 September 2026 |
| model | deepseek-v4-flash, deepseek-v4-flash-vision-exp | Accepted, but the models are retired; requests go to V4.1-Flash-1017 at the Flash price |
| model | deepseek-chat, deepseek-reasoner | Changelog set 24 July 2026 for discontinuation (date passed); do not use in new code |
Moving OpenAI code over is a two-line change: set base_url to https://api.deepseek.com instead of the default OpenAI endpoint, and set model to deepseek-flash. The same model string now reaches V4.1-Flash-1017, so existing deepseek-flash code needs no change. Our report on the 1017 update and its Search API covers what changed around the model.
For context on what the string points to: DeepSeek’s launch news puts the V4.1-Flash release on 10 September 2026, when the new pricing took effect at 04:00 UTC, and the changelog entry of 17 October 2026 moved deepseek-flash to the 1017 revision.
DeepSeek’s docs say the legacy names deepseek-v4-flash and deepseek-v4-flash-vision-exp are still accepted, so code that uses them keeps running, but change the string when you next touch the file. The changelog says deepseek-chat and deepseek-reasoner pointed to the non-thinking and thinking modes of deepseek-v4-flash until their discontinuation date. That is why old tutorials worked, and it is not a reason to type those names in new code.
On V4 Pro, the changelog says V4-Pro and V4-Flash came to the API on 24 April 2026, and deepseek-v4-pro is a separate, higher-priced tier from Flash. Two DeepSeek pages disagree about its future. The V4.1-Flash launch news said all deepseek-v4-pro requests would route to V4.1-Flash from 14 September 2026. The later changelog says DeepSeek decided to continue providing V4 Pro after that date with billing unchanged, and the newer page is the one to follow.
The independent guide at deepseek.ai/docs still describes DeepSeek-V3 and R1 and tells readers to use deepseek-chat and deepseek-reasoner. It says it is not affiliated with DeepSeek. Copy model names from DeepSeek’s own docs, not from it.
Steps 6 to 10: a first reply in curl, Python and Node.js, then thinking level and streaming
Step 6: a curl smoke test that prints the status
The request body is the one from DeepSeek’s quickstart. It enables thinking and sets reasoning_effort to high, and the docs example is non-streaming, so it is not a plain chat call. The script prints the HTTP status and body, so a 401 or 402 is readable on the first run, and it removes its temporary file on exit.
#!/bin/sh
set -eu
: "${DEEPSEEK_API_KEY:?set DEEPSEEK_API_KEY first}"
tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT
status=$(curl https://api.deepseek.com/chat/completions -sS -o "$tmp" -w '%{http_code}' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{
"model": "deepseek-flash",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"thinking": {"type": "enabled"},
"reasoning_effort": "high",
"stream": false
}')
echo "HTTP $status"
cat "$tmp"
echo
case "$status" in 2??) ;; *) exit 1 ;; esac
A success status means the key, balance and model string are all accepted. A 402 sends you back to step 3. A 401 points at the key or the environment variable from step 4.
Step 7: the same call in Python
Install the packages with pip install openai python-dotenv. load_dotenv() copies the entries of a local .env file into the environment, so the os.environ[...] line works whether the key is exported in the shell or kept in .env. It raises a KeyError at once if the variable is missing from both.
import os
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
client = OpenAI(
api_key=os.environ["DEEPSEEK_API_KEY"],
base_url="https://api.deepseek.com",
)
response = client.chat.completions.create(
model="deepseek-flash",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
],
reasoning_effort="high",
extra_body={"thinking": {"type": "enabled"}},
)
print(response.choices[0].message.content)
print(response.usage)
The usage object holds the token counts for the call. Step 13 turns those counts into dollars.
Step 8: the same call in Node.js
Install with npm install openai and save the file as first-call.mjs so top-level await works. It uses the same OpenAI SDK with baseURL set to DeepSeek.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.DEEPSEEK_API_KEY,
baseURL: "https://api.deepseek.com",
});
const completion = await client.chat.completions.create({
model: "deepseek-flash",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Hello!" },
],
reasoning_effort: "high",
thinking: { type: "enabled" },
});
console.log(completion.choices[0].message.content);
console.log(completion.usage);
Step 9: pick a thinking level
The changelog says the thinking modes of V4-Pro and V4-Flash support three effort levels. DeepSeek’s guidance for choosing one:
| reasoning_effort | DeepSeek’s guidance |
|---|---|
| low | Simple tasks |
| high | Daily agent tasks (the level in DeepSeek’s quickstart example) |
| max | More complex scenarios |
Step 10: turn on streaming
DeepSeek’s quickstart example is non-streaming and says to set the stream parameter to true to get a streamed response. Some chunks carry no text, so check before printing.
stream = client.chat.completions.create(
model="deepseek-flash",
messages=[{"role": "user", "content": "Explain speculative decoding in simple terms."}],
stream=True,
)
for chunk in stream:
if not chunk.choices:
continue
delta = chunk.choices[0].delta
if delta.content:
print(delta.content, end="", flush=True)
Steps 11 and 12: images, the 1,048,576-token ceiling, and the error codes DeepSeek lists
Step 11: image input and a context budget
The changelog says V4.1 Flash is available on the API with native multimodal support, so text and images can go into the same chat completion call.
NVIDIA’s hosted-model reference gives the combined input and output context length as 1,048,576 tokens. Because input and output share that budget, a very long prompt leaves less room for the reply. Set an explicit max_tokens, and if a reply stops mid-sentence, raise it while keeping input plus output under the ceiling.
Step 12: read the error, then decide whether to retry
DeepSeek’s error-code page, read on 12 November 2026, has rows for 400, 401, 402, 422, 429 and 500 onward; 403, 404 and 408 are not among them. It lists 422 Invalid Parameters, with the cause “Your request contains invalid parameters.”
| Status | First thing to try | Retry unchanged? |
|---|---|---|
| 400 | Check the request body format against the docs | No |
| 401 | Check the key was copied in full and that DEEPSEEK_API_KEY is set in the shell that runs the code | No |
| 402 | Top up the balance (DeepSeek: “go to the Top up page to add funds”) | No |
| 422 | Check parameter names and values, including thinking and reasoning_effort | No |
| 429 | Slow down: add backoff with jitter and limit concurrency | Yes, with backoff |
| 500 onward | Server-side: wait and retry with backoff | Yes, with backoff |
Resending a 400, 401, 402 or 422 unchanged repeats the same failure, so only 429 and 500 onward belong in a retry loop. A minimal backoff wrapper:
import random
import time
from openai import APIStatusError
def call_with_retry(messages, max_tokens, max_retries=5):
for attempt in range(max_retries):
try:
return client.chat.completions.create(
model="deepseek-flash",
messages=messages,
max_tokens=max_tokens,
)
except APIStatusError as e:
if e.status_code != 429 and e.status_code < 500:
raise
if attempt == max_retries - 1:
raise
sleep_time = 2 ** attempt + random.uniform(0, 1)
time.sleep(sleep_time)
Step 13: what 10,000 requests cost at peak and off-peak, and how to keep the cache hitting
DeepSeek’s pricing page lists V4.1-Flash at $0.003 off-peak and $0.006 at peak per 1M cache-hit input tokens, $0.15 and $0.30 for cache-miss input, and $0.60 and $1.20 for output, with peak and off-peak pricing in force since 16 August 2026, and our comparison of DeepSeek, Haiku 5.5 and Gemini Flash sets those list prices against other vendors.
Peak hours are 01:00 to 04:00 and 06:00 to 10:00 UTC, Monday to Friday, excluding Chinese public holidays, and every other hour is off-peak. That is 7 hours a day for 5 days: 35 of the 168 hours in a week, or 20.8% before holidays are removed. In Central European Time (UTC+1 in November) the windows read 02:00 to 05:00 and 07:00 to 11:00. In US Pacific Standard Time (UTC-8) they read 17:00 to 20:00 and 22:00 to 02:00. Because the windows are defined in UTC, the first one of the week starts on Sunday at 17:00 Pacific and the last ends on Friday at 02:00.
To size a top-up, take one defined job: 10,000 requests of 2,000 input and 500 output tokens each, which is 20 million input tokens and 5 million output tokens, with no cache hits. At peak the input half costs $6.00 and the output half $6.00, $12.00 in total. Every off-peak rate is half the peak rate, so the same job comes to $6.00. We calculated these figures from DeepSeek’s published rates; they are not billed amounts.
Cache hits shrink only the input half. If every input token hit the cache at peak, the 20 million input tokens would cost $0.12 and the $6.00 for output would stay, so output length, which max_tokens limits, is the lever left. DeepSeek’s context-caching guide says the disk cache matches only the prefix of your input. Put static content first (system prompt, few-shot examples, a long reference document) and per-request content last. At peak a cache-hit input token costs 50 times less than a miss.
A reply of 1,000 output tokens costs $0.0012 at the peak output rate, so for your own first call, apply the rates above to the token counts in the usage object.
For one outside reference point, Mistral’s pricing page lists Mistral Large 4 at $0.70 per 1M input and $2.10 per 1M output tokens (checked on 12 November 2026), which makes the same job $14.00 plus $10.50, or $24.50, against DeepSeek’s $12.00 at peak and $6.00 off-peak. This is a list-price sum with no caching and says nothing about quality.
License: the weights are open
For the 1017 revision, the model repository on dell.huggingface.co states that the repository and the model weights are licensed under the MIT License, so the hosted API is not the only way to run it. Our report on the MIT-licensed 1017 update covers the release.
Function calling and tool use
DeepSeek’s tool-calls guide follows the OpenAI schema: define a tools array with a JSON Schema for each function, send it with the conversation, and check the response for a tool call before executing anything. The guide notes that the model itself does not execute functions; your code supplies get_weather or whatever you expose. Validate the arguments against your schema before running the function.
import json
def get_weather(city):
return {"city": city, "forecast": "sunny"}
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}
]
messages = [{"role": "user", "content": "What is the weather in Lisbon?"}]
response = client.chat.completions.create(
model="deepseek-flash", messages=messages, tools=tools
)
message = response.choices[0].message
if message.tool_calls:
messages.append(message)
for call in message.tool_calls:
arguments = json.loads(call.function.arguments)
result = get_weather(**arguments)
messages.append(
{"role": "tool", "tool_call_id": call.id, "content": json.dumps(result)}
)
final_response = client.chat.completions.create(
model="deepseek-flash", messages=messages, tools=tools
)
print(final_response.choices[0].message.content)
else:
print(message.content)
Pointing Claude Code, Codex and OpenCode at the same key
The key also works without code. DeepSeek’s quickstart says tools such as Claude Code, GitHub Copilot and OpenCode can use DeepSeek as the backend model directly, with no code required. For a tool that speaks the Anthropic format, use these three values from the table in step 5:
- Base URL:
https://api.deepseek.com/anthropic - API key: the same platform key from step 2
- Model:
deepseek-flash
For Codex, the changelog says the DeepSeek API natively supports the OpenAI Responses API format and is specifically adapted for Codex. For DeepSeek’s own agent tool, the changelog recommends upgrading to DeepSeek Harness 0.2.1-rc.1 or later for the best experience with V4.1-Flash-1017.




