# YouTube Keywords Discovery Tool (`w3crawler/youtube-keywords-discovery-tool`) Actor

Discover localized YouTube autocomplete phrases and attach current, first-party YouTube search-result evidence. This actor does not estimate search volume.

- **URL**: https://apify.com/w3crawler/youtube-keywords-discovery-tool.md
- **Developed by:** [w3crawler](https://apify.com/w3crawler) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.99 / 1,000 keyword discoveries

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## YouTube Keywords Discovery Tool

Discover localized phrases from YouTube's public autocomplete endpoint and optionally attach rich first-page public YouTube search evidence. The actor does not estimate search volume, scrape private APIs, or label suggestions as trending.

### What it collects

- Seed and expanded autocomplete queries, localized by language and country.
- One deduplicated record per discovered phrase, with the exact source query and suggestion position.
- Optional evidence for each phrase: video ID, title, description, channel name/ID/URL, displayed publish text, displayed view count and parsed count, displayed duration and seconds, badges, thumbnail set, canonical watch URL, evidence rank, and parser source.
- Exact four-field diagnostics (`url`, `error`, `errorCode`, `scrapedAt`) for blocked, failed, or empty public requests.
- An `OUTPUT` key-value record with item, request, proxy, failure, and timing counts.

Search evidence is limited to the first public results page because YouTube does not provide a stable documented pagination contract for this endpoint. Displayed view counts are preserved as page observations; they are not popularity or search-volume estimates.

### Input

| Field | Default | Rules | Description |
|---|---:|---|---|
| `keywords` | — | Required; 1–20 unique strings, 1–200 chars | Seed phrases. |
| `language` | `en` | 2–3 letters, optional region | Public page language, e.g. `en` or `pt-BR`. |
| `country` | `US` | Two letters | Public page country context. |
| `maxSuggestionsPerKeyword` | `20` | 1–50 | Maximum unique phrases per seed. |
| `expandWithLetters` | `false` | boolean | Also query `seed a` through `seed z`. |
| `includeSearchEvidence` | `true` | boolean | Retrieve public search evidence for each phrase. |
| `maxSearchResults` | `5` | 0–10 | Evidence rows per phrase; `0` skips evidence. |
| `maxRetries` | `2` | 0–3 | Bounded retries per public request. |
| `includeDiagnostics` | `true` | boolean | Emit exact diagnostic rows when an operation fails. |
| `enableProxyFallback` | `true` | boolean | Try the account-authorized Apify Proxy route after a direct failure, or direct after an explicit proxy failure. |
| `requestDelayMs` | `250` | 0–5000 | Delay between public requests. |
| `requestTimeoutSecs` | `60` | 5–120 | Timeout for one public request. |
| `proxyConfiguration` | — | optional object | Standard Apify Proxy configuration. Proxy URLs must not contain credentials. |

Example:

```json
{
  "keywords": ["how to cook pasta", "best programming language"],
  "language": "en",
  "country": "US",
  "maxSuggestionsPerKeyword": 10,
  "includeSearchEvidence": true,
  "maxSearchResults": 3,
  "maxRetries": 2,
  "includeDiagnostics": true,
  "enableProxyFallback": true
}
```

### Output record

```json
{
  "recordType": "youtube_keyword_discovery",
  "seedKeyword": "python tutorial",
  "keyword": "python tutorial for beginners",
  "source": "youtube-public-autocomplete",
  "sourceQuery": "python tutorial",
  "suggestionPosition": 1,
  "locale": {"language": "en", "country": "US"},
  "searchEvidenceCount": 1,
  "evidenceAvailable": true,
  "searchEvidenceUrl": "https://www.youtube.com/results?search_query=python+tutorial+for+beginners&hl=en&gl=US",
  "searchEvidence": [{
    "videoId": "abcdefghijk",
    "title": "Example video",
    "channelName": "Example channel",
    "viewCountText": "1.2M views",
    "viewCount": 1200000,
    "durationText": "1:24",
    "durationSeconds": 84,
    "thumbnailUrl": "https://i.ytimg.com/vi/abcdefghijk/hqdefault.jpg",
    "url": "https://www.youtube.com/watch?v=abcdefghijk",
    "rank": 1,
    "searchUrl": "https://www.youtube.com/results?search_query=python+tutorial+for+beginners&hl=en&gl=US",
    "sourceRenderer": "ytInitialData.videoRenderer"
  }],
  "discoveryMethod": "seed-query",
  "requestedMaxSuggestions": 10,
  "requestedMaxSearchResults": 3,
  "retrievedAt": "2026-09-08T10:30:00.000Z"
}
```

Run locally with `apify run --purge --input-file qa-inputs/youtube-keywords-discovery-tool/local-validation.json`, inspect `storage/datasets/default/`, and run `npm run validate-dataset`. Deploy with `apify push`, then call the cloud Actor with the proxy-enabled QA input and compare the dataset and `OUTPUT` store.

# Changelog

This Actor's version history is a separate document: https://apify.com/w3crawler/youtube-keywords-discovery-tool/changelog.md

# Actor input Schema

## `keywords` (type: `array`):

One to 20 seed phrases.

## `language` (type: `string`):

Two- or three-letter language code, optionally with a region.

## `country` (type: `string`):

Two-letter ISO country code used for public page localization.

## `maxSuggestionsPerKeyword` (type: `integer`):

Maximum unique autocomplete phrases emitted for each seed.

## `expandWithLetters` (type: `boolean`):

Also query the seed with each letter suffix.

## `includeSearchEvidence` (type: `boolean`):

Fetch current public YouTube search-result evidence for each discovered phrase.

## `maxSearchResults` (type: `integer`):

Maximum first-page video results per phrase; 0 skips evidence.

## `maxRetries` (type: `integer`):

Bounded retry attempts after a failed public request.

## `includeDiagnostics` (type: `boolean`):

Store exact four-field diagnostics for public access or parsing failures.

## `enableProxyFallback` (type: `boolean`):

Try the configured Apify Proxy route when direct public access fails, or direct access after an explicit proxy route fails.

## `requestDelayMs` (type: `integer`):

Bounded delay between public requests.

## `requestTimeoutSecs` (type: `integer`):

Timeout for one public HTTP request.

## `proxyConfiguration` (type: `object`):

Optional account-authorized Apify Proxy settings. Proxy URLs must be credential-free.

## Actor input object example

```json
{
  "keywords": [
    "how to cook pasta"
  ],
  "language": "en",
  "country": "US",
  "maxSuggestionsPerKeyword": 20,
  "expandWithLetters": false,
  "includeSearchEvidence": true,
  "maxSearchResults": 5,
  "maxRetries": 2,
  "includeDiagnostics": true,
  "enableProxyFallback": true,
  "requestDelayMs": 250,
  "requestTimeoutSecs": 60,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

## `dataset` (type: `string`):

No description

## `keyValueStore` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "keywords": [
        "how to cook pasta"
    ],
    "language": "en",
    "country": "US",
    "maxSuggestionsPerKeyword": 20,
    "expandWithLetters": false,
    "includeSearchEvidence": true,
    "maxSearchResults": 5,
    "maxRetries": 2,
    "includeDiagnostics": true,
    "enableProxyFallback": true,
    "requestDelayMs": 250,
    "requestTimeoutSecs": 60,
    "proxyConfiguration": {
        "useApifyProxy": false
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("w3crawler/youtube-keywords-discovery-tool").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "keywords": ["how to cook pasta"],
    "language": "en",
    "country": "US",
    "maxSuggestionsPerKeyword": 20,
    "expandWithLetters": False,
    "includeSearchEvidence": True,
    "maxSearchResults": 5,
    "maxRetries": 2,
    "includeDiagnostics": True,
    "enableProxyFallback": True,
    "requestDelayMs": 250,
    "requestTimeoutSecs": 60,
    "proxyConfiguration": { "useApifyProxy": False },
}

# Run the Actor and wait for it to finish
run = client.actor("w3crawler/youtube-keywords-discovery-tool").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "keywords": [
    "how to cook pasta"
  ],
  "language": "en",
  "country": "US",
  "maxSuggestionsPerKeyword": 20,
  "expandWithLetters": false,
  "includeSearchEvidence": true,
  "maxSearchResults": 5,
  "maxRetries": 2,
  "includeDiagnostics": true,
  "enableProxyFallback": true,
  "requestDelayMs": 250,
  "requestTimeoutSecs": 60,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}' |
apify call w3crawler/youtube-keywords-discovery-tool --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,w3crawler/youtube-keywords-discovery-tool"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/DQrE7ANyjhGeig8Ad/builds/CEhd4RK5oKl3nSkhr/openapi.json
