ChatCompletions格式
根据对话历史创建模型响应。支持流式和非流式响应。
兼容 OpenAI Chat Completions API。
Try It
POST
/v1/chat/completionshttps://api-platform.ope.ai认证
使用 Bearer Token 认证。
- Header:
Authorization: Bearer <api-key> - 示例:
Authorization: Bearer sk-xxxxxx
请求体(application/json)
以下字段按 OpenAI Chat Completions API 官方格式列出。
| 字段 | 类型 | 必填 | 说明 | 默认值 / 范围 |
|---|---|---|---|---|
model | string | 是 | 模型 ID | - |
messages | array<object> | 是 | 对话消息列表 | - |
temperature | number | 否 | 采样温度 | 默认 1;范围 0~2 |
top_p | number | 否 | 核采样参数 | 默认 1;范围 0~1 |
n | integer | 否 | 生成数量 | 默认 1;范围 >=1 |
stream | boolean | 否 | 是否流式响应 | 默认 false |
stream_options | object | 否 | 流式参数 | - |
stop | string | array<string> | 否 | 停止序列 | - |
max_tokens | integer | 否 | 最大生成 Token 数 | - |
max_completion_tokens | integer | 否 | 最大补全 Token 数 | - |
presence_penalty | number | 否 | 话题惩罚 | 默认 0;范围 -2~2 |
frequency_penalty | number | 否 | 频率惩罚 | 默认 0;范围 -2~2 |
logit_bias | object | 否 | Logit 偏置 | - |
user | string | 否 | 终端用户标识 | - |
tools | array<object> | 否 | 工具列表 | - |
tool_choice | string | object | 否 | 工具选择策略 | - |
response_format | object | 否 | 响应格式 | - |
seed | integer | 否 | 随机种子 | - |
reasoning_effort | "low" | "medium" | "high" | 否 | 推理强度(用于支持推理的模型) | - |
modalities | array<string> | 否 | 输出模态 | - |
audio | object | 否 | 音频输出配置 | - |
请求示例
下方域名为示例:
https://api-platform.ope.ai。
- cURL
- JavaScript
- Go
- Python
- Java
- C#
curl -X POST "https://api-platform.ope.ai/v1/chat/completions" \
-H "Authorization: Bearer $OPEAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{
"role": "user",
"content": "hello"
}
]
}'
const url = "https://api-platform.ope.ai/v1/chat/completions";
const apiKey = process.env.OPEAI_API_KEY;
const res = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "deepseek-v4-flash",
messages: [{ role: "user", content: "hello" }],
}),
});
console.log(await res.json());
package main
import (
"bytes"
"fmt"
"net/http"
"os"
)
func main() {
body := []byte(`{"model":"deepseek-v4-flash","messages":[{"role":"user","content":"hello"}]}`)
req, _ := http.NewRequest("POST", "https://api-platform.ope.ai/v1/chat/completions", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("OPEAI_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println(resp.Status)
}
import os
import requests
resp = requests.post(
"https://api-platform.ope.ai/v1/chat/completions",
headers={
"Authorization": f"Bearer {os.environ.get('OPEAI_API_KEY')}",
"Content-Type": "application/json",
},
json={
"model": "deepseek-v4-flash",
"messages": [{"role": "user", "content": "hello"}],
},
timeout=60,
)
print(resp.json())
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("OPEAI_API_KEY");
String url = "https://api-platform.ope.ai/v1/chat/completions";
String json = """
{
"model": "deepseek-v4-flash",
"messages": [
{ "role": "user", "content": "hello" }
]
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}
}
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
public class Program
{
public static async Task Main()
{
var apiKey = Environment.GetEnvironmentVariable("OPEAI_API_KEY");
var url = "https://api-platform.ope.ai/v1/chat/completions";
var json = """
{
"model": "deepseek-v4-flash",
"messages": [
{ "role": "user", "content": "hello" }
]
}
""";
using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var resp = await http.PostAsync(url, content);
Console.WriteLine((int)resp.StatusCode);
Console.WriteLine(await resp.Content.ReadAsStringAsync());
}
}
响应示例
- 200
- 400
- 429
{
"id": "string",
"object": "chat.completion",
"created": 0,
"model": "string",
"choices": [
{
"index": 0,
"message": {
"role": "system",
"content": "string",
"name": "string",
"tool_calls": [
{
"id": "string",
"type": "function",
"function": { "name": "string", "arguments": "string" }
}
],
"tool_call_id": "string",
"reasoning_content": "string"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0,
"prompt_tokens_details": {
"cached_tokens": 0,
"text_tokens": 0,
"audio_tokens": 0,
"image_tokens": 0
},
"completion_tokens_details": {
"text_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0
}
},
"system_fingerprint": "string"
}
{
"error": { "message": "string", "type": "string", "param": "string", "code": "string" }
}
{
"error": { "message": "string", "type": "string", "param": "string", "code": "string" }
}