OpenAI 兼容接口参数速查表
兼容 /v1/chat/completions 的请求字段对照(仅需替换 base_url 即可对接各厂商)。
广告位(百度联盟文中广告位)
| 参数名称 | 取值范围 | 含义 | 推荐值 | 示例 |
|---|---|---|---|---|
| base_url | 字符串 | 服务地址(替换厂商域名) | https://api.openai.com/v1 | https://api.openai.com/v1 |
| api_key | 字符串 | 鉴权密钥 | sk-... | sk-... |
| model | 字符串 | 模型名 | gpt-4o-mini | gpt-4o-mini |
| messages | 数组 | 对话消息列表 | [{"role":"user","content":"hi"}] | 见示例 |
| temperature | 0~2 | 采样温度(详见 LLM 基础参数) | 0.7 | 0.7 |
| tools | 数组 | 函数调用定义 | [{"type":"function",...}] | [...] |
| response_format | 对象 | 输出格式约束 | {"type":"json_object"} | 见示例 |
| stream | true/false | 流式返回 | true | true |
最小调用示例(curl)
curl https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"你好"}]}'强制 JSON 输出
{"model":"gpt-4o-mini","messages":[{"role":"user","content":"返回 JSON"}],"response_format":{"type":"json_object"}}广告位(百度联盟信息流广告位)