# FlashData YouTube Captions API

Retrieve YouTube captions as timestamped text and a full transcript. Uploader-provided captions are selected by default.

Canonical reference: https://flashdata.dev/docs/sources/youtube_captions
Reviewed: 2026-10-23

Endpoint: POST https://data.flashdata.dev/v1/queries/realtime
Authentication: X-API-Key: YOUR_API_KEY
Modes: [Realtime](https://flashdata.dev/docs/reference/realtime-and-async/reference.md#realtime) · [Async](https://flashdata.dev/docs/reference/realtime-and-async/reference.md#async) · [Batch](https://flashdata.dev/docs/reference/batch-and-bulk/reference.md#batch) · [Bulk](https://flashdata.dev/docs/reference/bulk-processing/reference.md)

Required source permission: youtube_captions

Replace YOUR_API_KEY with an API key that has this source permission and available credits. Run requests on your server or agent host.

[Set up authentication](https://flashdata.dev/docs/guides/headers-and-authentication/reference.md)

[Retrieve timestamped captions](https://flashdata.dev/docs/guides/timestamped-captions-recipe/reference.md)

<a id="quickstart"></a>

## Send a request

### Python

```bash
python3 -m pip install requests
```

```python
import json

import requests

api_key = "YOUR_API_KEY"
payload = {
    "source": "youtube_captions",
    "video_id": "dQw4w9WgXcQ",
    "params": {
        "language": "en",
        "auto": False,
    },
}

response = requests.post(
    "https://data.flashdata.dev/v1/queries/realtime",
    headers={"X-API-Key": api_key},
    json=payload,
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), ensure_ascii=False, indent=2))
```

### Bash / cURL

```bash
api_key="YOUR_API_KEY"
curl --fail-with-body --max-time 120 --request POST "https://data.flashdata.dev/v1/queries/realtime" \
  --header "Content-Type: application/json" \
  --header "X-API-Key: $api_key" \
  --data-binary @- <<'FLASHDATA_JSON'
{
  "source": "youtube_captions",
  "video_id": "dQw4w9WgXcQ",
  "params": {
    "language": "en",
    "auto": false
  }
}
FLASHDATA_JSON
```

<a id="parameters"></a>

## Parameters

<a id="parameters-group-0"></a>

### Request body

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <a id="parameter-source"></a> source | string | Yes | — | Set to youtube_captions.  |
| <a id="parameter-video_id"></a> video_id | string | Yes | Not set | The 11-character YouTube video ID, such as FUfGcZ092b0. Accepts letters, numbers, underscores and hyphens. Min length: 11. Max length: 11. Pattern: ^[A-Za-z0-9_-]{11}$ |
| <a id="parameter-params"></a> params | object | No | {} | Settings for this request.  |
| <a id="parameter-callback_url"></a> callback_url | string · nullable | No | Not set | Async and batch only. Public HTTPS completion URL on port 443, up to 2,048 characters. No user credentials or URL fragment. Omit, use null or an empty string for no notification. In a batch, set this on each query, outside params.  |

<a id="parameters-group-1"></a>

### Caption selection

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <a id="parameter-params-language"></a> params.language | string \| array | No | en-orig → en | Omit for English (en-orig, then en). With auto=true, each code tries its -orig track first, then the requested code. Explicit -orig codes and auto=false stay exact. Arrays request 1–10 distinct languages. Omit to prefer en-orig and fall back to en, returning one track. With auto=true, each code tries its -orig track first, then the requested code; explicit -orig codes and auto=false stay exact. Arrays of 1–10 distinct codes try every requested language and return tracks and per-language errors in request order. languageCode identifies the selected track; requestedLanguageCode is included when it differs from the requested code. |
| <a id="parameter-params-auto"></a> params.auto | boolean | No | false | true selects YouTube-generated captions; false selects uploader-provided captions. This selects caption origin, not language detection or new transcription.  |

<a id="response"></a>

## Read the result

Save the successful JSON response as response.json. Save this as read-response.py and run python read-response.py. It uses only Python's standard library and makes no new request.

### read-response.py

```python
import json
from pathlib import Path

response = json.loads(Path("response.json").read_text(encoding="utf-8-sig"))
if response.get("status") not in ("done", "completed") or not isinstance(response.get("results"), list):
    raise SystemExit("Expected completed result JSON; inspect the response or job status.")
if not response["results"]:
    print("[]")
    raise SystemExit(0)
result = response["results"][0]

output = {
    "tracks": result.get("tracks", [result]),
    "errors": result.get("errors", []),
}
print(json.dumps(output, ensure_ascii=False, indent=2))
```

## Sample response

Recorded example; fields and counts depend on the source and requested input.
```json
{
  "source": "youtube_captions",
  "status": "done",
  "results": [
    {
      "videoId": "dQw4w9WgXcQ",
      "languageCode": "en",
      "languageName": null,
      "isAutoGenerated": false,
      "segments": [
        {
          "start": 1.36,
          "end": 3.04,
          "text": "[♪♪♪]"
        },
        {
          "start": 18.64,
          "end": 21.880000000000003,
          "text": "♪ We're no strangers to love ♪"
        },
        {
          "start": 22.64,
          "end": 26.96,
          "text": "♪ You know the rules\nand so do I ♪"
        },
        {
          "start": 27.04,
          "end": 31.04,
          "text": "♪ A full commitment's\nwhat I'm thinking of ♪"
        },
        {
          "start": 31.12,
          "end": 35.08,
          "text": "♪ You wouldn't get this\nfrom any other guy ♪"
        },
        {
          "start": 35.16,
          "end": 39.52,
          "text": "♪ I just wanna tell you\nhow I'm feeling ♪"
        },
        {
          "start": 40.52,
          "end": 42.92,
          "text": "♪ Gotta make you understand ♪"
        },
        {
          "start": 43,
          "end": 45.12,
          "text": "♪ Never gonna give you up ♪"
        },
        {
          "start": 45.2,
          "end": 47.080000000000005,
          "text": "♪ Never gonna let you down ♪"
        },
        {
          "start": 47.32,
          "end": 51.12,
          "text": "♪ Never gonna run around\nand desert you ♪"
        },
        {
          "start": 51.48,
          "end": 53.48,
          "text": "♪ Never gonna make you cry ♪"
        },
        {
          "start": 53.6,
          "end": 55.52,
          "text": "♪ Never gonna say goodbye ♪"
        },
        {
          "start": 55.72,
          "end": 59.36,
          "text": "♪ Never gonna tell a lie\nand hurt you ♪"
        },
        {
          "start": 60.8,
          "end": 64.8,
          "text": "♪ We've known each other\nfor so long ♪"
        },
        {
          "start": 64.88,
          "end": 69.03999999999999,
          "text": "♪ Your heart's been aching\nbut you're too shy to say it ♪"
        },
        {
          "start": 69.12,
          "end": 72.96000000000001,
          "text": "♪ Inside we both know\nwhat's been going ♪"
        },
        {
          "start": 73.36,
          "end": 77.2,
          "text": "♪ We know the game\nand we're gonna play it ♪"
        },
        {
          "start": 77.4,
          "end": 82.04,
          "text": "♪ And if you ask me\nhow I'm feeling ♪"
        },
        {
          "start": 82.4,
          "end": 85.24000000000001,
          "text": "♪ Don't tell me\nyou're too blind to see ♪"
        },
        {
          "start": 85.32,
          "end": 87.27999999999999,
          "text": "♪ Never gonna give you up ♪"
        },
        {
          "start": 87.36,
          "end": 89.32,
          "text": "♪ Never gonna let you down ♪"
        },
        {
          "start": 89.44,
          "end": 93.72,
          "text": "♪ Never gonna run around\nand desert you ♪"
        },
        {
          "start": 93.8,
          "end": 95.6,
          "text": "♪ Never gonna make you cry ♪"
        },
        {
          "start": 95.76,
          "end": 98,
          "text": "♪ Never gonna say goodbye ♪"
        },
        {
          "start": 98.08,
          "end": 102.04,
          "text": "♪ Never gonna tell a lie\nand hurt you ♪"
        },
        {
          "start": 102.2,
          "end": 104.12,
          "text": "♪ Never gonna give you up ♪"
        },
        {
          "start": 104.28,
          "end": 106.36,
          "text": "♪ Never gonna let you down ♪"
        },
        {
          "start": 106.48,
          "end": 110.08,
          "text": "♪ Never gonna run around\nand desert you ♪"
        },
        {
          "start": 110.76,
          "end": 112.72,
          "text": "♪ Never gonna make you cry ♪"
        },
        {
          "start": 112.8,
          "end": 114.68,
          "text": "♪ Never gonna say goodbye ♪"
        },
        {
          "start": 114.96,
          "end": 118.76,
          "text": "♪ Never gonna tell a lie\nand hurt you ♪"
        },
        {
          "start": 119.84,
          "end": 122.96,
          "text": "♪ (Ooh, give you up) ♪"
        },
        {
          "start": 123.72,
          "end": 127.36,
          "text": "♪ (Ooh, give you up) ♪"
        },
        {
          "start": 128.48,
          "end": 130.11999999999998,
          "text": "♪ Never gonna give,\nnever gonna give ♪"
        },
        {
          "start": 130.24,
          "end": 131.56,
          "text": "♪ (Give you up) ♪"
        },
        {
          "start": 132.48,
          "end": 134.23999999999998,
          "text": "♪ Never gonna give,\nnever gonna give ♪"
        },
        {
          "start": 134.36,
          "end": 135.92000000000002,
          "text": "♪ (Give you up) ♪"
        },
        {
          "start": 136.76,
          "end": 141.07999999999998,
          "text": "♪ We've known each other\nfor so long ♪"
        },
        {
          "start": 141.2,
          "end": 145.2,
          "text": "♪ Your heart's been aching\nbut you're too shy to say it ♪"
        },
        {
          "start": 145.28,
          "end": 149.12,
          "text": "♪ Inside we both know\nwhat's been going ♪"
        },
        {
          "start": 149.52,
          "end": 153.20000000000002,
          "text": "♪ We know the game\nand we're gonna play it ♪"
        },
        {
          "start": 153.36,
          "end": 158.04000000000002,
          "text": "♪ I just wanna tell you\nhow I'm feeling ♪"
        },
        {
          "start": 158.64,
          "end": 161.32,
          "text": "♪ Gotta make you understand ♪"
        },
        {
          "start": 161.4,
          "end": 163.36,
          "text": "♪ Never gonna give you up ♪"
        },
        {
          "start": 163.44,
          "end": 165.64,
          "text": "♪ Never gonna let you down ♪"
        },
        {
          "start": 165.72,
          "end": 169.72,
          "text": "♪ Never gonna run around\nand desert you ♪"
        },
        {
          "start": 169.8,
          "end": 171.64,
          "text": "♪ Never gonna make you cry ♪"
        },
        {
          "start": 171.8,
          "end": 173.96,
          "text": "♪ Never gonna say goodbye ♪"
        },
        {
          "start": 174.04,
          "end": 177.6,
          "text": "♪ Never gonna tell a lie\nand hurt you ♪"
        },
        {
          "start": 178.2,
          "end": 180.24,
          "text": "♪ Never gonna give you up ♪"
        },
        {
          "start": 180.32,
          "end": 182.44,
          "text": "♪ Never gonna let you down ♪"
        },
        {
          "start": 182.52,
          "end": 186.64,
          "text": "♪ Never gonna run around\nand desert you ♪"
        },
        {
          "start": 186.72,
          "end": 188.72,
          "text": "♪ Never gonna make you cry ♪"
        },
        {
          "start": 188.84,
          "end": 190.72,
          "text": "♪ Never gonna say goodbye ♪"
        },
        {
          "start": 190.84,
          "end": 195.2,
          "text": "♪ Never gonna tell a lie\nand hurt you ♪"
        },
        {
          "start": 195.28,
          "end": 197.12,
          "text": "♪ Never gonna give you up ♪"
        },
        {
          "start": 197.2,
          "end": 199.24,
          "text": "♪ Never gonna let you down ♪"
        },
        {
          "start": 199.4,
          "end": 203.12,
          "text": "♪ Never gonna run around\nand desert you ♪"
        },
        {
          "start": 203.36,
          "end": 205.6,
          "text": "♪ Never gonna make you cry ♪"
        },
        {
          "start": 205.68,
          "end": 207.84,
          "text": "♪ Never gonna say goodbye ♪"
        },
        {
          "start": 207.92,
          "end": 211.32,
          "text": "♪ Never gonna tell a lie\nand hurt you ♪"
        }
      ],
      "fullText": "[♪♪♪] ♪ We're no strangers to love ♪ ♪ You know the rules\nand so do I ♪ ♪ A full commitment's\nwhat I'm thinking of ♪ ♪ You wouldn't get this\nfrom any other guy ♪ ♪ I just wanna tell you\nhow I'm feeling ♪ ♪ Gotta make you understand ♪ ♪ Never gonna give you up ♪ ♪ Never gonna let you down ♪ ♪ Never gonna run around\nand desert you ♪ ♪ Never gonna make you cry ♪ ♪ Never gonna say goodbye ♪ ♪ Never gonna tell a lie\nand hurt you ♪ ♪ We've known each other\nfor so long ♪ ♪ Your heart's been aching\nbut you're too shy to say it ♪ ♪ Inside we both know\nwhat's been going ♪ ♪ We know the game\nand we're gonna play it ♪ ♪ And if you ask me\nhow I'm feeling ♪ ♪ Don't tell me\nyou're too blind to see ♪ ♪ Never gonna give you up ♪ ♪ Never gonna let you down ♪ ♪ Never gonna run around\nand desert you ♪ ♪ Never gonna make you cry ♪ ♪ Never gonna say goodbye ♪ ♪ Never gonna tell a lie\nand hurt you ♪ ♪ Never gonna give you up ♪ ♪ Never gonna let you down ♪ ♪ Never gonna run around\nand desert you ♪ ♪ Never gonna make you cry ♪ ♪ Never gonna say goodbye ♪ ♪ Never gonna tell a lie\nand hurt you ♪ ♪ (Ooh, give you up) ♪ ♪ (Ooh, give you up) ♪ ♪ Never gonna give,\nnever gonna give ♪ ♪ (Give you up) ♪ ♪ Never gonna give,\nnever gonna give ♪ ♪ (Give you up) ♪ ♪ We've known each other\nfor so long ♪ ♪ Your heart's been aching\nbut you're too shy to say it ♪ ♪ Inside we both know\nwhat's been going ♪ ♪ We know the game\nand we're gonna play it ♪ ♪ I just wanna tell you\nhow I'm feeling ♪ ♪ Gotta make you understand ♪ ♪ Never gonna give you up ♪ ♪ Never gonna let you down ♪ ♪ Never gonna run around\nand desert you ♪ ♪ Never gonna make you cry ♪ ♪ Never gonna say goodbye ♪ ♪ Never gonna tell a lie\nand hurt you ♪ ♪ Never gonna give you up ♪ ♪ Never gonna let you down ♪ ♪ Never gonna run around\nand desert you ♪ ♪ Never gonna make you cry ♪ ♪ Never gonna say goodbye ♪ ♪ Never gonna tell a lie\nand hurt you ♪ ♪ Never gonna give you up ♪ ♪ Never gonna let you down ♪ ♪ Never gonna run around\nand desert you ♪ ♪ Never gonna make you cry ♪ ♪ Never gonna say goodbye ♪ ♪ Never gonna tell a lie\nand hurt you ♪"
    }
  ],
  "usage": {
    "credits": 0.01
  },
  "created_at": "2026-09-16T07:45:46.290Z"
}
```

## Multiple languages

Send a language array to receive tracks and per-language errors. This example shows English available and Spanish unavailable.

```json
{
  "source": "youtube_captions",
  "video_id": "jNQXAC9IVRw",
  "params": {
    "language": [
      "en",
      "es"
    ],
    "auto": false
  }
}
```

`results[0]`:

```json
{
  "videoId": "jNQXAC9IVRw",
  "isAutoGenerated": false,
  "tracks": [
    {
      "videoId": "jNQXAC9IVRw",
      "languageCode": "en",
      "languageName": null,
      "isAutoGenerated": false,
      "segments": [
        {
          "start": 0,
          "end": 1.5,
          "text": "Hello world."
        }
      ],
      "fullText": "Hello world."
    }
  ],
  "errors": [
    {
      "languageCode": "es",
      "code": "language_unavailable",
      "message": "Uploader-provided subtitles not available for language: es"
    }
  ]
}
```

## Response fields

| Field | Type | Description |
| --- | --- | --- |
| source | string | The requested API source. |
| status | string | done when the realtime request succeeds. |
| created_at | string | Response creation time in ISO 8601 format. |
| usage.credits | number | Credits charged for the request, based on your plan. |
| results[0].videoId | string | The requested video ID. |
| results[0].languageCode | string | Actual selected caption track code, such as en-orig. |
| results[0].languageName | string · nullable | Language display name when available. |
| results[0].requestedLanguageCode | string · optional | The requested code when it differs from languageCode, for example en when en-orig was selected. |
| results[0].isAutoGenerated | boolean | Whether the selected captions were generated automatically. |
| results[0].segments | array | Caption segments in chronological order. |
| results[0].segments[].start | number | Segment start time in seconds. |
| results[0].segments[].end | number | Segment end time in seconds. |
| results[0].segments[].text | string | Caption text. |
| results[0].fullText | string | All segment text joined into a transcript. |
| results[0].tracks | array · optional | For language arrays only. Available tracks in request order; each has the single-track fields listed above. |
| results[0].errors | array · optional | For language arrays only. Failed languages in request order. Empty when every track succeeds. |
| results[0].errors[].languageCode | string | The requested language that failed. |
| results[0].errors[].code | string | language_unavailable when the selected track does not exist; retrieval_failed when it could not be downloaded or parsed. |
| results[0].errors[].message | string | Description of the language failure. |

- The API reads captions already available on YouTube. It does not generate new transcripts or fall back between automatic and uploader-provided captions.
- A string language keeps the single-track response. An array, even ["en"], returns tracks and errors instead of top-level languageCode, segments and fullText. Each track includes those fields. auto applies to every language.
- For language arrays, check errors for tracks that failed. If no tracks are retrieved, the request fails and any reserved credits are refunded. Video extraction failures and request deadline expiry also fail the request.
- Available for realtime, async, batch and bulk. Bulk exports stay JSONL with one record per video, including its tracks and errors. Accept and X-Respond-With apply as usual.

## Response formats

Responses use JSON by default. Choose another format with these optional headers.

- Accept: application/json (default) or text/plain. Plain text presents the same fields in a readable, indented layout.
- X-Respond-With: markdown. Leave unset for original fields. Markdown works with either response format.

Markdown is available for realtime queries and completed results.

The fields below describe the default JSON response.

[Request and response format examples](https://flashdata.dev/docs/guides/response-formats/reference.md#headers)

<a id="job-lifecycle"></a>

<a id="async-batch"></a>

## API basics

The request builder and examples above use this source's parameters. Use the Python and cURL examples below for shared submission, status and result steps. A Batch body is a JSON object containing queries; each item returns its own job ID.

- [Async request and receipt](https://flashdata.dev/docs/reference/realtime-and-async/reference.md#async)

<a id="job-status"></a>

- [Check job status](https://flashdata.dev/docs/reference/realtime-and-async/reference.md#status)

<a id="job-results"></a>

- [Retrieve completed results](https://flashdata.dev/docs/reference/realtime-and-async/reference.md#results)
- [Batch JSON requests](https://flashdata.dev/docs/reference/batch-and-bulk/reference.md#batch)
- [Bulk processing API](https://flashdata.dev/docs/reference/bulk-processing/reference.md)
- [Build a Bulk workflow for this source](https://flashdata.dev/docs/reference/bulk-processing/reference.md?source=youtube_captions#playground)
- [Customer OpenAPI](https://flashdata.dev/docs/openapi.json)

<a id="webhooks"></a>

<a id="callbacks"></a>

## Completion notifications

- [Receive and verify completion webhooks](https://flashdata.dev/docs/guides/async-batch/reference.md#webhooks)

<a id="troubleshooting"></a>

## Troubleshooting

- [Errors and status codes](https://flashdata.dev/docs/errors/reference.md#status-codes)
- [When to retry](https://flashdata.dev/docs/errors/reference.md#retries)

## Related APIs

- [YouTube Transcript API](https://flashdata.dev/docs/sources/youtube_transcript/reference.md)
- [YouTube Video Metadata API](https://flashdata.dev/docs/sources/youtube_metadata/reference.md)
