Skip to main content
Your Python backend has TikTok links, pasted by users or collected by a scraper, and needs the video files. Fetching TikTok yourself works on a laptop and gets blocked once the code runs on a server, so this sends each link to Importly and saves the finished MP4. It needs only requests. The Node version does the same in JavaScript.

One video

download_tiktok.py
maxCostDollars caps what one file may cost. A short TikTok is about a cent, so 0.1 only stops an unusually long video; that job fails with MAX_COST_EXCEEDED instead of downloading. See Capping the cost. Share links such as vm.tiktok.com/... work as they are, so you can pass on whatever your users paste. If the post behind a share link has been deleted or made private, the job fails with VIDEO_UNAVAILABLE (“the TikTok short link no longer leads to a post”), so show that message to the user rather than retrying. See Media unavailable.

A list of videos

If another library or a scraper already gives you video URLs (a user’s posts, a hashtag, a search), you only need the files. This downloads them a few at a time and keeps going when one fails. Add it to download_tiktok.py above:
download_tiktok.py
Keep workers small. POST /import allows 240 requests per hour per key and 50 imports queued or running at once, and going over either returns 429 with retryAfter. For hundreds of links, use webhooks and a steady send rate instead: Batch imports has a sender that handles both.

What comes back

The finished job from GET /import/status:
TikTok videos are portrait, so 720p means 720 pixels on the short side (720×1280). Set "includeVideo": False in the request body for the audio only. All options are in Downloads.

Errors to handle

Every error has a documentationUrl with the fix. See Error handling.

In production

  • In a web app, don’t block a request on the loop. Pass webhookUrl and save the file when Importly calls you back (Webhooks); the Python (FastAPI) guide shows the endpoints, and Celery covers background workers.
  • Copy the file somewhere permanent, or set store: true to have every import land in your own bucket (recipe).
  • Only download videos your users have the right to use.
Downloads cost $0.002 per MB, with a $0.01 minimum, so a short TikTok is usually about a cent. Try it free, no card required. See Pricing & credits.