# YouTube Metadata Lookup (Bring Your Own Key) (`hydra_search/youtube-metadata-lookup`) Actor

Live video, channel, playlist and search metadata from the official YouTube Data API v3, using your own API key and quota. No caching, no transcripts, no scraping.

- **URL**: https://apify.com/hydra_search/youtube-metadata-lookup.md
- **Developed by:** [HYDRA SEARCH](https://apify.com/hydra_search) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 metadata records

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 Metadata Lookup

Live video, channel, playlist and keyword-search metadata from the official **YouTube Data API v3** — with your own API key and quota. No caching, no transcripts, no scraping.

### Why bring your own key?

YouTube's Developer Policies don't allow a third party to resell access to the API or to cache/redistribute the data it returns beyond narrow limits. So instead of us holding a shared key and reselling access to it, **you** supply your own API key from your own Google Cloud project, and every run calls the API live, on your own quota, and returns the results only to you. See `SOURCE_TERMS.md` for the exact clauses this is built around.

#### Trying it without a key first

Run it with no `apiKey` at all and it won't error out — you'll get back one sample row (`isSampleTestRecord: true`, titled "SAMPLE VIDEO (no API key supplied)") so you can see the output shape before setting up your own key. Nothing is charged for that row. The input form's `apiKey` field has no default value, so this is also what Apify Store's automatic "Try for free" test run hits.

#### Getting an API key (free)

1. Go to [console.cloud.google.com](https://console.cloud.google.com), create or pick a project.
2. Enable the **YouTube Data API v3** for that project.
3. Create credentials → API key.
4. Paste it into this Actor's `apiKey` input. It's a secret field — Apify won't show or log it.

YouTube's standard free quota is 10,000 units/day per project. A video/channel/playlist lookup costs 1 unit per batch of up to 50 items; a keyword search costs 100 units per page of results.

### What it returns

Metadata and public statistics only — titles, descriptions, publish dates, durations, view/like/comment counts, subscriber counts, and similar fields the API publishes. **No transcripts or captions** — there is no official API for fetching another channel's video transcripts, so this Actor doesn't attempt it (see `SOURCE_TERMS.md`).

Every record carries a `provenance` block: the canonical `youtube.com` URL for that item, when it was fetched, and a note that the data is live from the API, not a cached snapshot.

Video rows also get four computed fields, free (no extra API quota): `durationSeconds`, `isShort` (60 seconds or less), `engagementRate` (`(likes + comments) / views`), and `viewsPerDay` (views divided by days since publish). Any of them is `null` when its inputs are missing.

### Ranking and filters

`sortBy` (`viewCount`, `likeCount`, `commentCount` or `engagementRate`), `topN` and `minViewCount` let you ask for just the best rows instead of everything. They're applied after fetching, before pushing: drop rows below `minViewCount`, sort by `sortBy` highest-first, then keep the first `topN`. **Only the rows that survive this are pushed, and only pushed rows are charged** — so a run with `topN: 3` only ever charges you for 3 records, however many it had to fetch to rank them. A row missing the field used to sort or filter gets a `rankingNote` and is treated as 0.

### Channel uploads

Turn on `includeChannelUploads` to get each channel's recent uploads alongside its own metadata row, via YouTube's official "uploads" playlist — the same kind of row you'd get from looking up a playlist directly, tagged `channelUpload`. `maxUploadsPerChannel` caps how many per channel; if a channel has more uploads than that, you'll see a clear warning (logged, and listed in `RUN_SUMMARY.truncatedChannelUploads`) rather than a silently incomplete list.

### Comments

Turn on `includeComments` to also get each video's top-level comments (not replies) as their own rows, up to `maxCommentsPerVideo` per video. **Comments are priced separately from metadata rows**, under their own pay-per-event event, `comment-record` — see Pricing below. A video with comments turned off by its owner is skipped quietly; it doesn't fail the run.

### Important: this is a live lookup tool, not a dataset

Each run calls YouTube fresh and returns only what the API said at that moment. This Actor doesn't store or re-serve a previous run's results, and it doesn't build up a growing dataset over time. If you need a historical record, save the output yourself — that's your data, under your own account, same as if you'd called the API directly.

### Inputs

See the input form for full descriptions. In short: `apiKey` (secret — leave empty to get the sample row instead, see above), then any mix of `videoIds`, `channelRefs`, `playlistIds`, `searchQuery`, plus `maxResults` and `maxQuotaUnits` safety caps, `sortBy`/`topN`/`minViewCount` for ranking and filters, `includeChannelUploads`/`maxUploadsPerChannel` for channel uploads, and `includeComments`/`maxCommentsPerVideo` for comments.

### When a run stops early

The run summary (`RUN_SUMMARY` in the key-value store) always says why, in `stoppedReason`:

- `maxResults` — you got everything you asked for, up to your cap.
- `chargeLimit` — the Actor's own pay-per-event budget for this run was spent.
- `quotaBudget` — your `maxQuotaUnits` safety cap was reached before YouTube's own limit.
- `apiQuotaExceeded` — YouTube itself said your project's real daily quota is used up.

None of these are errors — the run finishes cleanly either way. A genuinely bad API key or a malformed request surfaces YouTube's own error message instead of being hidden.

### Pricing

Pay per result (event `metadata-record`): $1.50 per 1,000 results ($0.0015 each). You also pay Google nothing extra: the YouTube API quota is your own key's quota. See `SPEC.md` §7 for the reasoning.

Comments are priced separately, under a second event, `comment-record`. **No price has been set for it yet** — it needs to be entered in the Apify Console (Actor > Publication > Monetization > Pay per event > add event `comment-record`), same place `metadata-record` was entered.

# Actor input Schema

## `apiKey` (type: `string`):

A YouTube Data API v3 key from your own Google Cloud project (console.cloud.google.com, enable "YouTube Data API v3", create an API key). Used only for this run, never stored or logged. Quota usage counts against your own project's quota, not ours.

## `videoIds` (type: `array`):

YouTube video IDs (e.g. dQw4w9WgXcQ) or full video URLs (watch, youtu.be, shorts, embed). Leave empty to skip video lookups.

## `channelRefs` (type: `array`):

Channel IDs (start with UC...) or handles (e.g. @mkbhd, with or without the @). Leave empty to skip channel lookups.

## `playlistIds` (type: `array`):

Playlist IDs (e.g. PL... or UU...) or full playlist URLs. Each playlist also returns its items (videos in the playlist), up to the overall max results cap. Leave empty to skip playlist lookups.

## `searchQuery` (type: `string`):

A keyword search, same as typing into YouTube's search box. Leave empty to skip. Search is the most expensive call against your quota (100 units per call) — see README.

## `maxResults` (type: `integer`):

Stop after returning this many records in total, across every lookup type in this run.

## `maxQuotaUnits` (type: `integer`):

Stop cleanly once this many YouTube API quota units have been spent in this run, so one run can't silently use your whole daily allowance. The default (10,000) matches YouTube's standard daily project quota. Lower it if you share that quota with other tools.

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

Sort the finished rows by this field, highest first. Applied after fetching, before pushing — a missing value on a row counts as 0.

## `topN` (type: `integer`):

Optional. Keep only the first N rows after filtering and sorting. Only kept rows are pushed, and only pushed rows are charged.

## `minViewCount` (type: `integer`):

Drop rows with fewer views than this. A missing view count is treated as 0.

## `includeChannelUploads` (type: `boolean`):

For each channel in Channel IDs or handles, also return its recent uploads (via the channel's official uploads playlist), up to Max uploads per channel.

## `maxUploadsPerChannel` (type: `integer`):

Cap on how many recent uploads to return per channel when Include channel uploads is on. You'll get a clear warning if a channel has more uploads than this cap.

## `includeComments` (type: `boolean`):

For every video row returned (including from videoIds, playlists and channel uploads), also return its top-level comments, up to Max comments per video. Pushed as separate rows, priced separately from metadata rows — see README for the event name.

## `maxCommentsPerVideo` (type: `integer`):

Cap on how many top-level comments to return per video when Include comments is on.

## Actor input object example

```json
{
  "videoIds": [],
  "channelRefs": [],
  "playlistIds": [],
  "searchQuery": "",
  "maxResults": 10,
  "maxQuotaUnits": 1000,
  "sortBy": "none",
  "minViewCount": 0,
  "includeChannelUploads": false,
  "maxUploadsPerChannel": 10,
  "includeComments": false,
  "maxCommentsPerVideo": 10
}
```

# Actor output Schema

## `metadata` (type: `string`):

One row per video/channel/playlist/playlistItem/searchResult looked up (or one sample row when no API key was supplied), using the "overview" view defined in dataset_schema.json.

# 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 = {
    "videoIds": [],
    "channelRefs": [],
    "playlistIds": [],
    "searchQuery": "",
    "maxResults": 10,
    "maxQuotaUnits": 1000
};

// Run the Actor and wait for it to finish
const run = await client.actor("hydra_search/youtube-metadata-lookup").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 = {
    "videoIds": [],
    "channelRefs": [],
    "playlistIds": [],
    "searchQuery": "",
    "maxResults": 10,
    "maxQuotaUnits": 1000,
}

# Run the Actor and wait for it to finish
run = client.actor("hydra_search/youtube-metadata-lookup").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 '{
  "videoIds": [],
  "channelRefs": [],
  "playlistIds": [],
  "searchQuery": "",
  "maxResults": 10,
  "maxQuotaUnits": 1000
}' |
apify call hydra_search/youtube-metadata-lookup --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,hydra_search/youtube-metadata-lookup"
        }
    }
}
```

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/e4PHavFOchfpDiHy0/builds/DeRX30wSIwwF4bKDB/openapi.json
