对话 Beta
执行对话,支持或不支持流式输出。
针对所选 LLM 提供方执行一轮对话。
POST /chat/conversation/execute
执行单轮对话:将传入的用户消息持久化为不可变的 ConversationRecord,调用由 llm_provider_id 引用的具体 CognitiveInfrastructureLLMProvider,将传出的助手消息持久化为另一条不可变的 ConversationRecord,并返回助手输出及用量元数据。 该端点是多提供方聊天编排的运行时入口。可通过 ConversationManagement 容器实施治理(组织边界、允许的提供方、记忆策略等)。
认证: Bearer 令牌
请求体
对话执行请求载荷。
响应
-
200成功。 -
400请求错误(缺少必填字段或标识符无效)。 -
403禁止访问(对话治理不允许该提供方,或存在跨组织访问)。 -
500执行此操作时出错。
curl -X POST https://api.sommatic.ai/chat/conversation/execute \
-H "Authorization: Bearer $SOMMATIC_TOKEN" \
-H "Content-Type: application/json" \
-d '{}'const response = await fetch('https://api.sommatic.ai/chat/conversation/execute', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SOMMATIC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
});
const { success, message, result } = await response.json();import os
import requests
response = requests.post(
"https://api.sommatic.ai/chat/conversation/execute",
headers={
"Authorization": f"Bearer {os.environ['SOMMATIC_TOKEN']}",
},
json={},
)
data = response.json() 响应
{
"status": 200,
"success": true,
"message": "Operation completed successfully",
"result": {
"conversation_id": "c-4c3f0f2b7a1a4f7a9a1b2c3d4e5f6a7b",
"conversation_slug": "convo.ops.support.001",
"llm_provider_id": "llmprov-8f3c1a2b4d5e6f",
"llm_provider_slug": "llm.openai.gpt4_1",
"record_user_id": "rec-usr-001",
"record_assistant_id": "rec-asst-002",
"output": {
"text": "Here is a summary of the anomalies..."
},
"usage": {
"input_tokens": 123,
"output_tokens": 456,
"total_tokens": 579,
"latency_ms": 832
}
}
}{
"status": 400,
"success": false,
"message": "Please provide organization_id, conversation_id, llm_provider_id and message.text",
"result": null
}{
"status": 403,
"success": false,
"message": "Selected provider is not allowed for this conversation",
"result": null
}{
"status": 500,
"success": false,
"message": "Something went wrong while performing this action",
"result": null
}针对所选 LLM 提供方执行一轮对话,并以 SSE 流式返回。
POST /chat/conversation/execute/stream
POST /chat/conversation/execute 的流式版本。建立持久 SSE 连接,在 LLM 提供方返回 token 片段时逐一推送。连接生命周期如下:
- event: open:完成上下文校验后、首个 token 之前立即发送。
- event: chunk:每个 token 增量发送一次 { text, index }。
- event: done:完整响应持久化后发送一次;载荷与同步 /execute 端点返回的 JSON 响应完全一致。
- event: error:发生任何失败时发送,随后关闭流。 现有的 POST /chat/conversation/execute 端点保持不变。两个端点共享同一业务逻辑,并生成相同的持久化输出。
认证: Bearer 令牌
请求体
对话执行请求载荷(结构与 /execute 相同)。
响应
-
200SSE 流(text/event-stream)。
curl -X POST https://api.sommatic.ai/chat/conversation/execute/stream \
-H "Authorization: Bearer $SOMMATIC_TOKEN" \
-H "Content-Type: application/json" \
-d '{}' \
-Nconst response = await fetch('https://api.sommatic.ai/chat/conversation/execute/stream', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SOMMATIC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
});
const { success, message, result } = await response.json();import os
import requests
response = requests.post(
"https://api.sommatic.ai/chat/conversation/execute/stream",
headers={
"Authorization": f"Bearer {os.environ['SOMMATIC_TOKEN']}",
},
json={},
)
data = response.json() 响应
{
"status": 200,
"success": true,
"message": "Operation completed successfully",
"result": {}
}