对话

最近更新时间:2026-04-03 01:16:41

我的收藏

1. 接口描述

接口请求域名: cls.tencentcloudapi.com 。

调用接口,发起一次对话请求。
本接口支持智能生成检索分析语句等日志服务AI功能。
⚠️注意:通过SSE流式调用此接口时,请务必设置请求域名(Endpoint)为 cls.ai.tencentcloudapi.com。

默认接口请求频率限制:20次/秒。

推荐使用 API Explorer
点击调试
API Explorer 提供了在线调用、签名验证、SDK 代码生成和快速检索接口等能力。您可查看每次调用的请求内容和返回结果以及自动生成 SDK 调用示例。

2. 输入参数

以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数

参数名称 必选 类型 描述
Action String 公共参数,本接口取值:ChatCompletions。
Version String 公共参数,本接口取值:2020-10-16。
Region String 公共参数,详见产品支持的 地域列表
Model String

功能名称

枚举值:

  • text2sql: 智能生成检索分析语句
  • text2sql-reasoning: 智能生成检索分析语句-深度思考

示例值:text2sql
Messages.N Array of Message

聊天上下文信息。
说明:

  1. 长度最多为 11 (5轮历史会话 + user新提问) ,按对话时间从旧到新在数组中排列。超出此长度会丢弃旧会话数据。
  2. Message.Role 可选值:user、assistant。
    user 和 assistant 需交替出现,以 user 提问开始,user 提问结束,Content 不能为空。Role 的顺序示例:[user assistant user assistant user ...]。
Stream Boolean

流式调用开关。
说明:

  1. 未传值时默认为非流式调用(false)。
  2. 流式调用时以 SSE 协议增量返回结果(返回值取 Choices[n].Delta 中的值,需要拼接增量数据才能获得完整结果)。
  3. 非流式调用时:
    调用方式与普通 HTTP 请求无异。
    接口响应耗时较长,如需更低时延建议设置为 true。
    只返回一次最终结果(返回值取 Choices[n].Message 中的值)。

注意:

  1. 通过 SDK 调用时,流式和非流式调用需用不同的方式获取返回值,具体参考 SDK 中的注释或示例(在各语言 SDK 代码仓库的 examples/hunyuan/v20230901/ 目录中)。
  2. 可能会出现部分内容已输出,但中间某一段响应中的 FinishReason 值为 sensitive,此时说明安全审核未通过。如果业务场景有实时文字上屏的需求,需要自行撤回已上屏的内容,并建议自定义替换为一条提示语,如 “这个问题我不方便回答,不如我们换个话题试试”,以保障终端体验。

示例值:false
Metadata.N Array of MetadataItem

额外元数据信息。例如:[{"Key":"topic_id","Value":"xxxxxxxx-xxxx"},{"Key":"topic_region","Value":"ap-guangzhou"}]

3. 输出参数

参数名称 类型 描述
Created Integer

Unix 时间戳,单位为秒。


示例值:1705634032
Usage ChatUsage

Token 统计信息。

Id String

本次请求的 Id。


示例值:xxxxxxxx-xxxx
Choices Array of Choice

回复内容。

Model String

功能名称

枚举值:

  • text2sql: 智能生成检索分析语句
  • text2sql-reasoning: 智能生成检索分析语句-深度思考

示例值:text2sql
RequestId String 唯一请求 ID,由服务端生成,每次请求都会返回(若请求因其他原因未能抵达服务端,则该次请求不会获得 RequestId)。定位问题时需要提供该次请求的 RequestId。本接口为流式响应接口,当请求成功时,RequestId 会被放在 HTTP 响应的 Header "X-TC-RequestId" 中。

4. 示例

示例1 智能生成检索语句-不开启深度思考-流式调用

此示例说明如何通过流式调用接口,以及如何传递历史上下文会话内容。注意:流式调用的请求域名需使用 cls.ai.tencentcloudapi.com。

输入示例

POST / HTTP/1.1
Host: cls.ai.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: ChatCompletions
<公共请求参数>

{
    "Model": "text2sql",
    "Messages": [
        {
            "Role": "user",
            "Content": "状态码200, 统计日志条数"
        },
        {
            "Role": "assistant",
            "Content": "根据您的需求\"状态码200, 统计日志条数\",我分析出这是一个检索分析需求,需要检索状态码为200的日志,并统计日志条数。\n\n根据Nginx日志主题的字段配置,`status`字段是long类型且开启了统计状态。以下是生成的CQL语句:\n\n\\`\\`\\`sql\nstatus:200 | SELECT count(*) AS log_count\n\\`\\`\\`\n\n**解释说明:**\n1. **检索条件**:`status:200` - 检索状态码为200的日志\n2. **SQL语句**:`SELECT count(*) AS log_count` - 统计符合条件的日志条数\n3. **校验结果**:校验语句通过\n\n由于这是一个统计查询,需要使用管道符`|`将检索条件和SQL分析语句连接起来。语句使用了`status:200`作为检索条件,然后通过`count(*)`函数统计日志条数。"
        },
        {
            "Content": "再统计5xx的",
            "Role": "user"
        }
    ],
    "Stream": true,
    "Metadata": [
        {
            "Key": "topic_id",
            "Value": "xxxxxxxx-xxxx"
        },
        {
            "Key": "topic_region",
            "Value": "ap-guangzhou"
        }
    ]
}

输出示例

id: 1
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"根据","Role":"assistant","ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103178,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 2
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"您的需求\"","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103178,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 3
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"再统计5","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103178,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 4
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"xx的\",","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103178,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 5
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"这是","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 6
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"要","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 7
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"统计HTTP","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 8
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"状态码为","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 9
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"5xx(","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 10
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"服务器错误)","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 11
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"的日志条","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 12
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"数。\n\n","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 13
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"根据日志主题","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 14
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"字段","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 15
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"列表,`","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 16
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"status`","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 17
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"字段是long","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 18
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"类型且开启了","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 19
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"统计状态。","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 20
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"以下是生成的","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 21
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"CQL语句","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 22
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":":\n\n\`\`\`sql","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 23
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"\nstatus","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 24
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":">=500 AND","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 25
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" status<=","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 26
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"599 |","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 27
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" SELECT count(*)","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 28
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" AS log","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 29
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"_count\n\`\`\`\n\n","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 30
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"**解释说明","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 31
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":":**\n1","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 32
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":". **检索","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103179,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 33
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"条件**:","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 34
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"`status>=","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 35
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"500 AND status","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 36
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"<=599`","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 37
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" - 检索","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 38
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"状态码在","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 39
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"500-","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 40
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"599之间的","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 41
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"日志(5","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 42
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"xx服务器","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 43
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"错误)\n2","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 44
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":". **","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 45
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"SQL语句**","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 46
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":":`SELECT","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 47
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" count(*) AS","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 48
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" log_count`","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 49
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":" - 统计","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 50
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"符合条件的日志条","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 51
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"数\n3","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 52
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":". **校验","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 53
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"结果**:","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 54
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"校验语句","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 55
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"通过\n\n","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 56
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"该","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 57
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"语句使用了","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 58
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"数值","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 59
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"范围检索","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 60
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"条件","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103180,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 61
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"`status>=","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 62
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"500 AND status","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 63
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"<=599`","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 64
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"来匹配","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 65
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"所有","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 66
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"5xx状态","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 67
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"码,","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 68
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"然后统计","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 69
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"满足","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 70
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"条件的日志数量","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 71
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":"。","Role":null,"ReasoningContent":null},"Index":0,"FinishReason":null}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{}}

id: 72
data: {"RequestId":"xxxxxxxx-xxxx","Id":"xxxxxxxx-xxxx","Choices":[{"Delta":{"Content":null,"Role":null,"ReasoningContent":null},"Index":0,"FinishReason":"stop"}],"Created":1775103181,"Model":"text2sql","Object":"chat.completion.chunk","Usage":{"PromptTokens":12482,"CompletionTokens":175,"TotalTokens":12657}}

示例2 智能生成检索语句-开启深度思考-非流式调用

此示例说明如何通过非流式调用接口。

输入示例

POST / HTTP/1.1
Host: cls.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: ChatCompletions
<公共请求参数>

{
    "Messages": [
        {
            "Content": "状态码200, 统计日志条数",
            "Role": "user"
        }
    ],
    "Model": "text2sql-reasoning",
    "Metadata": [
        {
            "Key": "topic_region",
            "Value": "ap-guangzhou"
        },
        {
            "Key": "topic_id",
            "Value": "xxxxxxxx-xxxx"
        }
    ]
}

输出示例

{
  "Response": {
    "RequestId": "xxxxxxxx-xxxx",
    "Id": "xxxxxxxx-xxxx",
    "Created": 1775102996,
    "Model": "text2sql-reasoning",
    "Choices": [
      {
        "FinishReason": "stop",
        "Message": {
          "Role": "assistant",
          "Content": "\n\`\`\`sql\nstatus:200 | SELECT count(*) AS \"日志条数\"\n\`\`\`\n\n### 解释说明:\n1. **检索条件**:`status:200`\n   - 使用键值检索语法过滤状态码为200的日志\n   - `status`字段在索引配置中已开启统计(状态为1),可直接使用\n\n2. **分析语句**:`SELECT count(*) AS \"日志条数\"`\n   - 使用聚合函数`count(*)`统计符合条件的日志条数\n   - 字段别名使用双引号包裹(包含中文)\n\n3. **注意事项**:\n   - 该语句统计的是当前查询时间范围内的日志条数\n   - 如需调整时间范围,请在控制台右侧时间选择器修改\n   - `status`字段为long类型,支持精确数值检索\n\n### 校验结果:\n\`\`\`json\n{\n  \"status\": \"success\",\n  \"result\": {\n    \"日志条数\": 15234\n  }\n}\n\`\`\`",
          "ReasoningContent": "\n我们已知日志主题索引配置字段列表,其中包含字段:status:long::1,表示status字段是long类型,开启统计。\n 需求是:状态码200, 统计日志条数。\n 根据规则,纯统计需求应使用检索分析格式:[检索条件] | [SQL语句]\n 检索条件:状态码200,即status:200\n SQL语句:统计日志条数,即SELECT count(*) AS log_count\n\n 注意:由于status字段在索引配置中已开启统计,可以直接使用。\n\n 输出CQL语句:`status:200 | SELECT count(*) AS log_count`\n\n 解释说明:检索条件为status:200,然后使用SQL统计日志条数。\n\n 另外,由于需求中指定了状态码200,我们不需要考虑时间范围,因为用户可以在界面选择时间范围。\n\n 校验:我们可以模拟校验,假设有status字段且值为200的日志,则统计其数量。如果日志中没有status字段或没有值为200的日志,则返回0。\n\n 由于我们使用了已开启统计的字段,所以不会出现字段未开启统计的问题。\n\n 因此,最终输出如下:",
          "ToolCalls": []
        },
        "Index": 0
      }
    ],
    "Usage": {
      "PromptTokens": 11262,
      "CompletionTokens": 448,
      "TotalTokens": 11710
    }
  }
}

5. 开发者资源

腾讯云 API 平台

腾讯云 API 平台 是综合 API 文档、错误码、API Explorer 及 SDK 等资源的统一查询平台,方便您从同一入口查询及使用腾讯云提供的所有 API 服务。

API Inspector

用户可通过 API Inspector 查看控制台每一步操作关联的 API 调用情况,并自动生成各语言版本的 API 代码,也可前往 API Explorer 进行在线调试。

SDK

云 API 3.0 提供了配套的开发工具集(SDK),支持多种编程语言,能更方便的调用 API。

命令行工具

6. 错误码

以下仅列出了接口业务逻辑相关的错误码,其他错误码详见 公共错误码

错误码 描述
FailedOperation.Timeout 操作超时
ResourceNotFound.TopicNotExist 日志主题不存在。