Skip to main content
POST
/
chat-messages
A valid request URL is required to generate request examples
{ "event": "message", "task_id": "c3800678-a077-43df-a102-53f23ed20b88", "id": "b01a39de-3480-4f3e-9f1e-4841a80f8e5e", "message_id": "9da23599-e713-473b-982c-4328d4f5c78a", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "mode": "advanced-chat", "answer": "iPhone 13 Pro Max specs are listed here:...", "metadata": { "usage": { "prompt_tokens": 1033, "prompt_unit_price": "0.001", "prompt_price_unit": "0.001", "prompt_price": "0.0010330", "completion_tokens": 128, "completion_unit_price": "0.002", "completion_price_unit": "0.001", "completion_price": "0.0002560", "total_tokens": 1161, "total_price": "0.0012890", "currency": "USD", "latency": 0.7682376249867957 }, "retriever_resources": [ { "position": 1, "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb", "dataset_name": "iPhone", "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00", "document_name": "iPhone List", "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a", "score": 0.98457545, "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\" \"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\"" } ] }, "created_at": 1705407629 }

Authorizations

Authorization
string
header
required

API Key 认证。对于所有 API 请求,请在 Authorization HTTP 头中包含您的 API Key,并加上 Bearer 前缀。示例:Authorization: Bearer {API_KEY}强烈建议将 API Key 存储在服务端,不要在客户端共享或存储,以避免 API Key 泄漏导致严重后果。

Body

application/json

发送对话消息的请求体。

query
string
required

用户输入/问题内容。

inputs
object
required

允许输入应用定义的各种变量值。包含键值对。请参阅 获取应用参数 响应中的 user_input_form 字段,以了解应用所需的变量名称和类型。

user
string
required

用户标识符,在应用内唯一。此标识符用于限定数据访问范围——会话、消息和文件仅在使用相同的 user 值查询时可见。

response_mode
enum<string>

响应返回模式。streaming(推荐)使用 SSE。blocking 等待完成后返回(长时间处理可能会被中断)。Cloudflare 超时为 100 s。省略时默认为阻塞模式。

Available options:
streaming,
blocking
conversation_id
string

用于继续会话的会话 ID。传入上一条消息的 conversation_id。要开始新会话,请省略此字段或传入空字符串。响应会返回一个 conversation_id——在后续消息中传入该值即可继续该会话。

files
object[]

用于多模态理解的文件列表,包括图片、文档、音频和视频。要附加本地文件,请先通过 上传文件 上传,然后将返回的 id 作为 upload_file_id,并设置 transfer_method: local_file

auto_generate_name
boolean
default:true

自动生成会话标题。如果为 false,请使用 重命名会话 API 并设置 auto_generate: true 来异步生成标题。

workflow_id
string

指定要执行的已发布工作流版本 ID。如果未提供,将使用最新发布的版本。

Response

请求成功。内容类型和结构取决于请求中的 response_mode 参数。

  • 如果 response_modeblocking,返回 application/jsonChatCompletionResponse 对象。
  • 如果 response_modestreaming,返回 text/event-streamChunkChatEvent 对象流。
event
string

事件类型,固定为 message

task_id
string<uuid>

用于请求追踪和停止响应 API 的任务 ID。

id
string<uuid>

该响应事件的唯一 ID。

message_id
string<uuid>

唯一的消息 ID。调用反馈或推荐问题接口时,将此值作为 message_id 参数使用。

conversation_id
string<uuid>

会话 ID。

mode
string

应用模式,固定为 advanced-chat

answer
string

完整的响应内容。

metadata
object

包含用量和检索资源的元数据。

created_at
integer<int64>

消息创建时间戳(Unix 纪元秒)。