> 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/history

返回生成的音频列表（例如文本转语音、语音转语音、Studio、配音）。不包括音乐和 SFX 生成内容，目前也无法通过 API 获取。

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

- `page_size` (integer, optional, default: 100) — 最多返回的历史记录项数量。不能超过 1000，默认为 100。
- `start_after_history_item_id` (string, optional, nullable) — 指定从哪个 ID 之后开始获取。可使用此参数为大量历史记录分页。未提供此参数时，将按创建时间降序，从最新创建的历史记录开始获取。
- `voice_id` (string, optional, nullable) — 要筛选的音色 ID。可使用 [获取音色](/docs/api-reference/voices/search) 端点列出所有可用音色。
- `model_id` (string, optional, nullable) — 用于筛选历史记录项的搜索词。提供后，source 将成为必填项。
- `date_before_unix` (integer, optional, nullable) — 用于筛选此日期之前（不含）历史记录的 Unix 时间戳。
- `date_after_unix` (integer, optional, nullable) — 用于筛选此日期之后（含）历史记录的 Unix 时间戳。
- `sort_direction` (enum, optional, nullable, default: desc) — 结果排序方向。
  - Allowed values: `asc`, `desc`
- `search` (string, optional, nullable) — 用于筛选的搜索词
- `source` (enum, optional, nullable) — 生成历史记录的来源
  - Allowed values: `TTS`, `STS`, `Flows`

## Response

### 200

成功响应

- `history` (list of SpeechHistoryItemResponseModel, required) — 语音历史记录列表。
- `has_more` (boolean, required) — 是否还有更多历史记录可获取。
- `last_history_item_id` (string, optional, nullable) — 最后一条历史记录的 ID。
- `scanned_until` (integer, optional, nullable) — 最后一条历史记录的时间戳。

## Errors

### 422 Unprocessable Entity Error

验证错误。

- `detail` (list of ValidationError, optional)

## Types

### SpeechHistoryItemResponseModel

- `history_item_id` (string, required) — 历史记录项 ID。
- `date_unix` (integer, required) — 项目创建时的 Unix 时间戳。
- `character_count_change_from` (integer, required) — 字符数变更前的值。
- `character_count_change_to` (integer, required) — 字符数变更后的值。
- `content_type` (string, required) — 生成项的内容类型。
- `state` (any, required)
- `request_id` (string, optional, nullable) — 请求的 ID。
- `voice_id` (string, optional, nullable) — 所用音色的 ID。
- `model_id` (string, optional, nullable) — 模型的 ID。
- `voice_name` (string, optional, nullable) — 音色名称。
- `voice_category` (enum, optional, nullable) — 音色类别。可以是 'premade'、'cloned'、'generated' 或 'professional'。
  - Allowed values: `premade`, `cloned`, `generated`, `professional`
- `text` (string, optional, nullable) — 用于生成音频项目的文本。
- `settings` (map from string to any, optional, nullable) — 历史记录项的设置。
- `share_link_id` (string, optional, nullable) — 分享链接的 ID。
- `source` (enum, optional, nullable) — 历史记录项的来源。可以是 TTS（文本转语音）、STS（语音转文本）、AN（Audio Native）、项目、配音、PlayAPI、PD（发音词典）或 ConvAI（智能体平台）。
  - Allowed values: `TTS`, `STS`, `Projects`, `PD`, `AN`, `Dubbing`, `PlayAPI`, `ConvAI`, `VoiceGeneration`, `InVPC`, `Flows`, `VoicePreview`
- `alignments` (HistoryAlignmentsResponseModel, optional, nullable) — 历史记录项的对齐信息。
- `dialogue` (list of DialogueInputResponseModel, optional, nullable) — 用于生成音频项的对话（音色和文本对）。设置此项后，顶层的 `text` 和 `voice_id` 字段将为空。
- `output_format` (string, optional, nullable) — 音频最初生成时的输出格式。

### ValidationError

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

### HistoryAlignmentsResponseModel

- `alignment` (HistoryAlignmentResponseModel, required) — 文本对齐信息。
- `normalized_alignment` (HistoryAlignmentResponseModel, required) — 文本的规范化对齐信息。

### DialogueInputResponseModel

- `text` (string, required) — 对话输入行的文本。
- `voice_id` (string, required) — 此对话输入行所用音色的 ID。
- `voice_name` (string, required) — 此对话输入行使用的音色名称。

### ValidationErrorLocItems

- string
- integer

### HistoryAlignmentResponseModel

- `characters` (list of string, required) — 对齐信息中的字符。
- `character_start_times_seconds` (list of double, required) — 字符的起始时间，单位为秒。
- `character_end_times_seconds` (list of double, required) — 字符结束时间，单位为秒。

## Examples

**Response**

```json
{
  "history": [
    {
      "history_item_id": "ja9xsmfGhxYcymxGcOGB",
      "date_unix": 1714650306,
      "character_count_change_from": 17189,
      "character_count_change_to": 17231,
      "content_type": "audio/mpeg",
      "state": null,
      "request_id": "BF0BZg4IwLGBlaVjv9Im",
      "voice_id": "21m00Tcm4TlvDq8ikWAM",
      "model_id": "eleven_multilingual_v2",
      "voice_name": "Rachel",
      "voice_category": "premade",
      "text": "Hello, world!",
      "settings": {
        "similarity_boost": 0.5,
        "stability": 0.71,
        "style": 0,
        "use_speaker_boost": true
      },
      "source": "TTS"
    }
  ],
  "has_more": true,
  "last_history_item_id": "ja9xsmfGhxYcymxGcOGB",
  "scanned_until": 1714650306
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/history"

querystring = {"date_after_unix":"1640995200","date_before_unix":"1640995200","model_id":"eleven_turbo_v2","search":"In the land far far away","sort_direction":"desc","source":"TTS"}

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

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/history?date_after_unix=1640995200&date_before_unix=1640995200&model_id=eleven_turbo_v2&search=In+the+land+far+far+away&sort_direction=desc&source=TTS';
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/history?date_after_unix=1640995200&date_before_unix=1640995200&model_id=eleven_turbo_v2&search=In+the+land+far+far+away&sort_direction=desc&source=TTS"

	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/history?date_after_unix=1640995200&date_before_unix=1640995200&model_id=eleven_turbo_v2&search=In+the+land+far+far+away&sort_direction=desc&source=TTS")

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/history?date_after_unix=1640995200&date_before_unix=1640995200&model_id=eleven_turbo_v2&search=In+the+land+far+far+away&sort_direction=desc&source=TTS")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://api.elevenlabs.io/v1/history?date_after_unix=1640995200&date_before_unix=1640995200&model_id=eleven_turbo_v2&search=In+the+land+far+far+away&sort_direction=desc&source=TTS');

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

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/history?date_after_unix=1640995200&date_before_unix=1640995200&model_id=eleven_turbo_v2&search=In+the+land+far+far+away&sort_direction=desc&source=TTS");
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/history?date_after_unix=1640995200&date_before_unix=1640995200&model_id=eleven_turbo_v2&search=In+the+land+far+far+away&sort_direction=desc&source=TTS")! 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()
```