NAAPI 提供的 OpenAI Chat Completions 兼容接口,适合 OpenAI SDK、聊天客户端和 AI Agent 快速迁移。
https://naapi.cc/v1POST https://naapi.cc/v1/chat/completionsAuthorization: Bearer <API_KEY>choices[0].message.contentchoices[0].delta.contentNAAPI_API_KEY 环境变量读取naapi.apifox.cn是文档域名,不是 API 请求域名。
client.chat.completions.create(...)messages 对话数组previous_response_id 或 Responses 工具协议,优先使用 /v1/responses。MODEL 替换为账户当前可用的模型 ID。| 字段 | 必填 | 说明 |
|---|---|---|
model | 是 | 模型 ID |
messages | 是 | system / user / assistant / tool 消息数组 |
stream | 否 | true 返回 SSE 流,默认 false |
temperature | 否 | 采样温度 |
max_tokens | 否 | 传统最大输出 Token 数 |
max_completion_tokens | 否 | 新式最大补全 Token 数 |
tools | 否 | OpenAI 函数工具定义 |
tool_choice | 否 | auto、none、required 或指定函数 |
response_format | 否 | JSON 模式或 JSON Schema |
stream_options.include_usage | 否 | 流式结束前返回 usage |
reasoning_effort | 否 | 支持的模型可使用 low / medium / high |
stream: true。input / instructions 发到此接口。tool_call_id。response_format,业务侧仍要校验。error.message;400 / 401 / 429 不要用相同参数盲目重试。| 状态 | 常见原因 | 处理 |
|---|---|---|
400 | 字段错误或模型不支持参数 | 读取 error.message 并修正请求 |
401 | API Key 缺失或无效 | 检查 Bearer 鉴权 |
429 | 频率、并发或额度限制 | 降低并发,检查账户状态 |
5xx | 上游或网关短暂异常 | 使用有上限的退避重试 |