Runnable example scripts for every resource in the SDK.
Set your API key and run any example:
export TIKHUB_API_KEY="YOUR_API_KEY"
python examples/health_check.py # smallest possible call
python examples/quickstart.py # 4 useful endpoints, hand-written
python examples/douyin_web.py # all 76 Douyin web endpoints
python examples/tiktok_app_v3.py # all 75 TikTok app endpointsEvery script is fully self-contained — you can copy any one file out of
the repo and run it with just pip install tikhub.
Every per-resource file:
- Imports
TikHubandTikHubError. - Defines a tiny
demo()helper that calls one endpoint, prints a truncated JSON response, and continues on error. - Calls every endpoint on that resource using the example values from
spec/openapi.json.
# excerpt from examples/douyin_web.py
def main() -> None:
with TikHub() as client: # reads $TIKHUB_API_KEY
# GET /api/v1/douyin/web/fetch_one_video
# 获取单个作品数据/Get single video data
demo("fetch_one_video", lambda: client.douyin_web.fetch_one_video(aweme_id="..."))
# POST /api/v1/douyin/web/fetch_multi_video
# 批量获取视频信息/Batch Get Video Information
demo("fetch_multi_video", lambda: client.douyin_web.fetch_multi_video(body=[]))
# ... and 74 moreAll names match the SDK attribute on client.*. Endpoint counts in parentheses.
Total: 51 resource files, 1002 demo calls.
TikTok-Interaction-API(post_comment / like / follow / collect / forward / reply / apply) — these would actually mutate state. Use the SDK directly if you need them.sora2.upload_image— needs a real file to upload, can't be auto-generated as a one-liner.
- Many calls will return HTTP 400 with "Request failed. Please retry" — that's TikHub's generic upstream error when the spec's
examplevalue (e.g. an aweme_id, note_id, share URL) has gone stale on the upstream platform. The SDK is wired correctly; the example value just no longer points at a real piece of content. Replace the value in the call with a real one and try again. - Each demo call costs API quota. The largest file (
douyin_web.py) makes 76 calls; the smallest makes 1. - The
demo()helper truncates responses to 600 chars. To see the full payload, replacedemo(...)with a directclient.<resource>.<method>(...)call.
If TikHub publishes a new spec version, refresh everything in three commands:
python scripts/refresh_spec.py # pulls latest openapi.json
python scripts/generate_resources.py # rewrites src/tikhub/resources/*.py
python scripts/generate_examples.py # rewrites this directory