> 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

列出工作区中已发布的流程模板，以及每个可运行版本的输入和输出。在 `POST /v1/flows/templates/{template_id}/runs` 中使用此处的 ID 作为 `template_id` / `version_id`。基于你无法通过 API 使用的模型构建的版本会被排除，因此当模板没有任何已发布版本可通过此 API 运行时，`versions` 为空。其他工作区通过链接与你共享或发布到 Explore 的模板不会列出，但仍可通过 `template_id` 获取和运行。

Reference: https://elevenlabs.io/docs/api-reference/flows/templates/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

### Query parameters

- `cursor` (string, optional, nullable) — 分页游标：上一页响应中的 `next_cursor` 值。第一页请省略。
- `page_size` (integer, optional, default: 10) — 每页返回的模板数量。由于每一行都会展开其版本的输入和输出架构，该上限低于运行列表的上限。
- `versions_per_template` (integer, optional, default: 3) — 每个模板返回的已发布版本数量，按最新优先。`has_more_versions` 表示模板是否还有更多版本。
- `search` (string, optional, nullable) — 仅返回名称或描述包含此文本的模板。

## Response

### 200

成功响应

- `templates` (list of TemplateSummary, required) — 此页面的模板，按最近更新时间排序。由于无法运行的模板会在读取页面后被过滤，一页可能少于 `page_size` 个模板，甚至没有模板；只要 `has_more` 为 true，就继续分页。
- `next_cursor` (string, required, nullable) — 将其作为 `cursor` 传递以获取下一页。没有后续页面时为 `null`。
- `has_more` (boolean, required) — 此页之后是否还有更多模板。

## Errors

### 422 Unprocessable Entity Error

验证错误。

- `detail` (list of ValidationError, optional)

## Types

### TemplateSummary

调用方可运行的模板及其可运行版本。

- `id` (string, required) — 在 `POST /v1/flows/templates/{template_id}/runs` 中作为 `template_id` 传递。
- `name` (string, required) — 模板名称。
- `versions` (list of TemplateVersion, required) — 调用方可运行的已发布版本，按最新优先排序。若某版本的图表使用了无法通过 API 使用的模型，或其存储的快照已不存在，则不会列出该版本；即使模板仍有可在 ElevenLabs 应用中运行的版本，列表也可能为空。
- `has_more_versions` (boolean, required) — 此模板是否还有超出此处返回的 `versions_per_template` 的已发布版本。使用更大的 `versions_per_template` 获取 `GET /v1/flows/templates/{template_id}`，即可查看更多版本。
- `description` (string, optional, nullable) — 模板的描述（如有）。

### ValidationError

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

### TemplateVersion

已发布的模板快照及其运行端口。

- `version_id` (string, required) — 在 `POST /v1/flows/templates/{template_id}/runs` 中作为 `version_id` 传递，以将一次运行固定到此快照。
- `published_at_unix` (integer, required) — 此版本发布时间，以秒为单位的 Unix 时间戳。
- `is_latest` (boolean, required) — 当省略 `version_id` 或将其设为 `latest` 时，运行是否会使用此版本。
- `inputs` (list of TemplatePort, required) — 此版本接受的输入，按画布顺序排列。每次运行都需要提供所有输入。
- `outputs` (list of TemplatePort, required) — 此版本生成的输出，按画布顺序排列。

### ValidationErrorLocItems

- string
- integer

### TemplatePort

已发布模板版本的一个输入或输出端口。

- `id` (string, required) — 端口 ID。输入 ID 是 `POST /v1/flows/templates/{template_id}/runs` 中 `inputs` 映射的键；输出 ID 是运行响应中 `outputs` 映射的键。
- `content_schema` (ContentSchema, required) — 此端口接受或生成的内容，以 `ContentSchema` 表示。其 `title` 是端口显示名称，`description` 是模板作者编写的帮助文本。对于输入，`type` 决定可接受的值：`string` 接受纯字符串或 `generation` 引用，`voice` 接受 `voice` 引用，`image`/`video`/`audio` 接受 `asset`、`generation` 或 `inline_base64` 引用。`number`、`integer` 和 `boolean` 接受相应类型的 JSON 值。`array` 输入接受 JSON 数组，每个元素对应一个值，且均须符合其 `items` 要求。暂不支持通过此 API 绑定 `object` 输入。`string` 架构可包含 `enum`，指定仅接受的值。对于输出，`type` 决定运行响应在端口 ID 下包含的 `Template<Kind>Output` 结构。

### ContentSchema

- `type`: `array` (ArraySchema)
  - `items` (ContentSchema, required)
  - `description` (string, optional, nullable)
  - `title` (string, optional, nullable)
- `type`: `audio` (AudioSchema)
  - `description` (string, optional, nullable)
  - `title` (string, optional, nullable)
- `type`: `boolean` (BooleanSchema)
  - `description` (string, optional, nullable)
  - `title` (string, optional, nullable)
- `type`: `image` (ImageSchema)
  - `description` (string, optional, nullable)
  - `title` (string, optional, nullable)
- `type`: `integer` (IntegerSchema)
  - `description` (string, optional, nullable)
  - `title` (string, optional, nullable)
- `type`: `number` (NumberSchema)
  - `description` (string, optional, nullable)
  - `enum` (list of double, optional, nullable)
  - `title` (string, optional, nullable)
- `type`: `object` (ObjectSchema)
  - `description` (string, optional, nullable)
  - `properties` (map from string to ContentSchema, optional)
  - `required` (list of string, optional)
  - `title` (string, optional, nullable)
- `type`: `string` (StringSchema)
  - `description` (string, optional, nullable)
  - `enum` (list of string, optional, nullable)
  - `title` (string, optional, nullable)
- `type`: `video` (VideoSchema)
  - `description` (string, optional, nullable)
  - `title` (string, optional, nullable)
- `type`: `voice` (VoiceSchema)
  - `description` (string, optional, nullable)
  - `title` (string, optional, nullable)

## Examples

**Response**

```json
{
  "templates": [
    {
      "id": "tmpl_abc123",
      "name": "Product shot",
      "versions": [
        {
          "version_id": "ver_01hxyz",
          "published_at_unix": 1739721600,
          "is_latest": true,
          "inputs": [
            {
              "id": "prompt",
              "content_schema": {
                "type": "string",
                "title": "Prompt"
              }
            },
            {
              "id": "reference",
              "content_schema": {
                "type": "image",
                "description": "A clean product photo on any background.",
                "title": "Product photo"
              }
            }
          ],
          "outputs": [
            {
              "id": "product_still",
              "content_schema": {
                "type": "image",
                "title": "Final image"
              }
            }
          ]
        }
      ],
      "has_more_versions": false,
      "description": "Drop in a product photo, get a studio shot."
    }
  ],
  "next_cursor": "cGFnZXwx",
  "has_more": true
}
```

**SDK Code**

```python
import requests

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

response = requests.get(url)

print(response.json())
```

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

	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")

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")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

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

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

```csharp
using RestSharp;

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