curl --request POST \
--url https://api.poyo.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-5.2",
"messages": [
{
"role": "system",
"content": "You are a structured output assistant. Reply with JSON only."
},
{
"role": "user",
"content": "Generate a paginated list response example with fields items, page, page_size, total and sample values."
}
]
}
'import requests
url = "https://api.poyo.ai/v1/chat/completions"
payload = {
"model": "gpt-5.2",
"messages": [
{
"role": "system",
"content": "You are a structured output assistant. Reply with JSON only."
},
{
"role": "user",
"content": "Generate a paginated list response example with fields items, page, page_size, total and sample values."
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-5.2',
messages: [
{
role: 'system',
content: 'You are a structured output assistant. Reply with JSON only.'
},
{
role: 'user',
content: 'Generate a paginated list response example with fields items, page, page_size, total and sample values.'
}
]
})
};
fetch('https://api.poyo.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://api.poyo.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",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'gpt-5.2',
'messages' => [
[
'role' => 'system',
'content' => 'You are a structured output assistant. Reply with JSON only.'
],
[
'role' => 'user',
'content' => 'Generate a paginated list response example with fields items, page, page_size, total and sample values.'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.poyo.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-5.2\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a structured output assistant. Reply with JSON only.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Generate a paginated list response example with fields items, page, page_size, total and sample values.\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.poyo.ai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-5.2\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a structured output assistant. Reply with JSON only.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Generate a paginated list response example with fields items, page, page_size, total and sample values.\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.poyo.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"gpt-5.2\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a structured output assistant. Reply with JSON only.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Generate a paginated list response example with fields items, page, page_size, total and sample values.\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-9876543210",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-5.2",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The history of artificial intelligence (AI) dates back to the 1950s..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 320,
"total_tokens": 348
}
}{
"code": 400,
"error": {
"message": "Invalid request parameters: messages: Field required",
"type": "validation_error",
"details": {}
}
}{
"code": 401,
"error": {
"message": "Invalid API key",
"type": "authentication_error"
}
}{
"error": {
"message": "Model not found: no-such-model",
"type": "invalid_request_error",
"code": "model_not_found"
}
}Chat Completions
通用 Chat API 是与模型无关的接口,兼容 OpenAI Chat Completions 请求结构。传入 model id 和 messages,并可选择以服务器发送事件(SSE)流的方式返回。
curl --request POST \
--url https://api.poyo.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-5.2",
"messages": [
{
"role": "system",
"content": "You are a structured output assistant. Reply with JSON only."
},
{
"role": "user",
"content": "Generate a paginated list response example with fields items, page, page_size, total and sample values."
}
]
}
'import requests
url = "https://api.poyo.ai/v1/chat/completions"
payload = {
"model": "gpt-5.2",
"messages": [
{
"role": "system",
"content": "You are a structured output assistant. Reply with JSON only."
},
{
"role": "user",
"content": "Generate a paginated list response example with fields items, page, page_size, total and sample values."
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-5.2',
messages: [
{
role: 'system',
content: 'You are a structured output assistant. Reply with JSON only.'
},
{
role: 'user',
content: 'Generate a paginated list response example with fields items, page, page_size, total and sample values.'
}
]
})
};
fetch('https://api.poyo.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://api.poyo.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",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'gpt-5.2',
'messages' => [
[
'role' => 'system',
'content' => 'You are a structured output assistant. Reply with JSON only.'
],
[
'role' => 'user',
'content' => 'Generate a paginated list response example with fields items, page, page_size, total and sample values.'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.poyo.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"gpt-5.2\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a structured output assistant. Reply with JSON only.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Generate a paginated list response example with fields items, page, page_size, total and sample values.\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.poyo.ai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-5.2\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a structured output assistant. Reply with JSON only.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Generate a paginated list response example with fields items, page, page_size, total and sample values.\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.poyo.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"gpt-5.2\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a structured output assistant. Reply with JSON only.\"\n },\n {\n \"role\": \"user\",\n \"content\": \"Generate a paginated list response example with fields items, page, page_size, total and sample values.\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "chatcmpl-9876543210",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-5.2",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The history of artificial intelligence (AI) dates back to the 1950s..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 320,
"total_tokens": 348
}
}{
"code": 400,
"error": {
"message": "Invalid request parameters: messages: Field required",
"type": "validation_error",
"details": {}
}
}{
"code": 401,
"error": {
"message": "Invalid API key",
"type": "authentication_error"
}
}{
"error": {
"message": "Model not found: no-such-model",
"type": "invalid_request_error",
"code": "model_not_found"
}
}- 适用于大多数 LLM 的统一聊天 API 接口;哪些模型支持见 LLM 模型
- 通过 model 参数选择不同的 AI 模型
- 兼容 OpenAI Chat Completions API 格式
使用示例
基础对话
{
"model": "gpt-5.2",
"messages": [
{"role": "user", "content": "Explain vector databases in one sentence."}
]
}
系统提示词
{
"model": "claude-sonnet-4-5-20250929",
"messages": [
{"role": "system", "content": "You are a technical editor. Improve clarity of product copy."},
{"role": "user", "content": "Rewrite the button text 'Submission failed' to be friendly and actionable."}
]
}
多轮对话
{
"model": "gemini-3-flash-preview",
"messages": [
{"role": "user", "content": "Give me 3 customer support bot names."},
{"role": "assistant", "content": "1) HelpWave 2) CarePilot 3) SwiftSupport"},
{"role": "user", "content": "Add one style tag for each name."}
]
}
流式输出
{
"model": "gpt-5.2",
"messages": [
{"role": "user", "content": "Generate 5 short titles (max 6 words) about AI video generation."}
],
"stream": true
}
注意事项
- 使用
stream: true获取 SSE 流式响应。 - 不同模型支持的上下文长度、输出上限和可选参数可能不同。
- 对于需要工具或多模态结构化输入的新 OpenAI 兼容工作流,请使用 Responses API。
响应
非流式请求直接返回 Chat Completions 对象,不带code / data 包装。DeepSeek 等推理模型还会在 choices[].message.reasoning_content 中返回推理文本,并计入 usage.completion_tokens_details.reasoning_tokens。
流式输出
设置"stream": true 时,响应为 text/event-stream。每个事件是一行包含 chat.completion.chunk 对象的 data:,流以 data: [DONE] 结束:
data: {"id":"...","object":"chat.completion.chunk","model":"deepseek-v4-flash","choices":[{"index":0,"delta":{"role":"assistant"}}]}
data: {"id":"...","object":"chat.completion.chunk","model":"deepseek-v4-flash","choices":[{"index":0,"delta":{"content":"OK"}}]}
data: {"id":"...","object":"chat.completion.chunk","model":"deepseek-v4-flash","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":"stop"}],"usage":{"prompt_tokens":36,"completion_tokens":16,"total_tokens":52}}
data: [DONE]
- 文本在
choices[0].delta.content中返回。推理模型会先流式返回choices[0].delta.reasoning_content。 - 最后一个 chunk 携带
finish_reason和usage。
错误
401:缺少 API Key 或 API Key 无效。400:参数无效,或模型不支持 Chat Completions(例如gpt-5-6-sol只支持 Responses)。错误信息会列出支持的 URI。404:未知的 model id。
授权
所有 API 接口都需要 Bearer Token 认证。
创建 API Key:登录 PoYo,进入 仪表盘 → API 密钥(poyo.ai/zh/dashboard/api-key),点击创建 Key。
在请求头中添加:
Authorization: Bearer YOUR_API_KEY
请求体
模型名称。示例:gpt-5.2、claude-sonnet-4-5-20250929、gemini-3-flash-preview。
"gpt-5.2"
对话消息列表。每条消息包含 role 和 content。system 用于定义模型行为,user 用于用户输入,assistant 用于多轮对话中模型之前的回复。示例:[{"role": "user", "content": "Explain vector databases in one sentence."}]。
Show child attributes
Show child attributes
控制输出的随机性,范围 0-2。较低的值(如 0.2)使输出更确定,较高的值(如 1.8)使输出更随机。默认值:1.0。
0 <= x <= 21
生成的最大 token 数。不同模型的上限不同。
x >= 1256
是否使用流式输出。true 以 SSE 格式返回流式响应,false 一次性返回完整响应。默认值:false。
false
核采样参数,范围 0-1。控制生成文本的多样性。建议只使用 top_p 或 temperature 其中之一,不要同时使用。默认值:1.0。
0 <= x <= 11
频率惩罚,范围 -2.0 到 2.0。正值会降低重复相同词语的可能性。默认值:0。
-2 <= x <= 20
存在惩罚,范围 -2.0 到 2.0。正值会提高谈论新话题的可能性。默认值:0。
-2 <= x <= 20
停止序列。最多 4 个,遇到其中任一序列时停止生成。
"\n\nHuman:"
生成的补全数量。默认值:1。必须是普通数字,如 1,不要加引号。
x >= 11