跳转到主要内容
POST
/
v1
/
chat
/
completions
Chat Completions
curl --request POST \
  --url https://openp.ai/v1/chat/completions
import requests

url = "https://openp.ai/v1/chat/completions"

response = requests.post(url)

print(response.text)
const options = {method: 'POST'};

fetch('https://openp.ai/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://openp.ai/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"net/http"
"io"
)

func main() {

url := "https://openp.ai/v1/chat/completions"

req, _ := http.NewRequest("POST", url, nil)

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://openp.ai/v1/chat/completions")
.asString();
require 'uri'
require 'net/http'

url = URI("https://openp.ai/v1/chat/completions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body
创建一次模型响应,基于对话上下文(messages 数组)。 所有支持对话能力的模型(OpenAI / Claude / Gemini / DeepSeek / Qwen 等)都可通过此接口调用。

请求

鉴权

Authorization: Bearer sk-XXXXXXXXXXXXXXXX

主要参数

字段类型必填说明
modelstring模型 ID,如 gpt-5.5
messagesarray对话历史,每条 { role, content }
temperaturenumber0-2,默认 1。越低越确定
top_pnumber0-1,核采样,与 temperature 二选一
ninteger生成几个候选(默认 1)
streambooleantrue 启用 SSE 流式
stream_optionsobject{ include_usage: true } 在流末追加 usage
max_tokensinteger最大输出 token 数(旧字段,部分模型已被 max_completion_tokens 替代)
max_completion_tokensinteger新字段,适用于 o3 / GPT-5
stopstring | array停止序列
presence_penaltynumber-2~2
frequency_penaltynumber-2~2
logit_biasmaptoken 偏置
seedinteger复现性种子
response_formatobject{ type: "json_object" } 或 JSON Schema
toolsarray函数调用工具列表
tool_choicestring | objectauto / required / { type:"function", function:{name:"..."}}
parallel_tool_callsboolean是否允许并行调用工具
reasoning_effortstringo3 / GPT-5 的推理强度:low / medium / high
modalitiesarray多模态输出,如 ["text","audio"]
audioobject音频输出选项
userstring终端用户标识(用于审计)

messages 结构

[
  {"role": "system",    "content": "你是中文助手"},
  {"role": "user",      "content": "讲个笑话"},
  {"role": "assistant", "content": "为什么程序员喜欢黑夜?因为没有 bug。"},
  {"role": "user",      "content": [
    {"type": "text", "text": "看图说话"},
    {"type": "image_url", "image_url": {"url": "https://..."}}
  ]}
]
支持的 role:system / user / assistant / tool(函数返回)。

响应

{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "created": 1715750400,
  "model": "gpt-5.5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "回答内容..."
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 27,
    "completion_tokens": 19,
    "total_tokens": 46,
    "prompt_tokens_details": { "cached_tokens": 0 },
    "completion_tokens_details": { "reasoning_tokens": 0 }
  },
  "system_fingerprint": "fp_..."
}
finish_reason 可能值:stop / length / tool_calls / content_filter

流式响应

stream: true 时,服务端按 SSE 格式推送 chunk:
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"content":"你"},"index":0}]}

data: {"id":"chatcmpl-...","choices":[{"delta":{"content":"好"},"index":0}]}

data: {"id":"chatcmpl-...","choices":[{"delta":{},"index":0,"finish_reason":"stop"}]}

data: [DONE]
stream_options.include_usage: true 后,会在最后多发一条带 usage 的 chunk:
data: {"id":"chatcmpl-...","choices":[],"usage":{"prompt_tokens":...,"completion_tokens":...}}

函数调用

{
  "model": "gpt-5.5",
  "messages": [{"role": "user", "content": "上海天气"}],
  "tools": [{
    "type": "function",
    "function": {
      "name": "get_weather",
      "description": "Get weather",
      "parameters": {
        "type": "object",
        "properties": {"city": {"type": "string"}},
        "required": ["city"]
      }
    }
  }]
}
响应中:
{
  "choices": [{
    "message": {
      "role": "assistant",
      "content": null,
      "tool_calls": [{
        "id": "call_abc",
        "type": "function",
        "function": {"name": "get_weather", "arguments": "{\"city\":\"上海\"}"}
      }]
    },
    "finish_reason": "tool_calls"
  }]
}
执行工具后把结果追加到 messages:
{"role": "tool", "tool_call_id": "call_abc", "content": "上海今天 26°C,晴"}
再次调用 chat completions 即可让模型基于工具结果继续回答。

推理模型

对 o3 / GPT-5 系列,使用 reasoning_effort:
{
  "model": "o3-mini-high",
  "messages": [{"role": "user", "content": "证明 √2 是无理数"}],
  "reasoning_effort": "high",
  "max_completion_tokens": 4096
}
也可使用带后缀的模型 ID(o3-mini-low / -medium / -high),效果等价。

错误

常见错误见 错误码