向会话发送事件
curl --request POST \
--url https://api.moonshot.cn/v1/sessions/{id}/events \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"type": "next_turn",
"events": [
{
"type": "user.message",
"data": {
"content": [
{
"type": "text",
"text": "Hello"
}
]
}
}
]
}
'import requests
url = "https://api.moonshot.cn/v1/sessions/{id}/events"
payload = {
"type": "next_turn",
"events": [
{
"type": "user.message",
"data": { "content": [
{
"type": "text",
"text": "Hello"
}
] }
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
type: 'next_turn',
events: [{type: 'user.message', data: {content: [{type: 'text', text: 'Hello'}]}}]
})
};
fetch('https://api.moonshot.cn/v1/sessions/{id}/events', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/sessions/{id}/events",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'type' => 'next_turn',
'events' => [
[
'type' => 'user.message',
'data' => [
'content' => [
[
'type' => 'text',
'text' => 'Hello'
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/sessions/{id}/events"
payload := strings.NewReader("{\n \"type\": \"next_turn\",\n \"events\": [\n {\n \"type\": \"user.message\",\n \"data\": {\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"Hello\"\n }\n ]\n }\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/sessions/{id}/events")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"type\": \"next_turn\",\n \"events\": [\n {\n \"type\": \"user.message\",\n \"data\": {\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"Hello\"\n }\n ]\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/sessions/{id}/events")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"type\": \"next_turn\",\n \"events\": [\n {\n \"type\": \"user.message\",\n \"data\": {\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"Hello\"\n }\n ]\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"event_id": "sevt_01h455vb4pex5vsknk084sn02q"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}接收用户事件作为会话输入,返回 202。
- 排队的
user.message输入按到达顺序投递,每个轮次一条(type: next_turn,默认值),或在下一个步骤边界注入运行中的轮次(type: steer)。 user.interrupt事件停止运行中的轮次而不进入队列,且必须是请求中唯一的事件。详见其模型。- 消息内容中的文件块会自动作为文件资源绑定到会话。
- 空消息以默认提示词(
Continue.)唤醒智能体。已终止的会话拒绝输入,返回 400failed_precondition_error。
POST
/
v1
/
sessions
/
{id}
/
events
向会话发送事件
curl --request POST \
--url https://api.moonshot.cn/v1/sessions/{id}/events \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"type": "next_turn",
"events": [
{
"type": "user.message",
"data": {
"content": [
{
"type": "text",
"text": "Hello"
}
]
}
}
]
}
'import requests
url = "https://api.moonshot.cn/v1/sessions/{id}/events"
payload = {
"type": "next_turn",
"events": [
{
"type": "user.message",
"data": { "content": [
{
"type": "text",
"text": "Hello"
}
] }
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
type: 'next_turn',
events: [{type: 'user.message', data: {content: [{type: 'text', text: 'Hello'}]}}]
})
};
fetch('https://api.moonshot.cn/v1/sessions/{id}/events', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/sessions/{id}/events",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'type' => 'next_turn',
'events' => [
[
'type' => 'user.message',
'data' => [
'content' => [
[
'type' => 'text',
'text' => 'Hello'
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/sessions/{id}/events"
payload := strings.NewReader("{\n \"type\": \"next_turn\",\n \"events\": [\n {\n \"type\": \"user.message\",\n \"data\": {\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"Hello\"\n }\n ]\n }\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/sessions/{id}/events")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"type\": \"next_turn\",\n \"events\": [\n {\n \"type\": \"user.message\",\n \"data\": {\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"Hello\"\n }\n ]\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/sessions/{id}/events")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"type\": \"next_turn\",\n \"events\": [\n {\n \"type\": \"user.message\",\n \"data\": {\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"Hello\"\n }\n ]\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"event_id": "sevt_01h455vb4pex5vsknk084sn02q"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}路径参数
会话 ID。
Pattern:
^sesn_[0-9a-hjkmnp-tv-z]{26}$请求体
application/json
响应
事件已接受。返回排队输入的 event_id(user.interrupt 请求不携带)。
接受的排队输入的响应:排队输入的 event_id;user.interrupt 请求不携带(它不入队)。
已接受排队输入的事件 ID。待处理列表、撤回与消费回显(复用该 ID 作为自身事件 id)通过它进行关联。当部署提供输入队列时,每个排队输入都会设置此字段。否则不存在。user.interrupt 请求不产生排队输入,此字段始终不存在。
Pattern:
^sevt_[0-9a-hjkmnp-tv-z]{26}$此页面对您有帮助吗?