# YouTube Search API

> Setting SocialTap up for your user? Follow https://socialtap.dev/setup.md.

YouTube

Returns the YouTube videos, shorts and live streams that match a keyword, across YouTube or in one channel, by best match or popularity. Each has its channel, view count, upload day, length and, across YouTube, the part of the description that matched. Streams on air have no views, upload time or length. [Overview](https://socialtap.dev/apis/youtube/search-posts/index.md)

GET `/v1/youtube/search_posts`

> [!NOTE]
>
> **Good to know**
>
> - published_at is the latest time YouTube's relative upload label allows (listed in approximate_fields): "1 month ago" means one to two months back. The [YouTube Video API](https://socialtap.dev/docs/reference/youtube/post/index.md) returns the exact time.
> - text is the description snippet a result shows, so hashtags and mentions can miss some. text is null in a channel's search and with kind=short.
> - Words YouTube shows only to signed-in adults return private_or_unavailable. With kind=short they return an empty page.
> - A channel that doesn't exist returns not_found. No match, or a channel without search (YouTube's Music channel, an artist's Topic channel), returns an empty page.

## Example

cURL:

```shell
curl -G 'https://socialtap.dev/v1/youtube/search_posts' \
  --data-urlencode 'query=marathon training' \
  -H "x-api-key: $SOCIALTAP_API_KEY"
```

TypeScript SDK:

```typescript
// Save this as app.mjs (an ES module) and run: node app.mjs
import { SocialTap } from "socialtap";

const client = new SocialTap(); // apiKey defaults to process.env.SOCIALTAP_API_KEY

const res = await client.youtube.searchPosts.list({ query: "marathon training" });
console.log(res.data);
console.log(res.credits.charged, res.meta.request_id);
```

Python SDK:

```python
from socialtap import SocialTap

client = SocialTap()  # api_key defaults to os.environ["SOCIALTAP_API_KEY"]

res = client.youtube.search_posts.list(query="marathon training")
print(res.data)
print(res.credits.charged, res.meta.request_id)
```

Go SDK:

```go
package main

import (
	"context"
	"fmt"
	"log"

	socialtap "socialtap.dev/sdk/go"
)

func main() {
	ctx := context.Background()
	client, err := socialtap.NewClient() // the API key defaults to $SOCIALTAP_API_KEY
	if err != nil {
		log.Fatal(err)
	}
	res, err := client.YouTube.SearchPosts.List(ctx, socialtap.YouTubeSearchPostsParams{Query: "marathon training"})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(res.Data)
	fmt.Println(res.Credits.Charged, res.Meta.RequestID)
}
```

200 OK:

```json
{
  "data": [
    {
      "approximate_fields": [
        "published_at",
        "text",
        "hashtags"
      ],
      "author": {
        "avatar_url": "https://yt3.ggpht.com/uwKkQyYtcus-k-dbJlAt4CdiO8m9sAQu5Y3uk8Yy5MT5fAJTwh1RWYhe-L92qIfXHDofRV7rUw=s68-c-k-c0x00ffffff-no-rj",
        "display_name": "Sean Rhodes",
        "id": "UCumqzs0oO3LP2G-4juapxjQ",
        "is_verified": false,
        "url": "https://www.youtube.com/channel/UCumqzs0oO3LP2G-4juapxjQ",
        "username": "SeanRhodes247"
      },
      "coauthors": [],
      "duration_ms": 1473000,
      "hashtags": [],
      "id": "Iad9Tx-rTKw",
      "is_nsfw": null,
      "is_pinned": null,
      "is_sponsored": null,
      "language": null,
      "link_url": null,
      "media": [
        {
          "alt_text": null,
          "duration_ms": 1473000,
          "expires_at": null,
          "height": 360,
          "thumbnail_url": "https://i.ytimg.com/vi/Iad9Tx-rTKw/hqdefault.jpg",
          "type": "video",
          "url": null,
          "width": 480
        }
      ],
      "mentions": [],
      "metrics": {
        "comment_count": null,
        "like_count": null,
        "quote_count": null,
        "repost_count": null,
        "save_count": null,
        "share_count": null,
        "view_count": 19312
      },
      "platform": "youtube",
      "platform_specific": {
        "youtube": {
          "author_subscriber_count": null,
          "category": null,
          "chapters": [],
          "description_links": [],
          "is_age_restricted": null,
          "is_live_now": false,
          "is_paywalled": null,
          "is_unlisted": null,
          "keywords": [],
          "live_ended_at": null,
          "live_started_at": null,
          "scheduled_start_at": null
        }
      },
      "platform_type": "video",
      "published_at": "2026-07-22T00:00:00Z",
      "text": "Come along for a full day in my life while training to run a sub-2:35 marathon at the 2026 Chicago Marathon. In this episode of ...",
      "thumbnail_url": "https://i.ytimg.com/vi/Iad9Tx-rTKw/hqdefault.jpg",
      "title": "Inside My Sub-2:35 Marathon Training | Day in the Life | Road 2 Chicago Ep. 3",
      "type": "video",
      "unknown_fields": [
        "platform_specific.youtube.keywords",
        "platform_specific.youtube.chapters",
        "platform_specific.youtube.description_links"
      ],
      "url": "https://www.youtube.com/watch?v=Iad9Tx-rTKw"
    }
  ],
  "page": {
    "has_more": true,
    "next_cursor": "c1.EXAMPLE_CURSOR",
    "next_cursor_expires_at": "2026-10-26T12:00:00Z",
    "end_reason": null
  },
  "meta": {
    "request_id": "req_3f9c2a7d1e8b4c6a9f0e2d4b6a8c0e1f",
    "platform": "youtube",
    "source": "api",
    "is_cached": false,
    "credits_charged": 1,
    "latency_ms": 1000,
    "fetched_at": "2026-10-25T12:00:00Z",
    "input": null,
    "credits_remaining": 9999,
    "client_request_id": null,
    "warnings": []
  }
}
```

The first item of the page; long arrays and strings are shortened for display.

## Query parameters

| Name | Type | Description | Example |
| --- | --- | --- | --- |
| `query` required | `string`<br>max 500 chars | Words or a phrase, matched by YouTube's search as on youtube.com, in any language. YouTube's operators pass through: "exact phrase", intitle:word, -word, #hashtag. | `marathon training` |
| `kind` optional | `string`<br>default `all` | all: YouTube's result list without its shelves, such as rows of shorts (use short for those). video: YouTube's Videos filter. short: shorts, with rounded view counts and no verification badge. live: streams on air now. platform_type tells results apart.<br>One of `all`, `video`, `short`, `live` | `short` |
| `duration` optional | `string` | Only videos of this length, by YouTube's Duration filter: short is under 3 minutes, medium 3 to 20, long over 20. Returns no shorts or streams, so not with kind short or live.<br>One of `short`, `medium`, `long` | `long` |
| `author` optional | `string`<br>max 512 chars | Only this channel's videos, as its Search tab finds them: a handle, any channel link or a UC… channel ID. Not with kind, duration or sort=popular: a channel's search has its own order, no filters. | `@NASA` |
| `sort` optional | `string`<br>default `relevance` | Order of the results. relevance: YouTube's best match. popular: its Popularity ranking, roughly most viewed first.<br>One of `relevance`, `popular` | — |
| `since` optional | `string`<br>date-time | Only items at or after this time: RFC 3339 (2026-10-01T12:00:00Z) or a date (2026-10-01, midnight UTC). A newest-first list stops there, so older pages aren't fetched or charged; a list in another order filters each page. Keeps streams on air and results whose upload label overlaps the window. A since in the past year also sets YouTube's Upload date filter, so fewer pages are fetched. | `2026-10-01` |
| `until` optional | `string`<br>date-time | Only items before this time (exclusive): RFC 3339 or a date (midnight UTC). | `2026-10-08` |
| `limit` optional | `integer`<br>min 1<br>max 30 | Items per page, up to the endpoint's page size (the default; larger values are reduced to it). Every page costs the same, so a smaller limit makes a walk cost more. | `30` |
| `cursor` optional | `string` | page.next_cursor from the previous response, with the other parameters unchanged. Omit for the first page. | — |

Every endpoint also accepts [`max_age`](https://socialtap.dev/docs/reference/index.md#common-params), [`max_credits`](https://socialtap.dev/docs/reference/index.md#common-params) and [`fields`](https://socialtap.dev/docs/reference/index.md#common-params).

## Response

`{data, page, meta}`: `data` is an array of [post](https://socialtap.dev/resources/post/index.md) objects, `page` says how to get the next page. Fields only YouTube has are under `platform_specific.youtube`. [`meta`](https://socialtap.dev/docs/reference/index.md#meta) describes the request.

| Field | Type | Description |
| --- | --- | --- |
| `data[].id` | `string` | Platform-native post ID (string; Instagram shortcode, Reddit with its t3_ prefix). |
| `data[].url` | `string` (uri) | Canonical post URL. |
| `data[].type` | `string` | Normalized content shape. New values may be added; treat unknown values as other.<br>One of `video`, `image`, `carousel`, `text`, `link`, `audio` |
| `data[].platform_type` | `string` or `null` | The platform's own product label, lowercase (reel, short, story, live, tweet, …). |
| `data[].title` | `string` or `null` | Headline (YouTube title, Reddit title); null on caption-only platforms. |
| `data[].text` | `string` or `null` | Caption, description or body as plain text. |
| `data[].link_url` | `string` (uri) or `null` | The page the post links to: a link post's target, a pin's destination, or the page its link card or link sticker opens; null when it links to none. |
| `data[].language` | `string` or `null` | BCP-47 language of text, when the platform states it. |
| `data[].published_at` | `string` (date-time) or `null` | When the post went public, RFC 3339 UTC. |
| `data[].author` | `object` | The posting account. For a deleted account, or a credit that is no account (a radio show), id and username are null and display_name is the platform's label or name. |
| `data[].author.id` | `string` or `null` | Platform-native account ID; null when only the handle is known. |
| `data[].author.username` | `string` or `null` | Handle without the @; null when the account has none. |
| `data[].author.display_name` | `string` or `null` | Display name shown on the profile. |
| `data[].author.url` | `string` (uri) or `null` | Canonical profile URL. |
| `data[].author.avatar_url` | `string` (uri) or `null` | Profile picture URL. Platform CDN URLs can expire within hours. |
| `data[].author.is_verified` | `boolean` or `null` | Platform verification badge; null where the platform has no badge. |
| `data[].coauthors` | `object[]` | Other accounts credited as co-authors of the post (Instagram and Facebook collabs, YouTube collaborations), in the platform's order, author excluded; \[\] if none. |
| `data[].coauthors[].id` | `string` or `null` | Platform-native account ID; null when only the handle is known. |
| `data[].coauthors[].username` | `string` or `null` | Handle without the @; null when the account has none. |
| `data[].coauthors[].display_name` | `string` or `null` | Display name shown on the profile. |
| `data[].coauthors[].url` | `string` (uri) or `null` | Canonical profile URL. |
| `data[].coauthors[].avatar_url` | `string` (uri) or `null` | Profile picture URL. Platform CDN URLs can expire within hours. |
| `data[].coauthors[].is_verified` | `boolean` or `null` | Platform verification badge; null where the platform has no badge. |
| `data[].duration_ms` | `integer` or `null` | Length of the primary video or audio in milliseconds; null for other posts. |
| `data[].thumbnail_url` | `string` (uri) or `null` | Cover or poster image URL. |
| `data[].media` | `object[]` | Attachments in display order (carousel items); \[\] for text posts. |
| `data[].media[].type` | `string` | Kind of file. New values may be added; treat unknown values as other.<br>One of `image`, `video`, `audio`, `gif` |
| `data[].media[].url` | `string` (uri) or `null` | Direct file URL; null when the platform withholds it, or when the link would only work from SocialTap's network or with a login. Often signed and expiring: see expires_at. |
| `data[].media[].expires_at` | `string` (date-time) or `null` | When url stops working, RFC 3339 UTC, read from the platform's signed URL; null when unknown or when it does not expire. |
| `data[].media[].thumbnail_url` | `string` (uri) or `null` | Poster or preview image URL. |
| `data[].media[].width` | `integer` or `null` | Width in pixels. |
| `data[].media[].height` | `integer` or `null` | Height in pixels. |
| `data[].media[].duration_ms` | `integer` or `null` | Duration in milliseconds (video and audio only). |
| `data[].media[].alt_text` | `string` or `null` | Accessibility text provided by the author or platform. |
| `data[].hashtags` | `string[]` | Hashtags without #, case kept; \[\] if none. |
| `data[].mentions` | `string[]` | Mentioned or tagged usernames without @; \[\] if none. |
| `data[].is_pinned` | `boolean` or `null` | Pinned to the author's profile. |
| `data[].is_sponsored` | `boolean` or `null` | Labeled as a paid partnership or branded content. |
| `data[].is_nsfw` | `boolean` or `null` | Marked adult or sensitive by the platform. |
| `data[].metrics` | `object` | Counts at fetch time; null = not shown, 0 = zero. |
| `data[].metrics.view_count` | `integer` or `null` | Views or plays. |
| `data[].metrics.like_count` | `integer` or `null` | Likes, hearts, total reactions or upvotes; never negative. Null when hidden by the owner. |
| `data[].metrics.comment_count` | `integer` or `null` | Comments and replies. |
| `data[].metrics.share_count` | `integer` or `null` | Shares or sends (not reposts). |
| `data[].metrics.repost_count` | `integer` or `null` | Reposts, retweets or reshares. |
| `data[].metrics.quote_count` | `integer` or `null` | Quote posts. |
| `data[].metrics.save_count` | `integer` or `null` | Saves, bookmarks or favorites. |
| `data[].platform_specific.youtube` | `object` or `null` | A YouTube video's own fields. |
| `data[].platform_specific.youtube.category` | `string` or `null` | YouTube category (Music, Gaming, …), in English. |
| `data[].platform_specific.youtube.keywords` | `string[]` | The uploader's tags; \[\] when none. |
| `data[].platform_specific.youtube.chapters` | `object[]` | Chapters in playback order; \[\] when none. |
| `data[].platform_specific.youtube.chapters[].title` | `string` or `null` | Chapter title. |
| `data[].platform_specific.youtube.chapters[].start_ms` | `integer` or `null` | Start, in ms from the beginning. |
| `data[].platform_specific.youtube.description_links` | `string[]` | Links in the description, in order, deduplicated; \[\] when none. |
| `data[].platform_specific.youtube.is_unlisted` | `boolean` or `null` | Unlisted: watchable by link, not listed on the channel or in search. |
| `data[].platform_specific.youtube.is_age_restricted` | `boolean` or `null` | Viewers must sign in to confirm their age; null when the answer does not tell. |
| `data[].platform_specific.youtube.is_paywalled` | `boolean` or `null` | Must be bought or rented (movies, paid content). |
| `data[].platform_specific.youtube.is_live_now` | `boolean` or `null` | A live stream on air now. |
| `data[].platform_specific.youtube.live_started_at` | `string` (date-time) or `null` | When a live stream or premiere went on air; null if never live. |
| `data[].platform_specific.youtube.live_ended_at` | `string` (date-time) or `null` | When a live stream or premiere ended; null while live or if never live. |
| `data[].platform_specific.youtube.scheduled_start_at` | `string` (date-time) or `null` | When a scheduled stream or premiere is due to start; null otherwise. |
| `data[].platform_specific.youtube.author_subscriber_count` | `integer` or `null` | The channel's subscriber count, rounded by YouTube (in approximate_fields); null when hidden. |
| `data[].approximate_fields` | `string[]` | JSON paths of values rounded by the platform or parsed from display text. A list path (external_links) means the list may be incomplete. \[\] when all exact. |
| `data[].unknown_fields` | `string[]` | JSON paths of lists whose \[\] means unknown, not none (a source that cannot see them). \[\] when every list is known. |

Besides [the errors any request can return](https://socialtap.dev/docs/errors/index.md): [`not_found`](https://socialtap.dev/docs/errors/index.md#not_found) (404) and [`private_or_unavailable`](https://socialtap.dev/docs/errors/index.md#private_or_unavailable) (403) when the item can't be returned; [`invalid_cursor`](https://socialtap.dev/docs/errors/index.md#invalid_cursor) (400).

## Pagination

Send the same request with `cursor` set to `page.next_cursor` until `page.has_more` is `false`. [Pagination](https://socialtap.dev/docs/pagination/index.md)

- **Order**: `sort=relevance` (the default): YouTube's relevance ranking (its search order); `sort=popular`: YouTube's Popularity ranking (roughly most viewed first)
- **Page size**: Up to 30 videos, shorts and live streams (the default; `limit` lowers it)
- **Cursor lifetime**: 1 hour

## Pricing

**1 credit** per successful page ($0.75–$1.97 per 1,000). Failed requests are free. [How credits work](https://socialtap.dev/docs/credits/index.md)

Endpoint ID `youtube.search_posts` · operationId `youtube.search_posts.list`

---

[HTML version](https://socialtap.dev/docs/reference/youtube/search-posts/) · [Docs index for AI agents](https://socialtap.dev/llms.txt) · [All docs in one file](https://socialtap.dev/llms-full.txt)
