Last updated
SDKs and samples
Official client libraries for TypeScript and JavaScript, Python and Go wrap the REST API with authentication, retries, pagination and typed errors. Samples in eight languages show common tasks end to end.
Install
The SDKs, the MCP server, the samples and the OpenAPI file live in one open repository, MKK-Platform/toktokdata-sdks. Each SDK follows semantic versioning; the API path /v1 only grows in compatible ways.
npm install @toktokdata.live/sdkFirst request
Create a key under Settings → API keys (see Authentication) and put it in the TOKTOKDATA_API_KEY environment variable. This reads the hourly board for Vietnam:
import { TokTokData } from "@toktokdata.live/sdk"; const client = new TokTokData({ apiKey: process.env.TOKTOKDATA_API_KEY }); const board = await client.rankings.official("hourly", { region: "VN", limit: 10 });console.log(board.data);Responses are the API’s JSON unchanged: reads return data and provenance, as described in the reference.
What the SDKs handle
| Feature | Behaviour |
|---|---|
| Authentication | Sends Authorization: Bearer <key>. The key comes from the constructor or from TOKTOKDATA_API_KEY; without one the client fails at construction. |
| Retries | Retries network errors, 429 and retryable 5xx answers up to twice, waiting for Retry-After when it is sent. Never retries 402, other 4xx or daily_quota_exceeded. |
| Fresh data | Waits on 202 “still collecting” answers and asks again until the data is ready, for up to 3 minutes. |
| Pagination | Iterators that follow nextCursor page by page. |
| Errors | One error type with status, code, message, requestId and retryable. |
| Rate limits | The X-RateLimit-* headers of the last response, to slow down before a 429. |
| Webhooks | A helper that checks the x-toktokdata-signature of an alert delivery. |
Resources
Methods are grouped by resource, with the same names in every language: camelCase in TypeScript, snake_case in Python, PascalCase in Go. Path parameters are positional; query parameters and bodies go in one options object (a params struct in Go).
| Namespace | Covers | Scope |
|---|---|---|
rankings | Official boards, regions, board history and daily bars. | rank:read |
creators | Search, profile, analysis, changes, followers, following, top gifters, insights and videos. | creator:read · gifter:read · content:read |
agencies | Agency directory and one agency. | creator:read |
insights | Best time to go LIVE and hourly LIVE presence per region. | creator:read |
videos | One video and its comments. | content:read |
trends | Regional trends. | trend:read |
gifts | Gift catalog. | live:read |
gifters | Top gifters by window, segment and region. | gifter:read |
live | LIVE sessions, timelines, comparisons, creator performance, refresh, playback and chat. | live:read · live:stream |
alerts | Alert rules, test deliveries, fires, deliveries and stats. | webhook:manage |
exports | Create, poll and download exports. | export |
account | Entitlements and usage of the workspace. | keys:manage |
Errors and retries
Every failed call raises one error type: TokTokDataError in TypeScript and Python, *APIError in Go. It carries the error envelope and the HTTP status. Retries already happened by the time you see it, so a retryable error here means the API kept failing.
import { TokTokDataError } from "@toktokdata.live/sdk"; try { await client.creators.get("room.one");} catch (err) { if (err instanceof TokTokDataError) { console.error(err.status, err.code, err.requestId, err.retryable); } throw err;}402 credit_cap_exceeded means the workspace spent its credits for the period. Retrying cannot help: top up or wait for the monthly allotment (see Credits).Waiting for fresh data
Creator profiles, followers, following, video comments and LIVE playback may answer 202 while fresh data is collected. The SDK methods for these routes sleep for the advised retryAfterSeconds and ask again until the data arrives, for up to 3 minutes, then raise a timeout error. A 202 costs no more than a cached read. Pass wait: false (Python wait=False) to get the 202 body back and poll yourself.
Pagination
Cursor lists (followers, following, LIVE sessions, LIVE performance, board history and video comments) accept cursor and limit and return data.nextCursor. Each SDK has an iterator that follows the cursor and yields whole pages until nextCursor is null; see Pagination.
Webhook signatures
verifyWebhook (Python verify_webhook, Go VerifyWebhook) takes the raw body, the headers and the channel’s whsec_… secret, checks the HMAC in constant time, rejects timestamps older than five minutes and returns the parsed payload. The format is described under Webhooks.
Samples
The examples/ folder of the repository has runnable samples. Each one reads the key from TOKTOKDATA_API_KEY.
| Folder | Language | Uses |
|---|---|---|
examples/curl | Shell | curl |
examples/typescript | TypeScript | @toktokdata.live/sdk |
examples/python | Python | toktokdata |
examples/go | Go | toktokdata-sdks/go |
examples/java | Java | Plain HTTP, standard library |
examples/csharp | C# | Plain HTTP, standard library |
examples/php | PHP | Plain HTTP, standard library |
examples/ruby | Ruby | Plain HTTP, standard library |
The samples cover these tasks:
- Leaderboard: print the top creators of an official board.
- Creator report: read a profile and wait while fresh data is collected (202).
- CSV export: create an export, wait until it is ready and download it.
- Webhook server: receive alert deliveries and verify their signature.
Other languages
SDKs for Java, C#, PHP and Ruby are planned. Until then, the samples for those languages call the API over plain HTTP, and openapi/openapi.json in the repository describes every public route if you prefer to generate a client.