DeepSeek API key setup
Published 2026-10-08 · Updated 2026-10-21
A DeepSeek key is sk- followed by 32 lowercase hex characters, 35 characters total. It looks a lot like an old OpenAI key, which is why double-checking the base URL matters.
Setup
export DEEPSEEK_API_KEY="sk-..."
Base URL: https://api.deepseek.com/v1. DeepSeek is fully OpenAI-compatible.
Verify it
curl https://api.deepseek.com/v1/models \
-H "Authorization: Bearer $DEEPSEEK_API_KEY"
Python
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["DEEPSEEK_API_KEY"],
base_url="https://api.deepseek.com/v1",
)
resp = client.chat.completions.create(
model="deepseek-v4",
messages=[{"role": "user", "content": "Say hello"}],
)
print(resp.choices[0].message.content)
Worth knowing
deepseek-chatvsdeepseek-reasonerare the classic model aliases; the newer versioned ids (likedeepseek-v4) pin a specific release. The/modelsendpoint tells you what your key can actually call.- Balance endpoint.
GET /user/balancereturns the remaining credit in the account’s currency, the cheapest way to check whether a shared key still has money on it. - Off-peak discounts. DeepSeek has historically run cheaper pricing during off-peak UTC hours; worth checking the docs if you’re batching.
- No expiry by default. Keys don’t expire unless revoked, so a “verified” key can die the moment the owner rotates it, treat recency as your only signal.
If a key lists models but fails on chat with Insufficient Balance, the key is real but empty. Move to the next one.