> **For coding agents and LLMs:** This is one page from the Social Fetch docs (markdown export). For curated orientation and workflow guidance, start with [`/llms.txt`](https://www.socialfetch.dev/llms.txt); for agent onboarding and crawl rules, use [`/agents.txt`](https://www.socialfetch.dev/agents.txt); for the full endpoint list with links to pages like this one, use [`/llms-endpoints.txt`](https://www.socialfetch.dev/llms-endpoints.txt); for one platform's parameters and curls, use [`/llms-{platform}.txt`](https://www.socialfetch.dev/llms-tiktok.txt); use [`/llms.json`](https://www.socialfetch.dev/llms.json) when you need structured JSON for tool registration.

## This page

- **On-site (HTML):** [https://www.socialfetch.dev/docs/api/v1/tiktok/search/top/get](https://www.socialfetch.dev/docs/api/v1/tiktok/search/top/get)
- **Markdown (.mdx) URL:** [https://www.socialfetch.dev/docs/api/v1/tiktok/search/top/get.mdx](https://www.socialfetch.dev/docs/api/v1/tiktok/search/top/get.mdx)

## API base URL and authentication

- **API origin (from OpenAPI `servers`):** `https://api.socialfetch.dev`
- **Authentication:** send `x-api-key: sfk_...` on `/v1/**` routes unless the operation is explicitly anonymous (check OpenAPI `security`, the [API reference hub](https://www.socialfetch.dev/docs/api.mdx), [`/llms.txt`](https://www.socialfetch.dev/llms.txt), or [`/llms.json`](https://www.socialfetch.dev/llms.json) for each route).
- **OpenAPI JSON:** [https://www.socialfetch.dev/openapi.json](https://www.socialfetch.dev/openapi.json)

## Recommended docs entrypoints (this site)

- [Documentation overview](https://www.socialfetch.dev/docs.mdx) — top-level orientation (markdown).
- [Quickstart](https://www.socialfetch.dev/docs/quickstart.mdx) — authenticate with `x-api-key`, validate auth with `whoami`, and understand the JSON envelope.
- [SDK](https://www.socialfetch.dev/docs/sdk.mdx) — official TypeScript SDK guide, including `SocialFetchClient`, `Result`, and `unwrap()`.
- [Capability matrix](https://www.socialfetch.dev/docs/capability-matrix.mdx) — every operation with identifiers, pagination, outcomes, media download, credits, and its SDK method. Generated from OpenAPI, so use it for route selection instead of scanning individual pages.
- [Recipes](https://www.socialfetch.dev/docs/recipes.mdx) — copyable workflows (brand monitoring, transcripts, Ad Library, creator scoring, Reddit research) with credit callouts and SDK examples.
- [Integrations](https://www.socialfetch.dev/docs/integrations.mdx) — MCP for AI clients, n8n verified node, Apify Store Actors, Make custom app, SDK, and REST API connection paths.
- [MCP product page](https://www.socialfetch.dev/mcp) — hosted MCP overview, OAuth, Skills install.
- [MCP integration](https://www.socialfetch.dev/docs/integrations/mcp.mdx) — hosted `/mcp` server, OAuth, Cursor/VS Code/Claude install snippets, 184 endpoint tools, plus docs_search/docs_read for implementation help.
- [n8n integration](https://www.socialfetch.dev/docs/integrations/n8n.mdx) — install `n8n-nodes-socialfetch`, credentials, and workflow examples.
- [Apify integration](https://www.socialfetch.dev/docs/integrations/apify.mdx) — Store Actors under @social-fetch, PPE billing, dataset export, and quick start.
- [Make integration](https://www.socialfetch.dev/docs/integrations/make.mdx) — custom app modules for Make scenarios, API key credentials, and module catalog.
- [`/llms-endpoints.txt`](https://www.socialfetch.dev/llms-endpoints.txt) — every documented operation with a direct link to that route's agent-readable markdown page (prefer this over parsing OpenAPI).
- [`/llms-{platform}.txt`](https://www.socialfetch.dev/llms-tiktok.txt) — per-platform endpoint files generated from OpenAPI (parameters, credits, curls).
- [`/agents.txt`](https://www.socialfetch.dev/agents.txt) — agent crawl/onboarding file with capabilities, auth rules, and allowlist.
- [`/llms.json`](https://www.socialfetch.dev/llms.json) — structured machine-readable operation inventory with parameter names, pagination, outcomes, credits, and SDK mapping.
- [API reference hub](https://www.socialfetch.dev/docs/api.mdx) — human-friendly index of operations with links into generated pages.
- [Errors](https://www.socialfetch.dev/docs/errors.mdx) — shared error envelope and HTTP status guidance.
- [Credits](https://www.socialfetch.dev/docs/credits.mdx) — metering, `402`, and planning batch jobs.
- Outcome semantics such as `found`, `not_found`, and `private` are documented in [Errors](https://www.socialfetch.dev/docs/errors.mdx) and on operation pages when present in the OpenAPI contract.

## Markdown docs convention

- Every docs page has a markdown twin: append **`.mdx`** to the docs pathname (for example `/docs/quickstart` → `/docs/quickstart.mdx`).
- Agents that send `Accept: text/markdown` on `/docs/**` HTML URLs may receive markdown directly (same URL, `Vary: Accept`).

---
# Search TikTok Top results (https://www.socialfetch.dev/docs/api/v1/tiktok/search/top/get)

## Summary

Search TikTok Top results by keyword (not videos-only — use tiktok.search.videos.list for that).

**Tags:** `TikTok`

## HTTP

- **Method:** GET
- **Path:** `/v1/tiktok/search/top`
- **Base URL:** `https://api.socialfetch.dev`

## Capability summary

- **SDK mapping:** `client.tiktok.searchTop({ query, datePosted?, sortBy?, region?, cursor? })`
- **Accepted identifiers:** `query` (query)
- **Pagination:** cursor via `cursor`, next cursor: `data.page.nextCursor`, has more: `data.page.hasMore`
- **Ordering / list behavior:** Supported sort options: relevance, most-liked, date-posted.

## Agent notes

- **Disambiguation:** TikTok Top search returns videos and photo carousels. Use GET /v1/tiktok/search for videos-only keyword search, or GET /v1/tiktok/search/hashtags for hashtag search.

## Credits

- **Base:** 1 credit per successful lookup.
- **Maximum on success (200):** 1 credit.
- **Normalization failure (502):** 1 credit charged.
- **Authoritative field:** `meta.creditsCharged`.

## Authentication

- **`x-api-key`**: API key (`sfk_...`)

## Parameters

### `query` (query)

- **Required:** yes
- **Constraints:** type `string`; minLength: 1; maxLength: 512
- **Description:** Search query text for TikTok Top results.

### `datePosted` (query)

- **Required:** no
- **Constraints:** type `string`; enum: yesterday, this-week, this-month, last-3-months, last-6-months, all-time
- **Description:** Optional upload date filter for video results.

### `sortBy` (query)

- **Required:** no
- **Constraints:** type `string`; enum: relevance, most-liked, date-posted
- **Description:** Optional sort order for search results.

### `region` (query)

- **Required:** no
- **Constraints:** type `string`
- **Description:** Optional two-letter ISO 3166-1 country code for localized search results.

### `cursor` (query)

- **Required:** no
- **Constraints:** type `string`; minLength: 1
- **Description:** Opaque pagination cursor returned by a previous response.

## Behavior notes

- **`sortBy`**: Optional sort order for search results.
- **`region`**: Optional two-letter ISO 3166-1 country code for localized search results.

## Pagination

This endpoint uses **cursor-based pagination** via the `cursor` query parameter.

- Read **hasMore** from `data.page.hasMore`.
- When that value is `true`, read **nextCursor** from `data.page.nextCursor` and pass it as the `cursor` query parameter on the **next** request (URL-encode when building a query string).
- Omit `cursor` on the **first** request.
- Stop when **hasMore** is `false` or **nextCursor** is null (end of list).

## Responses (status codes)

- **200**: Top search results for the requested query.
- **400**: Invalid query parameters
- **401**: Missing or invalid API key
- **402**: Insufficient credits
- **500**: Unexpected or billing error
- **502**: Lookup could not be completed from the response (unexpected or invalid data).
- **503**: Service temporarily unavailable; safe to retry with backoff.

## Response body (200)

Top search results for the requested query.

### Field outline

- **data** (required) — type `object`. Endpoint-specific response payload.
  - **query** (required) — type `string`. Search query that was evaluated for this response.
  - **items** (required) — type `array`. Matching TikTok posts (videos and photo slideshows).
    - _items:_
      - **id** (required) — type `string`; minLength: 1. TikTok post identifier.
      - **caption** (required) — type `string`; nullable. Caption text shown for the post.
      - **createdAt** (required) — type `string`; nullable. When the post was created (ISO-8601).
      - **url** (required) — type `string`; nullable. Canonical public TikTok URL for the post.
      - **thumbnailUrl** (required) — type `string`; nullable. Thumbnail or cover image URL when available.
      - **durationMs** (required) — type `integer`; minimum: 0; nullable. Duration in milliseconds when available.
      - **mediaType** (required) — type `string`; enum: video, slideshow. Whether the post is a video or a photo slideshow.
      - **pinned** (required) — type `boolean`. Whether TikTok marks the post as pinned in this result set.
      - **isAd** (required) — type `boolean`. Whether TikTok marks the post as an ad.
      - **stats** (required) — type `object`. Engagement metrics for the post.
        - **views** (required) — type `integer`; minimum: 0. View count reported by TikTok for the video.
        - **likes** (required) — type `integer`; minimum: 0. Like count reported by TikTok for the video.
        - **comments** (required) — type `integer`; minimum: 0. Comment count reported by TikTok for the video.
        - **shares** (required) — type `integer`; minimum: 0. Share count reported by TikTok for the video.
        - **saves** (required) — type `integer`; minimum: 0. Save or collection count reported by TikTok for the video.
      - **media** (required) — type `object`. Media URLs for the post.
        - **downloadUrl** (required) — type `string`; nullable. Downloadable video URL when available.
        - **downloadWithoutWatermarkUrl** (required) — type `string`; nullable. Download URL without watermark when available.
        - **slideshowImages** (required) — type `array`. Ordered image URLs for photo slideshow posts. Empty for videos.
          - _items:_
            - type `string`
      - **author** (required) — type `object`. Author metadata for this Top search result.
        - **id** (required) — type `string`; nullable. TikTok user id for the author when available.
        - **handle** (required) — type `string`; nullable. TikTok handle for the author when available.
        - **displayName** (required) — type `string`; nullable. Display name for the author when available.
        - **avatarUrl** (required) — type `string`; nullable. Avatar image URL for the author when available.
        - **verified** (required) — type `boolean`. Whether the author is verified on TikTok.
      - **details** (optional) — type `object`. Additional TikTok-native fields for this post.
  - **page** (required) — type `object`. Pagination state for the current Top search page.
    - **hasMore** (required) — type `boolean`. Whether another page is available.
    - **nextCursor** (required) — type `string`; nullable. Cursor to pass in the next request when more pages exist; null on the last page.
- **meta** (required) — type `object`. Metadata describing the request and billing outcome.
  - **requestId** (required) — type `string`; minLength: 1. Unique request identifier for tracing this API call.
  - **creditsCharged** (required) — type `integer`; minimum: 0. Credits charged for this request.
  - **version** (required) — type `string`; enum: v1. Public API version that served the response.
  - **cached** (optional) — type `boolean`. True when served from shared response cache. Credits still apply (full endpoint price); Age header may be present.

### Example JSON (sample)

```json
{
  "data": {
    "query": "funny",
    "items": [
      {
        "id": "7677001872506588418",
        "caption": "this is so true #funny #cool #backtoit #oldtimes",
        "createdAt": "2026-08-22T23:28:19.000Z",
        "url": "https://www.tiktok.com/@fabflaps.romano9741/video/7677001872506588418",
        "thumbnailUrl": "https://p16-common-sign.tiktokcdn-us.com/tos-no1a-p-0037-no/owiTILALIIfLijBAeLIFwCQG72MhGeFDIJEVpK~tplv-x7g4mazu7z-crop-80-heic:500:800.heic?biz_tag=musically_general.video_cover&dr=9616&ftpl=1&idc=useast5&ps=13740610&refresh_token=ff8a0e71&shcp=c1333099&shp=0e6dc556&t=4d5b0474&x-expires=1787533200&x-signature=K2NcC7q…",
        "durationMs": 6154,
        "mediaType": "video",
        "pinned": false,
        "isAd": false,
        "stats": {
          "views": 10193130,
          "likes": 2141043,
          "comments": 7709,
          "shares": 295047,
          "saves": 135980
        },
        "media": {
          "downloadUrl": "https://v19.tiktokcdn-us.com/514c58223b5daabcd4fd87d1a7ca6273/6a8b9f94/video/tos/no1a/tos-no1a-ve-0068c001-no/ooFUuqjBfEBEErFRIYECZyAkxMgfbQlKFWiIJD/?a=1233&bti=NEBzbmQxZmR2bndsQGo6OjZALnAjYG1lb2IrbGhxYCMxNDNg&&bt=226&eid=5376&ft=gKfIn8s6oA-O12NvD2h.zIxR3Qx0~3_45SY&mime_type=video_mp4&rc=OWY0NGQ5OGg7Omk8NzppZkBpanI3b2…",
          "downloadWithoutWatermarkUrl": "https://v19.tiktokcdn-us.com/4fac67f5f667c1a439e48c1bef909f20/6a8b9f94/video/tos/no1a/tos-no1a-ve-0068c001-no/oQhgUYMQAfBEjlkqRNbBFExLJEE3ICFKMuUifD/?a=1233&bti=NEBzbmQxZmR2bndsQGo6OjZALnAjYG1lb2IrbGhxYCMxNDNg&&bt=192&ft=gKfIn8s6oA-O12NvD2h.zIxR3Qx0~3_45SY&mime_type=video_mp4&rc=MzxoMzo7OjM8NTo1NDZlaEBpanI3b2w5cm42ZDM…",
          "slideshowImages": []
        },
        "author": {
          "id": "7665742042623263766",
          "handle": "fabflaps.romano9741",
          "displayName": "user15062103140",
          "avatarUrl": "https://p16-common-sign.tiktokcdn-us.com/tos-maliva-avt-0068/1172ac28731053147f64d3b7ff636f61~tplv-tiktokx-cropcenter-q:100:100:q70.heic?biz_tag=musically_general.video_user_cover&dr=8835&idc=useast5&ps=87d6e48a&refresh_token=65892c32&s=SEARCH&sc=avatar&shcp=0e6dc556&shp=d05b14bd&t=223449c4&x-expires=1787598000&x-sign…",
          "verified": false
        },
        "details": {
          "desc_language": "en",
          "region": "GB",
          "music": {
            "author": "andi opi",
            "duration": 14,
            "id": 7642755575378103000,
            "title": "original sound - andi.opi5",
            "play_url": "https://v19.tiktokcdn-us.com/fcc232da2a272519a9666743f90a0735/6a948606/video/tos/alisg/tos-alisg-v-27dcd7/o0agvZhzC0WUI2QqJw6BBQ1YbEY1QHFQe4FEfD/?a=1233&bti=NEBzbmQxZmR2bndsQGo6OjZALnAjYG1lb2IrbGhxYCMxNDNg&&bt=125&ft=gKfIn8s6oA-O12NvD2h.zIxR3Qx0~3_45SY&mime_type=audio_mpeg&rc=MzY6aDQ1PDUzOzRkZGRpaUBpamZkOHU5cmY7OzMzOD…",
            "matched_song": {
              "author": "Virality",
              "id": "7660833800806057985",
              "title": "Jumperviolin"
            }
          },
          "is_eligible_for_commission": false,
          "is_paid_partnership": false,
          "shop_product_url": null
        }
      }
    ],
    "page": {
      "hasMore": true,
      "nextCursor": "eyJjIjoiMzAifQ"
    }
  },
  "meta": {
    "requestId": "req_1ba4fdb8-7566-4b53-9aab-cc9110e532d9",
    "creditsCharged": 1,
    "version": "v1"
  }
}
```

### Machine-readable error codes

When an error JSON body is returned, it may include one of these `error.code` values (derived from the OpenAPI schemas for this operation; additional codes may exist at runtime):

- `bad_request`

## Error handling & retries

Interpret HTTP status codes using the descriptions below. Do not assume a JSON body unless the OpenAPI schema defines one for that status.

- **400**: Invalid query parameters **Retry:** Fix the request; retrying the same invalid payload will not help.
- **401**: Missing or invalid API key **Retry:** Fix the API key first; retrying without changes will not help.
- **402**: Insufficient credits **Retry:** Do not retry without resolving billing/credits (retrying the same request will not help).
- **500**: Unexpected or billing error
- **502**: Lookup could not be completed from the response (unexpected or invalid data). **Retry:** May be transient; a few retries with backoff are reasonable.
- **503**: Service temporarily unavailable; safe to retry with backoff. **Retry:** Usually safe to retry with exponential backoff and jitter.

### Suggested client defaults

- Send the API key using the `x-api-key` header on every request.
- On `503` (and sometimes `502`), retry with backoff; cap retries and surface a clear error to the user.
- On `402`, surface an actionable billing message rather than blind retries.

## Examples

### TypeScript SDK

```typescript
import { SocialFetchClient } from "@socialfetch/sdk";

const client = new SocialFetchClient({
  apiKey: process.env.SOCIALFETCH_API_KEY!,
});

const result = await client.tiktok.searchTop({
  query: "funny",
});

if (!result.ok) {
  console.error(result.error);
} else {
  console.log(result.value.data);
}
```

### Node.js

```javascript
const response = await fetch(
  "https://api.socialfetch.dev/v1/tiktok/search/top?query=funny",
  {
    headers: {
      "x-api-key": "YOUR_API_KEY"
    }
  }
);

const data = await response.json();
console.log(data);
```

### cURL

```bash
curl "https://api.socialfetch.dev/v1/tiktok/search/top?query=funny" \
  -H "x-api-key: YOUR_API_KEY"
```

### Python

```python
import requests

response = requests.get(
    "https://api.socialfetch.dev/v1/tiktok/search/top?query=funny",
    headers={"x-api-key": "YOUR_API_KEY"},
)
data = response.json()
print(data)
```

### Example: optional query parameters

First request illustrating common optional query flags (adjust values to your integration):

```javascript
const url = "https://api.socialfetch.dev/v1/tiktok/search/top?sortBy=relevance";
const response = await fetch(url, {
  headers: { "x-api-key": "YOUR_API_KEY" },
});
const data = await response.json();
```

### Example: next page (pagination)

After a successful response, if pagination is not finished, request the next page using `cursor` (URL-encode when composing the query string):

```javascript
const previous = await response.json();
const nextCursor = previous?.data?.page?.nextCursor;
const hasMore = previous?.data?.page?.hasMore;
if (!hasMore || nextCursor == null) {
  // no more pages
} else {
  const nextUrl = new URL("https://api.socialfetch.dev/v1/tiktok/search/top");
  nextUrl.searchParams.set("cursor", nextCursor);
  // optionally preserve sort: nextUrl.searchParams.set("sortBy", "latest");
  const nextResponse = await fetch(nextUrl.toString(), {
    headers: { "x-api-key": "YOUR_API_KEY" },
  });
  const nextData = await nextResponse.json();
}
```