> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# 获取智能体会话主题

GET https://api.elevenlabs.io/v1/convai/agents/{agent_id}/topics

返回指定智能体最新的话题发现运行结果。

Reference: https://elevenlabs.io/docs/eleven-agents/api-reference/conversations/topics/get

## Servers

- `https://api.elevenlabs.io` (Production, default)
- `https://api.us.elevenlabs.io` (Production US)
- `https://api.eu.residency.elevenlabs.io` (Production EU)
- `https://api.in.residency.elevenlabs.io` (Production India)
- `https://api.sg.residency.elevenlabs.io` (Production Singapore)

## Request

### Path parameters

- `agent_id` (string, required) — 智能体 ID

### Query parameters

- `page_size` (integer, optional) — 要返回的顶级主题组数量。
- `sort_by` (enum, optional) — Column to rank topics by. Use conversations for volume, sentiment with sort_direction=asc for the most negative topics, and frustration with sort_direction=desc for the most frustrated ones. Topics with no score are always ranked last.
  - Allowed values: `conversations`, `sentiment`, `success_rate`, `frustration`
- `sort_direction` (enum, optional) — 主题排序方向。
  - Allowed values: `asc`, `desc`
- `from_unix_secs` (integer, optional) — 查看主题的时间窗口起点。与 to_unix_secs 一同设置时，范围内已完成的每日主题发现运行会汇总，因此该窗口同时限定指标和主题集。由于运行覆盖完整 UTC 日，会向下取整至对应 UTC 日的开始时间；aggregated_run_count 表示汇总的运行数量。省略两个边界可获取单个最新运行。
- `to_unix_secs` (integer, optional) — 查看主题的时间窗口结束时间。
- `include_evaluation_criteria` (boolean, optional, default: true) — 在每个主题的指标中包含按条件划分的评估明细。传入 false 可移除该明细：它会占据大部分负载，但无论是否包含都会返回加权 success_rate。
- `cursor` (string, optional) — 用于获取下一页。响应中会返回游标。

## Response

### 200

成功响应

- `topics` (list of AgentTopicResponseModel, required)
- `window_start_unix_secs` (integer, required)
- `window_end_unix_secs` (integer, required)
- `aggregated_run_count` (integer, optional, default: 0) — 返回指标汇总涵盖的每日主题发现运行次数。
- `has_more` (boolean, optional, default: false)
- `next_cursor` (string, optional)

## Errors

### 422 Topics Get Request Unprocessable Entity Error

验证错误。

- `detail` (list of ValidationError, optional)

## Types

### AgentTopicResponseModel

- `topic_id` (string, required)
- `label` (string, required)
- `description` (string, required)
- `conversation_count` (integer, required)
- `parent_topic_id` (string, optional)
- `x_2d` (double, optional)
- `y_2d` (double, optional)
- `metrics` (TopicMetricsAggregate, optional)
- `success_rate` (double, optional) — 该主题各评估标准的成功率，按已评分对话加权。无论 include_evaluation_criteria 的值为何，都会返回。

### ValidationError

- `loc` (list of ValidationErrorLocItem, required)
- `msg` (string, required)
- `type` (string, required)

### TopicMetricsAggregate

- `conversation_count` (integer, optional, default: 0)
- `sentiment` (TopicSentimentAggregate, optional)
- `evaluation_criteria` (list of TopicEvaluationCriteriaAggregate, optional)

### ValidationErrorLocItem

- string
- integer

### TopicSentimentAggregate

- `sentiment` (NumericDistributionAggregate, optional)
- `frustration` (NumericDistributionAggregate, optional)
- `positive_count` (integer, optional, default: 0)
- `neutral_count` (integer, optional, default: 0)
- `negative_count` (integer, optional, default: 0)

### TopicEvaluationCriteriaAggregate

- `criteria_id` (string, required)
- `success_count` (integer, optional, default: 0)
- `failure_count` (integer, optional, default: 0)
- `unknown_count` (integer, optional, default: 0)

### NumericDistributionAggregate

- `count` (integer, optional, default: 0)
- `sum` (double, optional, default: 0)
- `min` (double, optional)
- `max` (double, optional)

## Examples

**Response**

```json
{
  "topics": [
    {
      "topic_id": "topic_id",
      "label": "label",
      "description": "description",
      "conversation_count": 1,
      "parent_topic_id": "parent_topic_id",
      "x_2d": 1.1,
      "y_2d": 1.1,
      "success_rate": 1.1
    }
  ],
  "window_start_unix_secs": 1,
  "window_end_unix_secs": 1,
  "aggregated_run_count": 1,
  "has_more": true,
  "next_cursor": "next_cursor"
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/convai/agents/agent_id/topics"

querystring = {"cursor":"cursor","from_unix_secs":"1","include_evaluation_criteria":"true","page_size":"1","sort_by":"conversations","sort_direction":"asc","to_unix_secs":"1"}

response = requests.get(url, params=querystring)

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/convai/agents/agent_id/topics?cursor=cursor&from_unix_secs=1&include_evaluation_criteria=true&page_size=1&sort_by=conversations&sort_direction=asc&to_unix_secs=1';
const options = {method: 'GET'};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.elevenlabs.io/v1/convai/agents/agent_id/topics?cursor=cursor&from_unix_secs=1&include_evaluation_criteria=true&page_size=1&sort_by=conversations&sort_direction=asc&to_unix_secs=1"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.elevenlabs.io/v1/convai/agents/agent_id/topics?cursor=cursor&from_unix_secs=1&include_evaluation_criteria=true&page_size=1&sort_by=conversations&sort_direction=asc&to_unix_secs=1")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://api.elevenlabs.io/v1/convai/agents/agent_id/topics?cursor=cursor&from_unix_secs=1&include_evaluation_criteria=true&page_size=1&sort_by=conversations&sort_direction=asc&to_unix_secs=1")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://api.elevenlabs.io/v1/convai/agents/agent_id/topics?cursor=cursor&from_unix_secs=1&include_evaluation_criteria=true&page_size=1&sort_by=conversations&sort_direction=asc&to_unix_secs=1');

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/convai/agents/agent_id/topics?cursor=cursor&from_unix_secs=1&include_evaluation_criteria=true&page_size=1&sort_by=conversations&sort_direction=asc&to_unix_secs=1");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/convai/agents/agent_id/topics?cursor=cursor&from_unix_secs=1&include_evaluation_criteria=true&page_size=1&sort_by=conversations&sort_direction=asc&to_unix_secs=1")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```