OpenAI Chat
Interface description: Compatible endpoint of OpenAI Chat Completions API, supports stream streaming output. The request, response and error formats fully comply with the OpenAI specifications; authentication uses Authorization: Bearer <API Key> (included by OpenAI SDK by default). Existing OpenAI SDK or ecological tools only need to replace the baseURL and API Key to access, and billing is based on AiToEarn points.
Before calling this interface, please request the “Conversation Model List” interface (GET /api/ai/models/chat) to obtain the currently available model list.
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"
}
}Authorizations
Pass the API Key obtained from AiToEarn. Go to the "API Key Tutorial". Example: Bearer xxx.
Body
Model ID. First call the "Conversation Model List" interface (GET /api/ai/models/chat) and pass in the data[n].name returned by it.
Whether to stream the return
Response
Native third-party protocol response or SSE data, not wrapped in the AiToEarn common response envelope.
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"
}
}
