# YouTube Hashtag Search (`youtube.search_hashtag`)

Videos tagged with a YouTube hashtag (title, channel, views, length, publish time), with cursor pagination.

Docs: https://primaryapi.com/docs/api-reference/youtube/search_hashtag

- Endpoint: `POST https://api.primaryapi.com/v1/run/youtube.search_hashtag`
- Category: Social · Platform: `youtube` · Kind: search · Status: live
- Price: 2 credits per call. Every call costs the same, including calls that were retried automatically.
- Billing unit: per successful call
- Reliability: routed to a healthy upstream and retried automatically when an attempt fails; live 30-day status: `GET https://api.primaryapi.com/v1/status/apis?sku=youtube.search_hashtag`
- Execution: synchronous (answers 202 only if it outlives the wait window)

## Input

| Field | Type | Required | Default | Constraints | Description |
|---|---|---|---|---|---|
| `hashtag` | string | yes |  | max 100 chars; pattern: ^#*[\p{L}\p{M}\p{N}_]+$ | Hashtag to search for, with or without the leading #. |
| `type` | enum | no | "all" | one of: all, shorts | Content filter: all (default) or shorts only. |
| `limit` | integer | no | 20 | 1–50 | Maximum number of results to return (1-50, default 20). |
| `cursor` | string | no |  |  | Opaque pagination cursor: pass the previous response's nextCursor. |

Unknown fields are rejected with `400 invalid_input`. The routing controls `preferLatencyUnderMs` and `maxCredits` may be sent in the same JSON body.

## Output

When `output.found` is `true`, `output.data` has this shape:

| Field | Type | Description |
|---|---|---|
| `videos` | object[] |  |
| `videos[].id` | string | 11-character video ID |
| `videos[].url` | string | Watch URL |
| `videos[].title` | string \| null |  |
| `videos[].image` | string \| null | Thumbnail URL |
| `videos[].views` | integer \| null |  |
| `videos[].lengthText` | string \| null | Duration label as YouTube shows it, e.g. "4:14" |
| `videos[].durationSeconds` | integer \| null |  |
| `videos[].publishedTime` | string \| null | Relative publish label, e.g. "2 years ago" |
| `videos[].createdUtc` | string \| null | Publish time, ISO 8601 (best effort; null when the source only gives a relative label) |
| `videos[].channel` | string \| null | Channel title |
| `videos[].channelTitle` | string \| null | Channel title (same value as channel; AnyAPI hashtag-search naming) |
| `videos[].authorId` | string \| null | Channel ID (UC…) |
| `videos[].authorHandle` | string \| null | Channel handle without @ |
| `videos[].authorAvatarUrl` | string \| null |  |
| `nextCursor` | string \| null |  |

When the thing you asked about does not exist (or a search matches nothing) the call still succeeds: `output.found` is `false`, `output.data` is `null` and `output.reason` says why (`not_found`, `private`, `no_results`, …). Misses are free unless the notes below say misses are billed.

Pagination: pass the previous response’s `nextCursor` as `cursor` to get the next page; `nextCursor: null` means there are no more results.

## Example request

```bash
curl -sS -X POST "https://api.primaryapi.com/v1/run/youtube.search_hashtag" \
  -H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"hashtag":"shorts"}'
```

## Example response

_Values are placeholders that follow the output schema; `credits` is what this call would cost at the usual price._

```json
{
  "output": {
    "found": true,
    "data": {
      "videos": [
        {
          "id": "jXMISgQq9MM",
          "url": "https://www.youtube.com/watch?v=jXMISgQq9MM",
          "title": "Epic fails 🤣🤣🤣 #shorts #funny #fails",
          "image": "https://i.ytimg.com/vi/jXMISgQq9MM/hqdefault.jpg",
          "views": 22668056,
          "lengthText": "1:00",
          "durationSeconds": 60,
          "publishedTime": "4 weeks ago",
          "createdUtc": "2025-01-04T23:12:42.919Z",
          "channel": "ZZang Funny",
          "channelTitle": "ZZang Funny",
          "authorId": "UCvUzWu1Whyw1FWuLl9GOo_g",
          "authorHandle": null,
          "authorAvatarUrl": "https://yt3.ggpht.com/rcZKcfewHTzkauGknat3NeC53rGBofYDbL8AjFkwvsk2fXzM1clht7OTn9-1IIPnmbeZkrNGdxI=s68-c-k-c0x00ffffff-no-rj"
        }
      ],
      "nextCursor": "eyJsIjoieW91dHViZS5zZWFyY2hfaGFzaHRhZyNzY3JhcGVjcmVhdG9ycyIsInQiOiI0cW1Gc2dMdEJSSUpSa1ZvWVguLi4uIn0"
    }
  },
  "provider": "PrimaryAPI",
  "credits": 2,
  "items": 1,
  "requestId": "req_01JBXK6Y2N9V8T4R3Q2P1M0A7Z",
  "nextCursor": null
}
```

## Pricing and reliability

- Usual price: 2 credits per call
- Price ceiling: the usual price, even when a call is retried. A quote’s `maxCredits` is the most a given call can cost; the `maxCredits` routing control caps it per call
- Live 30-day status, success rate, uptime and latency: `GET https://api.primaryapi.com/v1/status/apis?sku=youtube.search_hashtag`

## Errors to handle

`invalid_input`, `unauthorized`, `insufficient_balance`, `key_limit_reached`, `trial_cap_reached`, `forbidden`, `not_found`, `idempotency_conflict`, `rate_limited`, `all_sources_failed`, `service_unavailable`, `timeout`. See https://primaryapi.com/docs/errors.

## Notes

Fallback: delegate to youtube.search with query "#tag", which approximates the hashtag page (YouTube ranks the two differently) and serves type=all only.

