curl 命令行调用随性 API:参数详解与实用技巧

作者:

在

最简调用

curl https://api.ns666.cfd/v1/chat/completions 
  -H "Content-Type: application/json" 
  -H "Authorization: Bearer $API_KEY" 
  -d '{"model":"deepseek-v4-flash","messages":[{"role":"user","content":"你好"}]}'

常用参数

参数 说明 示例
model 模型名称 deepseek-v4-flash
messages 对话历史 [{“role”:”user”,”content”:”hi”}]
temperature 随机性 0-2 0.7
max_tokens 最大输出长度 1000
stream 是否流式 true
top_p 核采样 0.9

流式输出

curl -N https://api.ns666.cfd/v1/chat/completions 
  -H "Content-Type: application/json" 
  -H "Authorization: Bearer $API_KEY" 
  -d '{"model":"deepseek-v4-flash","messages":[{"role":"user","content":"你好"}],"stream":true}'

-N 关闭缓冲,否则看不到实时输出。

查看响应头与耗时

curl -i -w "n耗时: %{time_total}sn" 
  https://api.ns666.cfd/v1/chat/completions 
  -H "Content-Type: application/json" 
  -H "Authorization: Bearer $API_KEY" 
  -d '{"model":"deepseek-v4-flash","messages":[{"role":"user","content":"hi"}]}'

列出可用模型

curl https://api.ns666.cfd/v1/models 
  -H "Authorization: Bearer $API_KEY"

常见错误

  • 401 Unauthorized — Key 错误或未带 Authorization 头
  • 403 Forbidden — 令牌被禁用或额度耗尽
  • 404 Not Found — 路径写错,应为 /v1/chat/completions
  • 429 Too Many Requests — 触发限流,降低频率

相关文档