DeepSeek API 快速开始
如果你只是想确认 API 能不能用,先记住当前三个核心值:
| 项目 | 当前值 |
|---|---|
| OpenAI 兼容 Base URL | https://api.deepseek.com |
| Anthropic 兼容 Base URL | https://api.deepseek.com/anthropic |
| 当前主模型 | deepseek-flash |
本页校对日期:2026-09-25。DeepSeek 更新速度较快,正式部署前建议再查看官方快速开始。
1. 创建 API Key
前往 DeepSeek 开放平台创建 API Key。不要把真实 Key 提交到 Git,也不要写进公开网页前端。
建议在服务端使用环境变量:
DEEPSEEK_API_KEY=sk-xxxxxxxx
2. 用 curl 验证
curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{
"model": "deepseek-flash",
"messages": [
{"role": "user", "content": "用一句话解释什么是 RAG"}
]
}'
只要返回 JSON 且 choices 中有模型输出,就说明 Key、网络和模型名都基本正常。
3. 选择 SDK
DeepSeek 的 OpenAI 兼容接口可以直接复用 OpenAI SDK:
如果你用的是 Claude Code 等 Anthropic 生态工具,则使用 https://api.deepseek.com/anthropic:
Codex 当前可通过 DeepSeek 原生支持的 Responses API 接入:
4. 先用 deepseek-flash
对于第一次接入,建议先用:
deepseek-flash
官方当前文档将它对应到 DeepSeek-V4.1-Flash。旧名称可能仍有兼容路由,但新项目不要继续把旧模型名写死。
5. 出错先看这几个地方
401:API Key 不正确或请求头错误。402:余额/计费相关问题。429:频率、并发或服务繁忙。model not found:模型名过期或写错。- Agent / thinking 多轮报
reasoning_content:检查客户端是否正确回传思考字段。
完整整理见常见错误。