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

获取一个 flows 模板及每个可运行版本的输入和输出。若没有可通过此 API 运行的已发布版本，`versions` 为空。适用于你可打开的任何模板，包括通过链接分享给你的模板，或其他工作区发布到 Explore 的模板；`GET /v1/flows/templates` 不会列出这些模板。

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

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

### Query parameters

- `versions_per_template` (integer, optional, default: 10) — 每个模板返回的已发布版本数量，按最新优先。`has_more_versions` 表示模板是否还有更多版本。

## Response

### 200

成功响应

- `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) — 模板的描述（如有）。

## Errors

### 422 Unprocessable Entity Error

验证错误。

- `detail` (list of ValidationError, optional)

## Types

### 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) — 此版本生成的输出，按画布顺序排列。

### ValidationError

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

### 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` 结构。

### ValidationErrorLocItems

- string
- integer

### 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
{
  "id": "tmpl_abc123",
  "name": "Product shot",
  "versions": [
    {
      "version_id": "ver_01hxyz",
      "published_at_unix": 1,
      "is_latest": true,
      "inputs": [
        {
          "id": "prompt",
          "content_schema": {
            "type": "string",
            "description": "string",
            "enum": [
              "string"
            ],
            "title": "string"
          }
        }
      ],
      "outputs": [
        {
          "id": "prompt",
          "content_schema": {
            "type": "string",
            "description": "string",
            "enum": [
              "string"
            ],
            "title": "string"
          }
        }
      ]
    }
  ],
  "has_more_versions": true,
  "description": "string"
}
```

**SDK Code**

```python
import requests

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

response = requests.get(url)

print(response.json())
```

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

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

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")
  .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');

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

```csharp
using RestSharp;

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