DeepSeek Chat Completions 的认证头怎样写?
先说出你的答案
定义边界、关键机制、一个反例;P8题再补容量、失败与验证。
查看完整题解
参考回答
直接回答
用 HTTP 头 Authorization: Bearer <API_KEY>。OpenAI 兼容 SDK 会按所配置的 api_key 帮你构造。其他兼容协议的认证形式应按各自文档核对。
讲清原理
认证信息应由服务端持有。遇到 401 先查密钥来自哪个环境、是否过期或被撤销、请求是否走错服务入口。
例子与易错点
下面只构造一条带模拟值的请求,确认凭据位于 HTTP 头,且没有放进 JSON。
import httpx
request = httpx.Request(
"POST", "https://api.deepseek.com/chat/completions",
headers={"Authorization": "Bearer local-test-key"},
json={"model": "deepseek-flash", "messages": [{"role": "user", "content": "你好"}]},
)
assert request.headers["Authorization"] == "Bearer local-test-key"
assert b"local-test-key" not in request.content
print("the test credential exists only in the header")
和评分标准对照,你能独立回答到哪一步?
自评会安排下一次复习,不保存你的口述内容。
这道题,你掌握得怎么样?
掌握程度由你主动标记,阅读和收藏不会自动改变状态。