AI 服务/大语言模型
OpenAI 对话
接口说明:OpenAI Chat Completions API 的兼容端点,支持 stream 流式输出。请求、响应与错误格式完全遵循 OpenAI 规范;鉴权使用 Authorization: Bearer <API Key>(OpenAI SDK 默认携带),已有 OpenAI SDK 或生态工具只需替换 baseURL 与 API Key 即可接入,按 AiToEarn 积分计费。
调用本接口前,请先请求「对话模型列表」接口(GET /api/ai/models/chat),获取当前可用的模型列表。
POST
/
api
/
ai
/
chat
/
completions
OpenAI 对话
curl --request POST \
--url https://aitoearn.cn/api/ai/chat/completions \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "<string>",
"content": "<unknown>"
}
],
"model": "<string>"
}
'import requests
url = "https://aitoearn.cn/api/ai/chat/completions"
payload = {
"messages": [
{
"role": "<string>",
"content": "<unknown>"
}
],
"model": "<string>"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({messages: [{role: '<string>', content: '<unknown>'}], model: '<string>'})
};
fetch('https://aitoearn.cn/api/ai/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://aitoearn.cn/api/ai/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<unknown>\"\n }\n ],\n \"model\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
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))
}{
"id": "string",
"object": "string",
"created": "integer",
"model": "string",
"choices": [
{
"index": "integer",
"message": {
"role": "string",
"content": "string",
"reasoning_content": "string",
"tool_calls": [
"object"
]
},
"finish_reason": "string",
"native_finish_reason": "string"
}
],
"usage": {
"completion_tokens": "integer",
"total_tokens": "integer",
"prompt_tokens": "integer",
"prompt_tokens_details": "object | null",
"completion_tokens_details": "object | null"
}
}授权
传入从 AiToEarn 获取 API Key。点击前往「API Key 获取教程」。示例:Bearer xxx。
请求体
application/json
响应
第三方协议原生响应或 SSE 数据。不使用 AiToEarn 通用响应包裹。
最后修改于 2026年9月29日
⌘I
OpenAI 对话
curl --request POST \
--url https://aitoearn.cn/api/ai/chat/completions \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "<string>",
"content": "<unknown>"
}
],
"model": "<string>"
}
'import requests
url = "https://aitoearn.cn/api/ai/chat/completions"
payload = {
"messages": [
{
"role": "<string>",
"content": "<unknown>"
}
],
"model": "<string>"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({messages: [{role: '<string>', content: '<unknown>'}], model: '<string>'})
};
fetch('https://aitoearn.cn/api/ai/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://aitoearn.cn/api/ai/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<unknown>\"\n }\n ],\n \"model\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
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))
}{
"id": "string",
"object": "string",
"created": "integer",
"model": "string",
"choices": [
{
"index": "integer",
"message": {
"role": "string",
"content": "string",
"reasoning_content": "string",
"tool_calls": [
"object"
]
},
"finish_reason": "string",
"native_finish_reason": "string"
}
],
"usage": {
"completion_tokens": "integer",
"total_tokens": "integer",
"prompt_tokens": "integer",
"prompt_tokens_details": "object | null",
"completion_tokens_details": "object | null"
}
}
