# YouTube Search API

> Search YouTube and get matching videos (title, channel, views, length, publish time) as normalized JSON.

Source: https://www.sandbase.ai/apis/youtube/search
API reference: https://www.sandbase.ai/apis/youtube/search/docs

## Facts

- Provider: YouTube
- Type: Data API
- Endpoint: `POST https://api.sandbase.ai/v1/api/youtube/search`
- Price: From $0.0005 per call
- Capabilities: api, youtube, social media
- Billing: pay per use from one SandBase balance; no provider account or subscription needed

## Call it

`POST https://api.sandbase.ai/v1/api/youtube/search` with `Authorization: Bearer $SANDBASE_API_KEY` and the parameters as a JSON body.

| Parameter | Type | Required | Allowed values |
| --- | --- | --- | --- |
| `query` | string | yes |  |
| `cursor` | string | no |  |
| `sortBy` | string | no | relevance, popular |
| `uploadDate` | string | no | today, this_week, this_month, this_year |
| `requireCursor` | boolean | no |  |
| `requireFields` | array | no |  |

## FAQ

### How do I use the YouTube Search API?

Send a POST request to https://api.sandbase.ai/v1/api/youtube/search with your SandBase API key in the Authorization header (Bearer) and the parameters as a JSON body. You can also try it in the Playground on this page without writing code.

### How much does the YouTube Search API cost?

From $0.0005 per call, billed from your SandBase balance. You are only charged for calls you make; there is no subscription.

### What parameters does the YouTube Search API accept?

Required: query (string). Optional: cursor (string), sortBy (one of relevance, popular), uploadDate (one of today, this_week, this_month, this_year), requireCursor (boolean) and requireFields (array). The Parameters table and the Playground on this page list every field.

### What does the YouTube Search API return?

A JSON response returned in the same HTTP request (synchronous).

### Do I need a YouTube developer account or API key?

No. YouTube Search runs through SandBase, so one SandBase API key covers this endpoint and every other API and model in the catalog. You do not need to apply for YouTube API access separately.

## README

### YouTube Search API

Search YouTube and get matching videos (title, channel, views, length, publish time) as normalized JSON.

#### Request

```bash
curl -X POST "https://api.sandbase.ai/v1/api/youtube/search" \
  -H "Authorization: Bearer $SANDBASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "how to cook rice"}'
```

The result is returned in `outputs[0].data`. A lookup that finds nothing still succeeds and returns `found: false`.

#### Parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `query` | string | Yes | The YouTube search query. |
| `cursor` | string | No | Continuation token from a previous response for pagination. |
| `requireCursor` | boolean | No | Deprecated; send `requireFields: ["nextCursor"]` instead, which does exactly the same thing. Set true if you intend to page through results, so the request is only served by a source that can return a nextCursor. Omit it |
| `requireFields` | array | No | Optional; omit it and routing is unchanged, with the cheapest source serving. Name the output fields this request must be able to return, for example `nextCursor`, and it is served only by a source that returns every one |
| `sortBy` | string | No | Sort order: "relevance" (default) or "popular" (most-viewed). One of: `relevance`, `popular`. |
| `uploadDate` | string | No | Filter by upload recency. Omit for any time. One of: `today`, `this_week`, `this_month`, `this_year`. |

#### Pricing

Billed at the actual cost of each call, usually $0.0005 per request. A call can cost more when the first data source fails and another one answers. Failed calls are not charged. Lookups that find nothing and searches with no results are billed at their actual cost, which is often lower and can be $0.
