ChatCompletions格式
根据对话历史创建模型响应。支持流式和非流式响应。
兼容 OpenAI Chat Completions API。
POST
/v1/chat/completionsChatCompletions格式
根据对话历史创建模型响应。支持流式和非流式响应。 兼容 OpenAI Chat Completions API。
鉴权: 使用 Bearer Token 认证。 格式: `Authorization: Bearer sk-xxxxxx`
请求体
必填
Content-Type: application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型 ID 示例: "gpt-4" |
messages | array<object> | 是 | 对话消息列表 |
[] | object | ||
role | string | 是 | 消息角色 可选值: system, user, assistant, tool, developer |
content | string | array<object> | 是 | 消息内容 |
[] | object | ||
type | string | 可选值: text, image_url, input_audio, file, video_url | |
text | string | ||
image_url | object | ||
url | string | 图片 URL 或 base64 | |
detail | string | 可选值: low, high, auto | |
input_audio | object | ||
data | string | Base64 编码的音频数据 | |
format | string | 可选值: wav, mp3 | |
file | object | ||
filename | string | ||
file_data | string | ||
file_id | string | ||
video_url | object | ||
url | string | ||
name | string | 发送者名称 | |
tool_calls | array<object> | ||
[] | object | ||
id | string | ||
type | string | 示例: "function" | |
function | object | ||
name | string | ||
arguments | string | ||
tool_call_id | string | 工具调用 ID(用于 tool 角色消息) | |
reasoning_content | string | 推理内容 | |
temperature | number | 采样温度 默认: 1 | |
top_p | number | 核采样参数 默认: 1 | |
n | integer | 生成数量 默认: 1 | |
stream | boolean | 是否流式响应 默认: false | |
stream_options | object | ||
include_usage | boolean | ||
stop | string | array<string> | 停止序列 | |
[] | string | ||
max_tokens | integer | 最大生成 Token 数 | |
max_completion_tokens | integer | 最大补全 Token 数 | |
presence_penalty | number | 默认: 0 | |
frequency_penalty | number | 默认: 0 | |
logit_bias | object | ||
user | string | ||
tools | array<object> | ||
[] | object | ||
type | string | 示例: "function" | |
function | object | ||
name | string | ||
description | string | ||
parameters | object | JSON Schema 格式的参数定义 | |
tool_choice | string | object | ||
type | string | ||
function | object | ||
name | string | ||
response_format | object | ||
type | string | 可选值: text, json_object, json_schema | |
json_schema | object | JSON Schema 定义 | |
seed | integer | ||
reasoning_effort | string | 推理强度 (用于支持推理的模型) 可选值: low, medium, high | |
modalities | array<string> | ||
[] | string | 可选值: text, audio | |
audio | object | ||
voice | string | ||
format | string |
示例代码
curl -X POST "https://api.nodeprice.com/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"model": "string",
"messages": [
{
"role": "system",
"content": "string",
"name": "string",
"tool_calls": [
{
"id": "string",
"type": "string",
"function": {
"name": "string",
"arguments": "string"
}
}
],
"tool_call_id": "string",
"reasoning_content": "string"
}
],
"temperature": 1,
"top_p": 1,
"n": 1,
"stream": false,
"stream_options": {
"include_usage": false
},
"stop": "string",
"max_tokens": 0,
"max_completion_tokens": 0,
"presence_penalty": 0,
"frequency_penalty": 0,
"logit_bias": {},
"user": "string",
"tools": [
{
"type": "string",
"function": {
"name": "string",
"description": "string",
"parameters": {}
}
}
],
"tool_choice": "none",
"response_format": {
"type": "text",
"json_schema": {}
},
"seed": 0,
"reasoning_effort": "low",
"modalities": [
"text"
],
"audio": {
"voice": "string",
"format": "string"
}
}'const url = "https://api.nodeprice.com/v1/chat/completions";
const body = {
"model": "string",
"messages": [
{
"role": "system",
"content": "string",
"name": "string",
"tool_calls": [
{
"id": "string",
"type": "string",
"function": {
"name": "string",
"arguments": "string"
}
}
],
"tool_call_id": "string",
"reasoning_content": "string"
}
],
"temperature": 1,
"top_p": 1,
"n": 1,
"stream": false,
"stream_options": {
"include_usage": false
},
"stop": "string",
"max_tokens": 0,
"max_completion_tokens": 0,
"presence_penalty": 0,
"frequency_penalty": 0,
"logit_bias": {},
"user": "string",
"tools": [
{
"type": "string",
"function": {
"name": "string",
"description": "string",
"parameters": {}
}
}
],
"tool_choice": "none",
"response_format": {
"type": "text",
"json_schema": {}
},
"seed": 0,
"reasoning_effort": "low",
"modalities": [
"text"
],
"audio": {
"voice": "string",
"format": "string"
}
};
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer <token>"
},
body: JSON.stringify(body)
});
console.log(await response.text());package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
url := "https://api.nodeprice.com/v1/chat/completions"
body := strings.NewReader(`{
"model": "string",
"messages": [
{
"role": "system",
"content": "string",
"name": "string",
"tool_calls": [
{
"id": "string",
"type": "string",
"function": {
"name": "string",
"arguments": "string"
}
}
],
"tool_call_id": "string",
"reasoning_content": "string"
}
],
"temperature": 1,
"top_p": 1,
"n": 1,
"stream": false,
"stream_options": {
"include_usage": false
},
"stop": "string",
"max_tokens": 0,
"max_completion_tokens": 0,
"presence_penalty": 0,
"frequency_penalty": 0,
"logit_bias": {},
"user": "string",
"tools": [
{
"type": "string",
"function": {
"name": "string",
"description": "string",
"parameters": {}
}
}
],
"tool_choice": "none",
"response_format": {
"type": "text",
"json_schema": {}
},
"seed": 0,
"reasoning_effort": "low",
"modalities": [
"text"
],
"audio": {
"voice": "string",
"format": "string"
}
}`)
req, err := http.NewRequest("POST", url, body)
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer <token>")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(data))
}import requests
url = "https://api.nodeprice.com/v1/chat/completions"
body = """{
"model": "string",
"messages": [
{
"role": "system",
"content": "string",
"name": "string",
"tool_calls": [
{
"id": "string",
"type": "string",
"function": {
"name": "string",
"arguments": "string"
}
}
],
"tool_call_id": "string",
"reasoning_content": "string"
}
],
"temperature": 1,
"top_p": 1,
"n": 1,
"stream": false,
"stream_options": {
"include_usage": false
},
"stop": "string",
"max_tokens": 0,
"max_completion_tokens": 0,
"presence_penalty": 0,
"frequency_penalty": 0,
"logit_bias": {},
"user": "string",
"tools": [
{
"type": "string",
"function": {
"name": "string",
"description": "string",
"parameters": {}
}
}
],
"tool_choice": "none",
"response_format": {
"type": "text",
"json_schema": {}
},
"seed": 0,
"reasoning_effort": "low",
"modalities": [
"text"
],
"audio": {
"voice": "string",
"format": "string"
}
}"""
response = requests.request("POST", url, data=body, headers={
"Content-Type": "application/json",
"Authorization": "Bearer <token>"
})
print(response.text)OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n"
+ " \"model\": \"string\",\n"
+ " \"messages\": [\n"
+ " {\n"
+ " \"role\": \"system\",\n"
+ " \"content\": \"string\",\n"
+ " \"name\": \"string\",\n"
+ " \"tool_calls\": [\n"
+ " {\n"
+ " \"id\": \"string\",\n"
+ " \"type\": \"string\",\n"
+ " \"function\": {\n"
+ " \"name\": \"string\",\n"
+ " \"arguments\": \"string\"\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"tool_call_id\": \"string\",\n"
+ " \"reasoning_content\": \"string\"\n"
+ " }\n"
+ " ],\n"
+ " \"temperature\": 1,\n"
+ " \"top_p\": 1,\n"
+ " \"n\": 1,\n"
+ " \"stream\": false,\n"
+ " \"stream_options\": {\n"
+ " \"include_usage\": false\n"
+ " },\n"
+ " \"stop\": \"string\",\n"
+ " \"max_tokens\": 0,\n"
+ " \"max_completion_tokens\": 0,\n"
+ " \"presence_penalty\": 0,\n"
+ " \"frequency_penalty\": 0,\n"
+ " \"logit_bias\": {},\n"
+ " \"user\": \"string\",\n"
+ " \"tools\": [\n"
+ " {\n"
+ " \"type\": \"string\",\n"
+ " \"function\": {\n"
+ " \"name\": \"string\",\n"
+ " \"description\": \"string\",\n"
+ " \"parameters\": {}\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"tool_choice\": \"none\",\n"
+ " \"response_format\": {\n"
+ " \"type\": \"text\",\n"
+ " \"json_schema\": {}\n"
+ " },\n"
+ " \"seed\": 0,\n"
+ " \"reasoning_effort\": \"low\",\n"
+ " \"modalities\": [\n"
+ " \"text\"\n"
+ " ],\n"
+ " \"audio\": {\n"
+ " \"voice\": \"string\",\n"
+ " \"format\": \"string\"\n"
+ " }\n"
+ "}");
Request request = new Request.Builder()
.url("https://api.nodeprice.com/v1/chat/completions")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer <token>")
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());#include <stdio.h>
#include <curl/curl.h>
int main(void) {
CURL *curl = curl_easy_init();
if (curl == NULL) {
return 1;
}
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Authorization: Bearer <token>");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.nodeprice.com/v1/chat/completions");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\n"
+ " \"model\": \"string\",\n"
+ " \"messages\": [\n"
+ " {\n"
+ " \"role\": \"system\",\n"
+ " \"content\": \"string\",\n"
+ " \"name\": \"string\",\n"
+ " \"tool_calls\": [\n"
+ " {\n"
+ " \"id\": \"string\",\n"
+ " \"type\": \"string\",\n"
+ " \"function\": {\n"
+ " \"name\": \"string\",\n"
+ " \"arguments\": \"string\"\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"tool_call_id\": \"string\",\n"
+ " \"reasoning_content\": \"string\"\n"
+ " }\n"
+ " ],\n"
+ " \"temperature\": 1,\n"
+ " \"top_p\": 1,\n"
+ " \"n\": 1,\n"
+ " \"stream\": false,\n"
+ " \"stream_options\": {\n"
+ " \"include_usage\": false\n"
+ " },\n"
+ " \"stop\": \"string\",\n"
+ " \"max_tokens\": 0,\n"
+ " \"max_completion_tokens\": 0,\n"
+ " \"presence_penalty\": 0,\n"
+ " \"frequency_penalty\": 0,\n"
+ " \"logit_bias\": {},\n"
+ " \"user\": \"string\",\n"
+ " \"tools\": [\n"
+ " {\n"
+ " \"type\": \"string\",\n"
+ " \"function\": {\n"
+ " \"name\": \"string\",\n"
+ " \"description\": \"string\",\n"
+ " \"parameters\": {}\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"tool_choice\": \"none\",\n"
+ " \"response_format\": {\n"
+ " \"type\": \"text\",\n"
+ " \"json_schema\": {}\n"
+ " },\n"
+ " \"seed\": 0,\n"
+ " \"reasoning_effort\": \"low\",\n"
+ " \"modalities\": [\n"
+ " \"text\"\n"
+ " ],\n"
+ " \"audio\": {\n"
+ " \"voice\": \"string\",\n"
+ " \"format\": \"string\"\n"
+ " }\n"
+ "}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
CURLcode code = curl_easy_perform(curl);
if (code != CURLE_OK) {
fprintf(stderr, "%s\n", curl_easy_strerror(code));
}
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return 0;
}using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.nodeprice.com/v1/chat/completions");
request.Headers.Add("Authorization", "Bearer <token>");
request.Content = new StringContent("{\n"
+ " \"model\": \"string\",\n"
+ " \"messages\": [\n"
+ " {\n"
+ " \"role\": \"system\",\n"
+ " \"content\": \"string\",\n"
+ " \"name\": \"string\",\n"
+ " \"tool_calls\": [\n"
+ " {\n"
+ " \"id\": \"string\",\n"
+ " \"type\": \"string\",\n"
+ " \"function\": {\n"
+ " \"name\": \"string\",\n"
+ " \"arguments\": \"string\"\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"tool_call_id\": \"string\",\n"
+ " \"reasoning_content\": \"string\"\n"
+ " }\n"
+ " ],\n"
+ " \"temperature\": 1,\n"
+ " \"top_p\": 1,\n"
+ " \"n\": 1,\n"
+ " \"stream\": false,\n"
+ " \"stream_options\": {\n"
+ " \"include_usage\": false\n"
+ " },\n"
+ " \"stop\": \"string\",\n"
+ " \"max_tokens\": 0,\n"
+ " \"max_completion_tokens\": 0,\n"
+ " \"presence_penalty\": 0,\n"
+ " \"frequency_penalty\": 0,\n"
+ " \"logit_bias\": {},\n"
+ " \"user\": \"string\",\n"
+ " \"tools\": [\n"
+ " {\n"
+ " \"type\": \"string\",\n"
+ " \"function\": {\n"
+ " \"name\": \"string\",\n"
+ " \"description\": \"string\",\n"
+ " \"parameters\": {}\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"tool_choice\": \"none\",\n"
+ " \"response_format\": {\n"
+ " \"type\": \"text\",\n"
+ " \"json_schema\": {}\n"
+ " },\n"
+ " \"seed\": 0,\n"
+ " \"reasoning_effort\": \"low\",\n"
+ " \"modalities\": [\n"
+ " \"text\"\n"
+ " ],\n"
+ " \"audio\": {\n"
+ " \"voice\": \"string\",\n"
+ " \"format\": \"string\"\n"
+ " }\n"
+ "}", Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
}响应
200 成功创建响应
Content-Type: application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | ||
object | string | 示例: "chat.completion" | |
created | integer | ||
model | string | ||
choices | array<object> | ||
[] | object | ||
index | integer | ||
message | object | ||
role | string | 是 | 消息角色 可选值: system, user, assistant, tool, developer |
content | string | array<object> | 是 | 消息内容 |
[] | object | ||
type | string | 可选值: text, image_url, input_audio, file, video_url | |
text | string | ||
image_url | object | ||
url | string | 图片 URL 或 base64 | |
detail | string | 可选值: low, high, auto | |
input_audio | object | ||
data | string | Base64 编码的音频数据 | |
format | string | 可选值: wav, mp3 | |
file | object | ||
filename | string | ||
file_data | string | ||
file_id | string | ||
video_url | object | ||
url | string | ||
name | string | 发送者名称 | |
tool_calls | array<object> | ||
[] | object | ||
id | string | ||
type | string | 示例: "function" | |
function | object | ||
name | string | ||
arguments | string | ||
tool_call_id | string | 工具调用 ID(用于 tool 角色消息) | |
reasoning_content | string | 推理内容 | |
finish_reason | string | 可选值: stop, length, tool_calls, content_filter | |
usage | object | ||
prompt_tokens | integer | 提示词 Token 数 | |
completion_tokens | integer | 补全 Token 数 | |
total_tokens | integer | 总 Token 数 | |
prompt_tokens_details | object | ||
cached_tokens | integer | ||
text_tokens | integer | ||
audio_tokens | integer | ||
image_tokens | integer | ||
completion_tokens_details | object | ||
text_tokens | integer | ||
audio_tokens | integer | ||
reasoning_tokens | integer | ||
system_fingerprint | string |
400 请求参数错误
Content-Type: application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
error | object | ||
message | string | 错误信息 | |
type | string | 错误类型 | |
param | string | null | 相关参数 | |
code | string | null | 错误代码 |
429 请求频率限制
Content-Type: application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
error | object | ||
message | string | 错误信息 | |
type | string | 错误类型 | |
param | string | null | 相关参数 | |
code | string | null | 错误代码 |