# YouTube Search API - Video Results by Keyword (`stas_k/youtube-search-results-api`) Actor

You should not have to copy YouTube results by hand page by page. This actor searches by keyword, pages deep with the continuation token and returns one row per video: title, channel, views, age, duration and url.

- **URL**: https://apify.com/stas_k/youtube-search-results-api.md
- **Developed by:** [Stas K](https://apify.com/stas_k) (community)
- **Categories:** Social media, Developer tools, SEO tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.40 / 1,000 videos

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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 Search API - Video Results by Keyword

You should not have to copy YouTube results by hand page after page. Give this actor one
or more keyword phrases and it returns one row per video: title, channel, views, age,
duration, thumbnail and a direct url. It pages through the results with the continuation
token the page itself hands back, so the long tail of a niche is reachable, not just the
first screen.

### What you get

One row per video:

| field | meaning |
|---|---|
| `query` | the phrase this video was found for |
| `videoId`, `url` | the id and `https://www.youtube.com/watch?v=<id>` |
| `title` | as shown in the results |
| `channel`, `channelId`, `channelUrl` | who published it |
| `views`, `viewsText` | view count as a number and as shown (`13,456,364` / `13,456,364 views`) |
| `publishedText`, `publishedDaysAgo` | age as the page states it, and that age converted to a lower bound in days |
| `durationText`, `durationSeconds` | length, both as shown and in seconds |
| `isLive` | `true` for a live broadcast, otherwise `null` |
| `badges` | labels the page carries (for example `Fundraiser`) |
| `description` | the snippet YouTube shows under the result, when it shows one |
| `thumbnailUrl` | cover image |
| `status`, `billable` | `OK` for a delivered video; a status row carries a reason instead of data |

### Depth, measured

On 2026-11-12 a search page returned 9-20 videos and a continuation token, and five pages
of one phrase gave **79 unique videos**. `maxResultsPerQuery` defaults to 50 and is capped
at 500. Depth is limited by how many pages YouTube is willing to serve for a phrase, not by
this actor: when the token runs out, the phrase is finished.

`sortBy=views` really reorders the page (the first result is the most watched).
`sortBy=date` and `sortBy=rating` are **ignored by the endpoint** - the first page comes
back identical - so they are not offered here. For fresh videos use `uploadDate`:
`hour`, `today`, `week`, `month` or `year` really do restrict the page (measured: a week
filter returned videos published 23 hours to 6 days ago).

### What this actor does not do

- It does not read transcripts or captions - that is a different actor.
- It does not read comments.
- It does not return the exact upload timestamp: YouTube shows an age ("2 years ago"), so
  `publishedDaysAgo` is a lower bound, not a date. Do not treat it as one.
- It does not click through to the video page. Everything above comes from the results
  page itself.
- It does not bypass a block. If YouTube answers something other than results, the row says
  so and costs nothing.
- It does not return **Shorts**. YouTube puts a Shorts shelf beside the results and renders
  those entries as `shortsLockupViewModel`, not as videos. They are counted in
  `shortsSkipped` in the summary and cost nothing; they never become rows. Measured on
  2026-11-12: a search for "cats" carried 40 Shorts next to 9 videos, so this is the
  difference between "nothing was found" and "a shelf was skipped".

### Money

Price: **$0.0004 per delivered video** (`video-delivered`), The lowest spending limit you can set per run is $0.05.

A row is charged only when it reached the dataset. A status row never carries a video id,
a title or a description, so it can never be mistaken for the product.

Free, with the reason in the row:

| status | when |
|---|---|
| `INVALID_INPUT` | the phrase is empty or not a phrase |
| `DUPLICATE` | the same phrase appears twice in one run |
| `NO_RESULTS_FOUND` | the search returned no videos |
| `NOT_CHECKED_LIMIT` | beyond `maxResultsPerQuery` |
| `NOT_CHECKED_TIME` | not enough time before the platform deadline |
| `NOT_CHECKED_ERROR` | the search page could not be read; the reason names the error |
| `NOT_CHECKED_CAP` | the spending cap leaves no budget |
| `NOT_CHECKED_BILLING` | the price could not be read, so nothing is sold |
| `NOT_CHECKED_CHARGE_UNVERIFIED` | the charge failed and the row was not confirmed |

`shortsSkipped` is a counter, not a row: Shorts are never sold here and never delivered,
so nothing about them is charged.

`stopReason` names the money fact first: `spending-cap`, `billing-price-unknown`,
`charge-error`, `dataset-write-error` or `deadline`. `counterMismatch` in the summary is
`true` when delivered rows do not add up to charged plus delivered-unpaid, and
`datasetNote` explains a doubt the counters cannot express.

### Input

| field | default | meaning |
|---|---|---|
| `queries` | required | one or more keyword phrases |
| `maxResultsPerQuery` | 50 | stop after this many videos per phrase |
| `sortBy` | relevance | `relevance` or `views` |
| `uploadDate` | any | `hour`, `today`, `week`, `month`, `year` |
| `videoDuration` | any | `short` (under 4 min), `medium`, `long` (over 20 min) |
| `region` | US | two letter country code that shapes the mix |
| `language` | en | two letter language code for titles and labels |

### Resource use

512 MB of memory and no browser: the actor talks to the public search endpoint with plain
HTTP, so a run of 50 videos finishes in seconds and a large run in a couple of minutes.

### Status of this build

`0.1`. The parsing is checked against a saved real page, and the money path is checked by
running the real `main()` against a stand that repeats the SDK, including its silent cut of
a batch that does not fit the budget.

# Actor input Schema

## `queries` (type: `array`):

One or more keyword phrases. Each phrase is searched once and gives its own rows.

## `maxResultsPerQuery` (type: `integer`):

Stop after this many videos for each phrase. Paging follows the page's own continuation token.

## `sortBy` (type: `string`):

relevance keeps YouTube's own order; views puts the most watched first. YouTube ignores date and rating sorting here, so they are not offered; use uploadDate for fresh videos.

## `uploadDate` (type: `string`):

Restrict the page to recent videos. This is the honest way to get fresh results, because the endpoint ignores date sorting.

## `videoDuration` (type: `string`):

Filter by length: short is under 4 minutes, long is over 20.

## `region` (type: `string`):

Two letter country code that shapes the result mix, for example US, DE or UA.

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

Two letter language code for titles and labels, for example en or de.

## Actor input object example

```json
{
  "queries": [
    "python tutorial",
    "ai news"
  ],
  "maxResultsPerQuery": 50,
  "sortBy": "relevance",
  "uploadDate": "any",
  "videoDuration": "any",
  "region": "US",
  "language": "en"
}
```

# Actor output Schema

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

Every delivered video has query, videoId, url, title, channel, channelId, views, viewsText, publishedText, publishedDaysAgo, durationText, durationSeconds, isLive, badges, description and thumbnailUrl. Rows with status other than OK carry a reason instead of data.

## `summary` (type: `string`):

Counters, chargedEvents, byStatus, stopReason, datasetNote and counterMismatch. shortsSkipped counts Shorts shelf entries on the pages that were read: YouTube renders them as shortsLockupViewModel rather than videoRenderer, so they never become rows and are counted here. Status codes: OK, INVALID_INPUT, DUPLICATE, NO_RESULTS_FOUND, NOT_CHECKED_LIMIT, NOT_CHECKED_TIME, NOT_CHECKED_ERROR, NOT_CHECKED_CAP, NOT_CHECKED_BILLING, NOT_CHECKED_CHARGE_UNVERIFIED. Stop reasons: spending-cap, billing-price-unknown, charge-error, dataset-write-error, deadline.

# 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 = {
    "queries": [
        "python tutorial",
        "ai news"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("stas_k/youtube-search-results-api").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 = { "queries": [
        "python tutorial",
        "ai news",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("stas_k/youtube-search-results-api").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 '{
  "queries": [
    "python tutorial",
    "ai news"
  ]
}' |
apify call stas_k/youtube-search-results-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,stas_k/youtube-search-results-api"
        }
    }
}
```

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/xJP8DQos5bwjs9RkU/builds/ldLuYuK70jX13OSoy/openapi.json
