API时序图

接口说明

Websocket OpenAPI

  • URL
    例如:wss://test/api/v1/chat

  • Query

参数名 类型 说明 是否必需
deviceId String 设备唯一ID 必需
xxx Object 附加参数 非必需

示例
wss://test/api/v1/chat?deviceId=12345678

对话事件

上行事件

提交文本

  • 事件类型:input_text
  • 事件说明:提交文本内容。
  • 事件结构:
参数名 类型 说明 是否必需
id String 客户端自行生成的事件 ID 必需
event_type String 固定为 input_text 必需
deviceId String 设备唯一ID 必需
question String 问题 必需
stream Boolean 是否启用流式返回 必需
xxx Object 附加参数 非必需
  • 事件示例
    {
    "id": "event_id",
    "event_type": "input_text",
    "deviceId": "12345678",
    "question": "你是谁?",
    "stream": true
    }

打断智能体输出

  • 事件类型:conversation.chat.cancel
  • 事件说明:发送此事件可取消正在进行的对话,中断后,服务端将会返回 conversation.chat.canceled 事件。
  • 事件结构:
参数名 类型 说明 是否必需
id String 客户端自行生成的事件 ID 必需
event_type String 固定为 conversation.chat.cancel 必需
  • 事件示例
    {
    "id": "event_id",
    "event_type": "conversation.chat.cancel"
    }

下行事件

对话连接成功

  • 事件类型:chat.created
  • 事件说明:流式对话接口成功建立连接后服务端会发送此事件。
  • 事件结构:
参数名 类型 说明 是否必需
id String 服务端生成的唯一 ID 必需
event_type String 固定为 chat.created 必需
detail Object 事件详情 非必需
detail.logid String 本次请求的日志 ID 非必需
  • 事件示例
    {
      "id": "7446668538246561xxxx",
      "event_type": "chat.created",
      "detail": {
          "logid": "20241210152726467C48D89D6DB2F3***"    }
    }

对话开始

  • 事件类型:conversation.chat.created
  • 事件说明:创建对话的事件,表示对话开始。
  • 事件结构:
参数名 类型 说明 是否必需
id String 服务端生成的唯一 ID 必需
event_type String 固定为 conversation.chat.created 必需
data Object 事件数据,包含对话的详细信息 非必需
data.id String 对话 ID,即对话的唯一标识 非必需
data.conversation_id String 会话 ID,即会话的唯一标识 非必需
detail Object 事件详情 非必需
detail.logid String 本次请求的日志 ID 非必需
  • 事件示例
    {
    "id": "744666853824656xxx",
    "event_type": "conversation.chat.created",
    "data": {
        "id": "123",
        "conversation_id": "123"
    },
    "detail": {
        "logid": "20241210152726467C48D89D6DB2F3***"
    }    
    }

增量消息

  • 事件类型:conversation.message.delta
  • 事件说明:增量消息,通常是 type=answer 时的增量消息。
  • 事件结构:
参数名 类型 说明 是否必需
id String 服务端生成的唯一 ID 必需
event_type String 固定为 conversation.message.delta 必需
data Object 事件数据,包含对话的详细信息 必需
data.id String 对话 ID,即对话的唯一标识 非必需
data.conversation_id String 会话 ID,即会话的唯一标识 非必需
data.content String 消息的内容,支持纯文本 必需
data.type String 消息类型。取值 answer 必需
detail Object 事件详情 非必需
detail.logid String 本次请求的日志 ID 非必需
  • 事件示例
    {
    "id": "event_1",
    "event_type": "conversation.message.delta",
    "data": {
        "id": "msg_006",
        "conversation_id": "123",
        "type": "answer",
        "content": "你好你好"
    },
    "detail": {
        "logid": "20241210152726467C48D89D6DB2F3***"
    }
    }

增量语音

  • 事件类型:conversation.audio.delta
  • 事件说明:增量语音,通常是 type=answer 时的增量语音。
  • 事件结构:
参数名 类型 说明 是否必需
id String 服务端生成的唯一 ID 必需
event_type String 固定为 conversation.audio.delta 必需
data Object 事件数据,包含对话的详细信息 必需
data.id String 对话 ID,即对话的唯一标识 非必需
data.conversation_id String 会话 ID,即会话的唯一标识 非必需
data.content String 语音二进制 base64 后的字符串。 必需
data.type String 消息类型。取值 answer 必需
detail Object 事件详情 非必需
detail.logid String 本次请求的日志 ID 非必需
  • 事件示例
    {
    "id": "event_1",
    "event_type": "conversation.audio.delta",
    "data": {
        "id": "msg_006",
        "type": "answer",
        "content": "base64audio",
        "conversation_id": "123"
    },
    "detail": {
        "logid": "20241210152726467C48D89D6DB2F3***"
    }
    }

消息完成

  • 事件类型:conversation.message.completed
  • 事件说明:消息已回复完成。
  • 事件结构:
参数名 类型 说明 是否必需
id String 服务端生成的唯一 ID 必需
event_type String 固定为 conversation.message.completed 必需
data Object 事件数据,包含对话的详细信息 非必需
data.id String 对话 ID,即对话的唯一标识 非必需
data.conversation_id String 会话 ID,即会话的唯一标识 非必需
detail Object 事件详情 非必需
detail.logid String 本次请求的日志 ID 非必需
  • 事件示例
    {
    "id": "event_1",
    "event_type": "conversation.message.completed",
    "data": {
      "id": "msg_002",
      "conversation_id": "123"
    },
    "detail": {
        "logid": "20241210152726467C48D89D6DB2F3***"
    }
    }

语音回复完成

  • 事件类型:conversation.audio.completed
  • 事件说明:音频回复完成。
  • 事件结构:
参数名 类型 说明 是否必需
id String 服务端生成的唯一 ID 必需
event_type String 固定为 conversation.audio.completed 必需
data Object 事件数据,包含对话的详细信息 非必需
data.id String 对话 ID,即对话的唯一标识 非必需
data.conversation_id String 会话 ID,即会话的唯一标识 非必需
detail Object 事件详情 非必需
detail.logid String 本次请求的日志 ID 非必需
  • 事件示例
    {
    "id": "event_1",
    "event_type": "conversation.audio.completed",
    "data": {
      "id": "msg_002",
      "conversation_id": "123"
    },
    "detail": {
        "logid": "20241210152726467C48D89D6DB2F3***"
    }
    }

对话完成

  • 事件类型:conversation.chat.completed
  • 事件说明:表示对话已完成。
  • 事件结构:
参数名 类型 说明 是否必需
id String 服务端生成的唯一 ID 必需
event_type String 固定为 conversation.chat.completed 必需
data Object 事件数据,包含对话的详细信息 非必需
data.id String 对话 ID,即对话的唯一标识 非必需
data.conversation_id String 会话 ID,即会话的唯一标识 非必需
detail Object 事件详情 非必需
detail.logid String 本次请求的日志 ID 非必需
  • 事件示例
    {
    "id": "event_1",
    "event_type": "conversation.chat.completed",
    "data": {
      "id": "123",
      "conversation_id": "123"
    },
    "detail": {
        "logid": "20241210152726467C48D89D6DB2F3***"
    }   
    }

对话失败

  • 事件类型:conversation.chat.failed
  • 事件说明:此事件用于标识对话失败。
  • 事件结构:
参数名 类型 说明 是否必需
id String 服务端生成的唯一 ID 必需
event_type String 固定为 conversation.chat.failed 必需
data Object 事件数据,包含对话的详细信息 非必需
data.id String 对话 ID,即对话的唯一标识 非必需
data.conversation_id String 会话 ID,即会话的唯一标识 非必需
data.last_error Object 对话运行异常时,此字段中返回详细的错误信息,包括:Code:错误码。Integer 类型。0 表示成功,其他值表示失败。Msg:错误信息。String 类型。 非必需
detail Object 事件详情 非必需
detail.logid String 本次请求的日志 ID 非必需
  • 事件示例
    {
    "id": "event_1",
    "event_type": "conversation.chat.failed",
    "data": {
        "id": "123",
        "conversation_id": "123",
        "last_error": {
            "code": 1,
            "msg": "发生异常"
        }
    },
    "detail": {
        "logid": "20241210152726467C48D89D6DB2F3***"
    }   
    }

发生错误

  • 事件类型:error
  • 事件说明:对话过程中的错误事件。
  • 事件结构:
参数名 类型 说明 是否必需
id String 服务端生成的唯一 ID 必需
event_type String 固定为 error 必需
data Object 事件数据,包含对话的详细信息 必需
data.code Integer 错误码 必需
data.msg String 错误信息 必需
detail Object 事件详情 非必需
detail.logid String 本次请求的日志 ID 非必需
  • 事件示例
    {
    "id": "event_1",
    "event_type": "error",
    "data": {
        "code": 1,
        "msg": "发生异常"
    },
    "detail": {
        "logid": "20241210152726467C48D89D6DB2F3***"
    }
    }

智能体输出中断

  • 事件类型:conversation.chat.canceled
  • 事件说明:客户端提交 conversation.chat.cancel 事件,服务端完成中断后,将返回此事件。
  • 事件结构:
参数名 类型 说明 是否必需
id String 服务端生成的唯一 ID 必需
event_type String 固定为 conversation.chat.canceled 必需
detail Object 事件详情 非必需
detail.logid String 本次请求的日志 ID 非必需
  • 事件示例
    {
    "id": "event_id",
    "event_type": "conversation.chat.canceled",
    "detail": {
        "logid": "20241210152726467C48D89D6DB2F3***"
    }
    }
作者:admin  创建时间:2025-07-31 15:34
最后编辑:admin  更新时间:2025-09-11 18:23