# TikTok Top Search (`tiktok.search_top`)

Results of TikTok's "Top" search tab for a keyword: videos and photo carousels with captions and engagement counts.

Docs: https://primaryapi.com/docs/api-reference/tiktok/search_top

- Endpoint: `POST https://api.primaryapi.com/v1/run/tiktok.search_top`
- Category: Social · Platform: `tiktok` · Kind: search · Status: live
- Price: 2 credits per call; up to 3 credits if a call is retried elsewhere. A quote’s `maxCredits` is the most a given call can cost.
- 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=tiktok.search_top`
- Execution: synchronous (answers 202 only if it outlives the wait window)

## Input

| Field | Type | Required | Default | Constraints | Description |
|---|---|---|---|---|---|
| `query` | string | yes |  | max 500 chars | Keyword to search TikTok's "Top" tab for. |
| `publishTime` | enum | no | "all-time" |  | Only posts published within this window: all-time, yesterday, this-week, this-month, last-3-months or last-6-months. |
| `sortBy` | enum | no | "relevance" | one of: relevance, most-liked, date-posted | Sort order: relevance, most-liked or date-posted. |
| `region` | string | no |  | pattern: ^[A-Za-z]{2}$ | Two-letter country code the search runs from, e.g. "US" or "GB" (biases results; it is not a strict filter). |
| `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 |
|---|---|---|
| `items` | object[] |  |
| `items[].id` | string | TikTok post id (aweme_id). |
| `items[].url` | string \| null | Canonical web URL of the post. |
| `items[].caption` | string \| null |  |
| `items[].createdUtc` | string \| null | Creation time, ISO-8601 UTC. |
| `items[].durationSeconds` | number \| null |  |
| `items[].hashtags` | string[] | Hashtags without the leading #. |
| `items[].mentions` | string[] | Handles @-mentioned in the caption, without @, when the source provides them. |
| `items[].image` | string \| null | Cover image URL (signed CDN link, expires). |
| `items[].likes` | integer \| null |  |
| `items[].comments` | integer \| null |  |
| `items[].shares` | integer \| null |  |
| `items[].saves` | integer \| null |  |
| `items[].views` | integer \| null |  |
| `items[].author` | string \| null | Creator handle (same value as authorHandle). |
| `items[].authorHandle` | string \| null |  |
| `items[].authorName` | string \| null |  |
| `items[].authorUserId` | string \| null |  |
| `items[].authorSecUid` | string \| null |  |
| `items[].authorImage` | string \| null |  |
| `items[].authorVerified` | boolean \| null |  |
| `items[].authorFollowers` | integer \| null | Creator follower count when the source provides it. |
| `items[].soundTitle` | string \| null |  |
| `items[].soundAuthor` | string \| null |  |
| `items[].soundClipId` | string \| null |  |
| `items[].videoUrl` | string \| null | Playable MP4 URL (signed CDN link, expires). |
| `items[].region` | string \| null |  |
| `items[].locationName` | string \| null |  |
| `items[].isPinned` | boolean \| null |  |
| `items[].paidPartnership` | boolean \| null |  |
| `items[].contentType` | enum | video, or photo for photo-mode (slideshow) posts. |
| `items[].images` | string[] | Image URLs of a photo-mode post, in order (empty for videos). |
| `hasMore` | boolean \| null | True when nextCursor can fetch another page; null when the serving source cannot tell. |
| `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/tiktok.search_top" \
  -H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"dogs"}'
```

## 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": {
      "items": [
        {
          "id": "string",
          "url": "https://example.com",
          "caption": "string",
          "createdUtc": "string",
          "durationSeconds": 0,
          "hashtags": [
            "string"
          ],
          "mentions": [
            "string"
          ],
          "image": "string",
          "likes": 0,
          "comments": 0,
          "shares": 0,
          "saves": 0,
          "views": 0,
          "author": "string",
          "authorHandle": "string",
          "authorName": "string",
          "authorUserId": "string",
          "authorSecUid": "string",
          "authorImage": "string",
          "authorVerified": true,
          "authorFollowers": 0,
          "soundTitle": "string",
          "soundAuthor": "string",
          "soundClipId": "string",
          "videoUrl": "https://example.com",
          "region": "string",
          "locationName": "string",
          "isPinned": true,
          "paidPartnership": true,
          "contentType": "video",
          "images": [
            "string"
          ]
        }
      ],
      "hasMore": true,
      "nextCursor": null
    }
  },
  "provider": "PrimaryAPI",
  "credits": 2,
  "items": 1,
  "requestId": "req_01JBXK6Y2N9V8T4R3Q2P1M0A7Z",
  "nextCursor": null
}
```

## Pricing and reliability

- Usual price: 2 credits per call
- Price ceiling: up to 3 credits if a call is retried elsewhere. 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=tiktok.search_top`

## 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

Flat price per page. Only post cards are returned (user/sound/hashtag cards of the mixed tab are dropped). Pass nextCursor to continue; a cursor only resumes on the source that issued it. Zero hits return found=false (no_results).

