AI 服务/Agent
发起对话
使用 X-Api-Key 发起或继续 Agent 对话。本接口不接受 Authorization: Bearer <API Key>。
省略 sessionId 时创建新会话,此时 messages 必须包含一条 role=user 的消息。继续已有会话、提交工具审批或等待续跑时必须传入 sessionId。运行中的会话返回业务码 18120,请改用断点续播接口。
成功响应是 AI SDK UI Message SSE 流,不使用 { code, data } 包裹。新会话标题生成后,流内会写入 data-title。需要人工审批时,流内会写入 data-approval-cost。
POST
/
api
/
ai
/
agent
/
chat
发起对话
curl --request POST \
--url https://aitoearn.cn/api/ai/agent/chat \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--data '{}'import requests
url = "https://aitoearn.cn/api/ai/agent/chat"
payload = {}
headers = {
"X-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('https://aitoearn.cn/api/ai/agent/chat', 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/agent/chat"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Api-Key", "<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": "AgentController_chat_example",
"object": "response"
}授权
需要从 AiToEarn 获取 API Key。点击前往「API Key 获取教程」。
请求体
application/json
会话 ID。省略时创建新会话。
模型。传 auto 或具体模型 ID,默认 auto。
推理强度。模型不支持该强度时会失败。
可用选项:
none, low, medium, high, xhigh, max 用户 IANA 时区,例如 Asia/Shanghai。
响应
第三方协议原生响应或 SSE 数据。不使用 AiToEarn 通用响应包裹。
第三方协议原生响应,不使用 AiToEarn 通用响应包裹。
最后修改于 2026年9月29日
⌘I
发起对话
curl --request POST \
--url https://aitoearn.cn/api/ai/agent/chat \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--data '{}'import requests
url = "https://aitoearn.cn/api/ai/agent/chat"
payload = {}
headers = {
"X-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('https://aitoearn.cn/api/ai/agent/chat', 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/agent/chat"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Api-Key", "<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": "AgentController_chat_example",
"object": "response"
}
