# TikTok Search API

> Search TikTok by keyword for top videos, users, videos, photo posts, live streams or sounds, with an optional country, as JSON. 1 credit per page.

**Search TikTok by keyword** for videos, accounts, photo posts, live streams or sounds.

```
GET https://api.handlehaul.com/v1/tiktok/search?q=&type=
```

**Cost:** 1 credit per page (free from cache, kept 15 minutes).

## Parameters

| Parameter | In | Description |
|---|---|---|
| `q` | query | What to search for (1 to 100 characters). |
| `type` | query | `top` (default), `users`, `videos`, `photo`, `live` or `music`. |
| `region` | query | Optional 2-letter country code (default `US`). |
| `cursor` | query | `pagination.next_cursor` from the previous page (keep `q`, `type` and `region` the same). |
| `fresh` | query | `true` skips the cache. |
| `raw` | query | `true` returns TikTok's own JSON in `data`. |

What `data` holds depends on `type`:

| `type` | Items |
|---|---|
| `users` | accounts (the TikTok user shape, with follower and like counts) |
| `top` | the video results of TikTok's blended search (account cards are left out; use `users`) |
| `videos`, `photo` | posts (the TikTok post shape) |
| `live` | live streams: `id`, `title`, `viewer_count`, `cover_url`, `author` |
| `music` | sounds (the TikTok sound shape) |

## Response

```json
{
  "data": [
    {
      "id": "6800349351199050453",
      "sec_uid": "MS4wLjABAAAAFLh-SwKoll0vQk30vGxgf5v9-2wK5VmzQXOonFd1x0s",
      "handle": "kai_ivy71",
      "nickname": "Kai Ivy",
      "avatar_url": "https://p16-sign.tiktokcdn-us.com/…/avatar/6800349351199050453~c5_100x100.jpeg",
      "is_verified": false,
      "is_private": false,
      "url": "https://www.tiktok.com/@kai_ivy71",
      "counts": {
        "followers": 1000,
        "following": null,
        "likes": 20000,
        "videos": null
      }
    }
  ],
  "pagination": {
    "next_cursor": "eyJ2…sealed…",
    "has_more": true,
    "page_size": 10
  },
  "meta": {
    "request_id": "req_…",
    "cached": false,
    "cache_age_seconds": 0,
    "credits_charged": 1,
    "credits_remaining": 26943
  }
}
```

## Examples

```bash
curl "https://api.handlehaul.com/v1/tiktok/search?q=coffee&type=users" -H "X-Api-Key: $HANDLEHAUL_API_KEY"
```

```python
import os, requests
r = requests.get("https://api.handlehaul.com/v1/tiktok/search?q=coffee&type=users",
                 headers={"X-Api-Key": os.environ["HANDLEHAUL_API_KEY"]}, timeout=60)
r.raise_for_status()
for u in r.json()["data"]:
    print(u["handle"], u["nickname"])
```

```javascript
const res = await fetch("https://api.handlehaul.com/v1/tiktok/search?q=coffee&type=users", {
  headers: { "X-Api-Key": process.env.HANDLEHAUL_API_KEY },
});
const { data, meta } = await res.json();
```

```php
$ch = curl_init("https://api.handlehaul.com/v1/tiktok/search?q=coffee&type=users");
curl_setopt_array($ch, [
    CURLOPT_HTTPHEADER => ["X-Api-Key: " . getenv("HANDLEHAUL_API_KEY")],
    CURLOPT_RETURNTRANSFER => true,
]);
$body = json_decode(curl_exec($ch), true);
print_r($body["data"]);
```

```go
req, _ := http.NewRequest("GET", "https://api.handlehaul.com/v1/tiktok/search?q=coffee&type=users", nil)
req.Header.Set("X-Api-Key", os.Getenv("HANDLEHAUL_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
    log.Fatal(err)
}
defer res.Body.Close()
var body map[string]any
json.NewDecoder(res.Body).Decode(&body)
fmt.Println(body["data"])
```

## FAQ

### How do I find TikTok accounts by name?
Call `GET /v1/tiktok/search?q=<name>&type=users`. Each result has the `handle`, `id` and `sec_uid` to use with the other TikTok endpoints.
