Skip to content
UGC API

Post to TikTok with Python

TikTok's Content Posting API lets an app publish videos and photo slideshows to a creator's account. This guide shows the full flow in Python with requests: what you need for keys, the creator info call TikTok requires, initializing a post from a URL, and checking status. Then the same thing in a few lines with UGC API.

Updated

What you need (the "TikTok API key")

  1. A TikTok developer app at developers.tiktok.com, with Login Kit and the Content Posting API added. It gives you a client key and client secret; that is the closest thing to an API key.
  2. Scopes: user.info.basic, video.publish (direct post) and/or video.upload (send to the creator's inbox as a draft).
  3. A verified domain or URL prefix for PULL_FROM_URL, so TikTok can fetch your media.
  4. A user access token for each creator, from the OAuth flow. Access tokens last 24 hours; refresh tokens last a year.
  5. The audit. Until TikTok audits your app, every direct post is private (SELF_ONLY), and only a handful of users can post. See the audit guide.

Step 1: query creator info

TikTok requires apps to fetch the creator's info before each post and show who it posts as, and which privacy levels are allowed. Never hard-code the privacy level; let the user pick from privacy_level_options.

python
import requests, time

API = "https://open.tiktokapis.com/v2"
token = "act.example..."  # the creator's user access token
H = {"Authorization": f"Bearer {token}", "Content-Type": "application/json; charset=UTF-8"}

info = requests.post(f"{API}/post/publish/creator_info/query/", headers=H).json()["data"]
print("Posting as", info["creator_nickname"])
print("Allowed privacy:", info["privacy_level_options"])
print("Max video seconds:", info["max_video_post_duration_sec"])

Step 2: initialize a video post

python
body = {
    "post_info": {
        "title": "3 ingredient dinner #cooking",
        "privacy_level": "PUBLIC_TO_EVERYONE",   # must be one of privacy_level_options
        "disable_comment": False,
        "disable_duet": False,
        "disable_stitch": False,
        "video_cover_timestamp_ms": 1000,
    },
    "source_info": {
        "source": "PULL_FROM_URL",
        "video_url": "https://media.example.com/clip.mp4",  # on your verified domain
    },
}
r = requests.post(f"{API}/post/publish/video/init/", headers=H, json=body).json()
if r["error"]["code"] != "ok":
    raise SystemExit(r["error"])
publish_id = r["data"]["publish_id"]

For a file on disk instead of a URL, use source: "FILE_UPLOAD" with video_size, chunk_size and total_chunk_count, then PUT the bytes to the returned upload_url in chunks with Content-Range headers.

Step 3: check status

python
while True:
    s = requests.post(f"{API}/post/publish/status/fetch/", headers=H,
                      json={"publish_id": publish_id}).json()["data"]
    print(s["status"])
    if s["status"] in ("PUBLISH_COMPLETE", "FAILED"):
        break
    time.sleep(5)

print(s.get("fail_reason") or s.get("publicaly_available_post_id"))
Yes, TikTok's field is spelled publicaly_available_post_id. Public posts can take several minutes to get it while moderation runs.

Posting a photo slideshow

python
body = {
    "post_info": {"title": "5 things I stopped buying", "description": "#budget",
                  "privacy_level": "PUBLIC_TO_EVERYONE", "auto_add_music": True},
    "source_info": {"source": "PULL_FROM_URL", "photo_cover_index": 0,
                    "photo_images": [f"https://media.example.com/s/{i}.jpg" for i in range(1, 6)]},
    "post_mode": "DIRECT_POST",
    "media_type": "PHOTO",
}
r = requests.post(f"{API}/post/publish/content/init/", headers=H, json=body).json()

Up to 35 images, JPEG or WebP. post_mode: "MEDIA_UPLOAD" sends it to the creator's inbox as a draft instead.

Errors you'll meet

ErrorMeaning
unaudited_client_can_only_post_to_private_accountsApp not audited; the creator's account must be private and privacy SELF_ONLY
url_ownership_unverifiedThe media URL's domain or prefix isn't verified in your app
spam_risk_too_many_postsThe creator hit TikTok's daily posting cap
privacy_level_option_mismatchThe privacy you sent isn't in the creator's privacy_level_options
access_token_invalidToken expired; refresh it

The short version with UGC API

UGC API is an audited TikTok app, so public posting works from day one, and media can be any public URL. Creators connect with a connect link. From Python:

python
import requests

r = requests.post(
    "https://ugcapi.dev/v1/posts",
    headers={"Authorization": "Bearer ugc_live_..."},
    json={
        "accounts": ["acc_tt_01", "acc_tt_02"],
        "format": "video",
        "media": ["https://cdn.example.com/clip.mp4"],
        "caption": "3 ingredient dinner #cooking",
        "scheduled_at": "2026-11-20T18:00:00Z",
        "options": {"tiktok": {"privacy": "PUBLIC_TO_EVERYONE", "allow_comment": True}},
    },
)
print(r.json())

Creator info, URL verification, token refresh, status polling and retries happen on our side. The same call posts to Instagram, Facebook and YouTube if you add those accounts. Results come back by webhook or GET /v1/posts/:id.

FAQ

Is there an official TikTok Python SDK?

No. TikTok's Content Posting API is plain HTTPS and JSON, so requests or httpx is all you need.

Is the TikTok posting API free?

Yes, TikTok doesn't charge for it. You need an approved app and, for public posts, a passed audit.

Can unofficial Python libraries post to TikTok?

Libraries that drive a logged-in browser or replay private endpoints break often and put accounts at risk. Use the official API or a provider built on it.

How many videos can I post per day through the API?

TikTok caps posts per creator per day, shared across every app the creator uses, typically around 15. Rate limits per token also apply.

Related