> 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/flows/templates/{template_id}/runs

列出通过此 API 创建的此模板运行记录，最新的排在前面。

Reference: https://elevenlabs.io/docs/api-reference/flows/templates/runs/list

## 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

- `template_id` (string, required) — 模板的 ID，如 ElevenLabs 应用中或通过 `GET /v1/flows/templates` 所示。

### Query parameters

- `cursor` (string, optional, nullable) — 分页游标：上一页响应中的 `next_cursor` 值。第一页请省略。
- `page_size` (integer, optional, default: 30) — 每页返回的运行记录数量。
- `version_id` (string, optional, nullable) — 仅返回此模板版本 id 的运行记录。

## Response

### 200

成功响应

- `runs` (list of TemplateRunResponse, required) — 此页面上的运行记录，按最新优先排序。每项的结构与 `GET /v1/flows/templates/{template_id}/runs/{run_id}` 相同。
- `next_cursor` (string, required, nullable) — 将其作为 `cursor` 传递以获取下一页。没有后续页面时为 `null`。
- `has_more` (boolean, required) — 此页之后是否还有更多运行记录。

## Errors

### 422 Unprocessable Entity Error

验证错误。

- `detail` (list of ValidationError, optional)

## Types

### TemplateRunResponse

模板运行及其输出。自创建运行任务起，每个输出都会存在并报告各自的 `status`；运行任务的 `status` 会汇总这些状态，并在其为 `completed` 或 `failed` 时结束。

- `id` (string, required) — 运行的唯一标识符。
- `template_id` (string, required) — 此次运行执行的模板，使运行多个模板的 webhook 使用方无需维护运行与模板的映射即可区分各次运行。
- `version_id` (string, required) — 此次运行执行的模板版本。创建运行时即会解析，因此使用 `latest` 启动的运行会记录实际执行的具体版本。
- `status` (enum, required) — 运行状态由各输出状态汇总而成：输出开始前为 `pending`，任一输出未完成时为 `generating`，所有输出完成后为 `completed`，所有输出结束且至少一项失败时为 `failed`。`completed` 和 `failed` 为终态：运行达到其中任一状态时，将触发 `flows_template_run` webhook。
  - Allowed values: `pending`, `generating`, `completed`, `failed`
- `outputs` (map from string to TemplateOutput, required) — The run's outputs, keyed by output port id. Each is a `TemplateOutput` discriminated on `type`, the `type` of its port's `content_schema`.

### ValidationError

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

### TemplateOutput

模板运行的一个输出，按 `type` 区分：即端口 `content_schema` 的 `type`。通过 `status` 查看其所处生命周期阶段。

- `type`: `array` (TemplateArrayOutput)
  - `has_more` (boolean, required) — 列表是否包含 `content` 之外的元素。
  - `id` (string, required) — 此输出对应生成记录的 ID。将其作为 `generation` 引用传入，即可在其他位置将此输出用作输入。
  - `status` (enum, required) — 输出的生命周期状态。当输出的内容字段已设置时，状态为 `completed`；当 `failure_reason` 和 `error_message` 已设置时，状态为 `failed`。
    - Allowed values: `pending`, `generating`, `completed`, `failed`
  - `content` (list of TemplateOutput, optional, nullable) — 列表中按顺序排列的首批元素，每项均遵循架构中 `items` 的结构。仅当 `status` 为 `completed` 时提供。`has_more` 为 true 时，这不是完整列表。保留项：目前尚无模板生成此类输出；发布此项是为了让能生成此类输出的模板可使用相同客户端运行。
  - `error_message` (string, optional, nullable) — 易读的失败说明。仅当 `status` 为 `failed` 时提供。失败的生成不收费。
  - `failure_reason` (enum, optional, nullable) — 失败类别。仅当 `status` 为 `failed` 时提供。
    - Allowed values: `timeout`, `model_error`, `moderated`, `invalid_parameters`, `dependency_failed`, `charging_failed`, `internal_error`
  - `next_cursor` (string, optional, nullable) — 将其作为 `cursor` 传递给后续端点，以获取 `content` 之后的元素。当 `content` 包含完整列表或输出尚未完成时为 `null`。保留字段：目前尚无模板生成此类输出；发布此字段是为了让将来生成此类输出的模板可由同一客户端运行。
- `type`: `audio` (TemplateAudioOutput)
  - `id` (string, required) — 此输出对应生成记录的 ID。将其作为 `generation` 引用传入，即可在其他位置将此输出用作输入。
  - `status` (enum, required) — 输出的生命周期状态。当输出的内容字段已设置时，状态为 `completed`；当 `failure_reason` 和 `error_message` 已设置时，状态为 `failed`。
    - Allowed values: `pending`, `generating`, `completed`, `failed`
  - `content_mime_type` (string, optional, nullable) — 生成媒体的 MIME 类型。仅当 `status` 为 `completed` 时提供。
  - `content_url` (string, optional, nullable) — 用于下载生成媒体的签名 URL。仅当 `status` 为 `completed` 时提供。该 URL 会在返回此响应约 1 小时后过期；请再次获取运行任务以取得新的 URL。
  - `error_message` (string, optional, nullable) — 易读的失败说明。仅当 `status` 为 `failed` 时提供。失败的生成不收费。
  - `failure_reason` (enum, optional, nullable) — 失败类别。仅当 `status` 为 `failed` 时提供。
    - Allowed values: `timeout`, `model_error`, `moderated`, `invalid_parameters`, `dependency_failed`, `charging_failed`, `internal_error`
- `type`: `boolean` (TemplateBooleanOutput)
  - `id` (string, required) — 此输出对应生成记录的 ID。将其作为 `generation` 引用传入，即可在其他位置将此输出用作输入。
  - `status` (enum, required) — 输出的生命周期状态。当输出的内容字段已设置时，状态为 `completed`；当 `failure_reason` 和 `error_message` 已设置时，状态为 `failed`。
    - Allowed values: `pending`, `generating`, `completed`, `failed`
  - `content` (boolean, optional, nullable) — 生成的布尔值。仅当 `status` 为 `completed` 时提供。保留项：目前尚无模板生成此类输出；发布此项是为了让能生成此类输出的模板可使用相同客户端运行。
  - `error_message` (string, optional, nullable) — 易读的失败说明。仅当 `status` 为 `failed` 时提供。失败的生成不收费。
  - `failure_reason` (enum, optional, nullable) — 失败类别。仅当 `status` 为 `failed` 时提供。
    - Allowed values: `timeout`, `model_error`, `moderated`, `invalid_parameters`, `dependency_failed`, `charging_failed`, `internal_error`
- `type`: `image` (TemplateImageOutput)
  - `id` (string, required) — 此输出对应生成记录的 ID。将其作为 `generation` 引用传入，即可在其他位置将此输出用作输入。
  - `status` (enum, required) — 输出的生命周期状态。当输出的内容字段已设置时，状态为 `completed`；当 `failure_reason` 和 `error_message` 已设置时，状态为 `failed`。
    - Allowed values: `pending`, `generating`, `completed`, `failed`
  - `content_mime_type` (string, optional, nullable) — 生成媒体的 MIME 类型。仅当 `status` 为 `completed` 时提供。
  - `content_url` (string, optional, nullable) — 用于下载生成媒体的签名 URL。仅当 `status` 为 `completed` 时提供。该 URL 会在返回此响应约 1 小时后过期；请再次获取运行任务以取得新的 URL。
  - `error_message` (string, optional, nullable) — 易读的失败说明。仅当 `status` 为 `failed` 时提供。失败的生成不收费。
  - `failure_reason` (enum, optional, nullable) — 失败类别。仅当 `status` 为 `failed` 时提供。
    - Allowed values: `timeout`, `model_error`, `moderated`, `invalid_parameters`, `dependency_failed`, `charging_failed`, `internal_error`
- `type`: `integer` (TemplateIntegerOutput)
  - `id` (string, required) — 此输出对应生成记录的 ID。将其作为 `generation` 引用传入，即可在其他位置将此输出用作输入。
  - `status` (enum, required) — 输出的生命周期状态。当输出的内容字段已设置时，状态为 `completed`；当 `failure_reason` 和 `error_message` 已设置时，状态为 `failed`。
    - Allowed values: `pending`, `generating`, `completed`, `failed`
  - `content` (integer, optional, nullable) — 生成的整数。仅当 `status` 为 `completed` 时提供。保留项：目前尚无模板生成此类输出；发布此项是为了让能生成此类输出的模板可使用相同客户端运行。
  - `error_message` (string, optional, nullable) — 易读的失败说明。仅当 `status` 为 `failed` 时提供。失败的生成不收费。
  - `failure_reason` (enum, optional, nullable) — 失败类别。仅当 `status` 为 `failed` 时提供。
    - Allowed values: `timeout`, `model_error`, `moderated`, `invalid_parameters`, `dependency_failed`, `charging_failed`, `internal_error`
- `type`: `number` (TemplateNumberOutput)
  - `id` (string, required) — 此输出对应生成记录的 ID。将其作为 `generation` 引用传入，即可在其他位置将此输出用作输入。
  - `status` (enum, required) — 输出的生命周期状态。当输出的内容字段已设置时，状态为 `completed`；当 `failure_reason` 和 `error_message` 已设置时，状态为 `failed`。
    - Allowed values: `pending`, `generating`, `completed`, `failed`
  - `content` (double, optional, nullable) — 生成的数字。仅当 `status` 为 `completed` 时提供。保留项：目前尚无模板生成此类输出；发布此项是为了让能生成此类输出的模板可使用相同客户端运行。
  - `error_message` (string, optional, nullable) — 易读的失败说明。仅当 `status` 为 `failed` 时提供。失败的生成不收费。
  - `failure_reason` (enum, optional, nullable) — 失败类别。仅当 `status` 为 `failed` 时提供。
    - Allowed values: `timeout`, `model_error`, `moderated`, `invalid_parameters`, `dependency_failed`, `charging_failed`, `internal_error`
- `type`: `object` (TemplateObjectOutput)
  - `id` (string, required) — 此输出对应生成记录的 ID。将其作为 `generation` 引用传入，即可在其他位置将此输出用作输入。
  - `status` (enum, required) — 输出的生命周期状态。当输出的内容字段已设置时，状态为 `completed`；当 `failure_reason` 和 `error_message` 已设置时，状态为 `failed`。
    - Allowed values: `pending`, `generating`, `completed`, `failed`
  - `content` (map from string to TemplateOutput, optional, nullable) — 每个字段一个输出，以字段名为键，且均遵循该字段架构的结构。仅在 `status` 为 `completed` 时提供。保留：目前尚无模板生成此类输出；发布它是为了让能够生成此类输出的模板可通过同一客户端运行。
  - `error_message` (string, optional, nullable) — 易读的失败说明。仅当 `status` 为 `failed` 时提供。失败的生成不收费。
  - `failure_reason` (enum, optional, nullable) — 失败类别。仅当 `status` 为 `failed` 时提供。
    - Allowed values: `timeout`, `model_error`, `moderated`, `invalid_parameters`, `dependency_failed`, `charging_failed`, `internal_error`
- `type`: `string` (TemplateStringOutput)
  - `id` (string, required) — 此输出对应生成记录的 ID。将其作为 `generation` 引用传入，即可在其他位置将此输出用作输入。
  - `status` (enum, required) — 输出的生命周期状态。当输出的内容字段已设置时，状态为 `completed`；当 `failure_reason` 和 `error_message` 已设置时，状态为 `failed`。
    - Allowed values: `pending`, `generating`, `completed`, `failed`
  - `content` (string, optional, nullable) — 生成的文本。仅当 `status` 为 `completed` 时提供。
  - `error_message` (string, optional, nullable) — 易读的失败说明。仅当 `status` 为 `failed` 时提供。失败的生成不收费。
  - `failure_reason` (enum, optional, nullable) — 失败类别。仅当 `status` 为 `failed` 时提供。
    - Allowed values: `timeout`, `model_error`, `moderated`, `invalid_parameters`, `dependency_failed`, `charging_failed`, `internal_error`
- `type`: `video` (TemplateVideoOutput)
  - `id` (string, required) — 此输出对应生成记录的 ID。将其作为 `generation` 引用传入，即可在其他位置将此输出用作输入。
  - `status` (enum, required) — 输出的生命周期状态。当输出的内容字段已设置时，状态为 `completed`；当 `failure_reason` 和 `error_message` 已设置时，状态为 `failed`。
    - Allowed values: `pending`, `generating`, `completed`, `failed`
  - `content_mime_type` (string, optional, nullable) — 生成媒体的 MIME 类型。仅当 `status` 为 `completed` 时提供。
  - `content_url` (string, optional, nullable) — 用于下载生成媒体的签名 URL。仅当 `status` 为 `completed` 时提供。该 URL 会在返回此响应约 1 小时后过期；请再次获取运行任务以取得新的 URL。
  - `error_message` (string, optional, nullable) — 易读的失败说明。仅当 `status` 为 `failed` 时提供。失败的生成不收费。
  - `failure_reason` (enum, optional, nullable) — 失败类别。仅当 `status` 为 `failed` 时提供。
    - Allowed values: `timeout`, `model_error`, `moderated`, `invalid_parameters`, `dependency_failed`, `charging_failed`, `internal_error`

### ValidationErrorLocItems

- string
- integer

## Examples

**Response**

```json
{
  "runs": [
    {
      "id": "sess_JWr5N6X9ZTqf8jD2LmQb",
      "template_id": "tmpl_abc123",
      "version_id": "ver_01hxyz",
      "status": "generating",
      "outputs": {
        "marketing_title": {
          "type": "string",
          "id": "Kx2mP7Y4WVrg9kE3NnRc",
          "status": "completed",
          "content": "Ride the wave."
        },
        "product_demo": {
          "type": "video",
          "id": "QWr5N6X9ZTqf8jD2La3B",
          "status": "generating"
        },
        "product_still": {
          "type": "image",
          "id": "JWr5N6X9ZTqf8jD2LmQb",
          "status": "completed",
          "content_mime_type": "image/png",
          "content_url": "https://storage.googleapis.com/generations/JWr5N6X9ZTqf8jD2LmQb"
        }
      }
    }
  ],
  "next_cursor": "MjAyNi0wNy0xN1QxMjowMDowMHxLeDJtUDdZNFdWcmc5a0UzTm5SYw",
  "has_more": true
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/flows/templates/template_id/runs"

response = requests.get(url)

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/flows/templates/template_id/runs';
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/flows/templates/template_id/runs"

	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/flows/templates/template_id/runs")

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/flows/templates/template_id/runs")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://api.elevenlabs.io/v1/flows/templates/template_id/runs');

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

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/flows/templates/template_id/runs");
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/flows/templates/template_id/runs")! 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()
```