For AI

How-to guides

Kuaishou API in Python: videos, accounts and comments (2026)

Five endpoints, in the order a script uses them: Kuaishou video search, video detail, account videos, video comments and comment replies, each a plain GET with an API key and no Kuaishou login. The worked example below is 5 calls and costs $0.046; a failed call is not charged.

Updated

Kuaishou (快手) data from Python usually starts with an open-source crawler. MediaCrawler, the best known, supports Kuaishou search, video IDs, comments and creator pages, and works by logging in through a Playwright browser with a QR code scanned in the app, then reusing the saved login state. That is a sound choice if you run it often and keep the browser and account healthy. This guide is the other option: each call is an HTTPS GET with an API key, no Kuaishou account, cookie, QR login or signature code, and requests as the only dependency.

You end with two CSV files: one of videos with plays, likes, comments, shares and saves, and one of comments and replies with text, likes, time and IP location.

Step by step

Set the key once: export OKDATA_API_KEY=okd_.... Every answer has code ("ok" on success); lists come in data.items with a page, single objects in data.item.

Three kinds of ID matter on Kuaishou. A video's ID is the 3x… part of its web link, as in https://www.kuaishou.com/short-video/3xm4f8kq2ze9wbs. An account's ID is a number such as 2318476509; the 快手号 handle people put in their bio is something else and shows up as author.username. A comment's ID is also a number.

Step 1: search videos

Kuaishou video search takes query plus three optional filters: sort (relevance by default, latest or popular), published_within (day, week or month) and duration (under_1_min, 1_to_5_min or over_5_min). One call returns about 10 videos for $0.02, each with the caption in text, the author, and metrics.views (plays), metrics.likes, metrics.comments, metrics.shares and metrics.favorites.

curl -G "https://api.okdata.online/v1/kuaishou/videos/search" -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'query=露营装备' --data-urlencode 'sort=popular' \
  --data-urlencode 'published_within=month' --data-urlencode 'duration=under_1_min'

Step 2: refresh one video

Kuaishou video detail takes id (the 3x… ID) or url, and a v.kuaishou.com short link from the share button works as url. At $0.002 it is the cheap way to re-read a video's counts later, for example once a day to track growth.

curl -G "https://api.okdata.online/v1/kuaishou/videos/get" -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'id=3xm4f8kq2ze9wbs'

Step 3: list the author's videos

Kuaishou account videos takes the numeric user ID as id, which you read from a video's author.id. sort is latest (the default) or popular. About 20 videos come back per page for $0.02.

curl -G "https://api.okdata.online/v1/kuaishou/users/videos/list" -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'id=2318476509' --data-urlencode 'sort=popular'

Step 4: read the comments

Kuaishou video comments takes the video's id or url and returns top-level comments newest first, about 10 a page, for $0.002. Each has id, text, author.name, likes, published_at and ip_location. The next page comes from sending page.next_cursor back as cursor.

curl -G "https://api.okdata.online/v1/kuaishou/videos/comments/list" -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'id=3xm4f8kq2ze9wbs'

Step 5: open a reply thread

Kuaishou comment replies needs the comment's ID as id and its video's 3x… ID as post_id. About 20 replies come back per page for $0.002, each with parent_id pointing at the comment.

curl -G "https://api.okdata.online/v1/kuaishou/comments/replies/list" -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'id=927364810552' --data-urlencode 'post_id=3xm4f8kq2ze9wbs'

Step 6: the full script

One function makes every call: it checks body["code"], returns None for deleted videos, and retries rate limits and busy upstreams with the same Idempotency-Key, so a retry is never charged twice. A generator handles paging with a page cap.

import csv
import os
import time
import uuid

import requests

API = "https://api.okdata.online"
KEY = os.environ["OKDATA_API_KEY"]
QUERY = "露营装备"
VIDEO_PAGES = 1     # pages of the author's videos; each page is one call
COMMENT_PAGES = 1   # pages of comments; each page is one call


def call(path, **params):
    headers = {"Authorization": f"Bearer {KEY}", "Idempotency-Key": str(uuid.uuid4())}
    for attempt in range(4):
        body = requests.get(API + path, headers=headers, params=params, timeout=60).json()
        if body["code"] == "ok":
            return body
        if body["code"] == "not_found":
            return None  # deleted or private: not charged
        if body.get("retry") in ("yes", "same_key"):
            time.sleep(body.get("retry_after_seconds") or 2 ** attempt)
            continue
        raise RuntimeError(f"{body['code']}: {body['message']} (request {body['request_id']})")
    raise RuntimeError(f"{path}: still failing after 4 tries")


def paged(path, max_pages, **params):
    cursor = None
    for _ in range(max_pages):
        body = call(path, **params, **({"cursor": cursor} if cursor else {}))
        if body is None:
            return
        yield from body["data"]["items"]
        if not body["page"]["has_more"]:
            return
        cursor = body["page"]["next_cursor"]


def video_row(v):
    m = v["metrics"]
    return [v["id"], v["published_at"], v["author"]["id"], v["author"]["name"], v["text"],
            m["views"], m["likes"], m["comments"], m["shares"], m["favorites"]]


hits = call("/v1/kuaishou/videos/search", query=QUERY, sort="popular", published_within="month")["data"]["items"]
if not hits:
    raise SystemExit("no videos found")
top = max(hits, key=lambda v: v["metrics"]["views"] or 0)

detail = call("/v1/kuaishou/videos/get", id=top["id"])
video = detail["data"]["item"] if detail else top
author_videos = list(paged("/v1/kuaishou/users/videos/list", VIDEO_PAGES, id=video["author"]["id"], sort="popular"))
comments = list(paged("/v1/kuaishou/videos/comments/list", COMMENT_PAGES, id=video["id"]))

replies = []
if comments:
    best = max(comments, key=lambda c: c["likes"] or 0)
    replies = list(paged("/v1/kuaishou/comments/replies/list", 1, id=best["id"], post_id=video["id"]))

with open("kuaishou_videos.csv", "w", newline="", encoding="utf-8-sig") as f:
    out = csv.writer(f)
    out.writerow(["video_id", "published_at", "author_id", "author", "caption", "plays", "likes", "comments", "shares", "saves"])
    out.writerows(video_row(v) for v in [video, *author_videos])

with open("kuaishou_comments.csv", "w", newline="", encoding="utf-8-sig") as f:
    out = csv.writer(f)
    out.writerow(["video_id", "comment_id", "parent_id", "text", "user", "likes", "ip_location", "published_at"])
    for c in comments + replies:
        out.writerow([video["id"], c["id"], c["parent_id"], c["text"], c["author"]["name"], c["likes"], c["ip_location"], c["published_at"]])

That is 5 calls, the worked example. The cheap endpoints are detail, comments and replies; search and account videos cost more per call, so cap those first. Fifty comment pages, about 500 comments, are $0.10.

Good to know

  • Follower counts. Videos carry the author's ID, name and verification, but author.followers is null. Kuaishou account profile has followers, total likes and video count for an account ID.
  • Reply counts. Kuaishou comments come back with replies null, so pick the threads to open by likes or by reading them, then call replies.
  • Order of comments. Newest first. There is no hottest-first option, which makes the comments endpoint good for checking what people say this week.
  • Photo posts. Some search results are photo sets, not videos; their type is image.
  • Extra fields. With view=full, posts add ext.duration_ms and ext.ip_location (where the post was published from). fields= trims the answer. Neither changes the price.
  • Free cases. Deleted or private videos answer not_found and are free, like every other error. Retries with the same Idempotency-Key within 24 hours return the stored result with meta.replayed: true.

For a daily look at what is trending on Kuaishou, the Kuaishou hot list is one call. Every Kuaishou endpoint is listed on the Kuaishou API page.

What the example costs

One filtered search for 露营装备 (camping gear), the detail of the most-played video, one page of its author's videos, one page of its comments and the replies under the most-liked comment

EndpointCallsPriceSubtotal
Kuaishou video search1$0.02$0.02
Kuaishou video detail1$0.002$0.002
Kuaishou account videos1$0.02$0.02
Kuaishou video comments1$0.002$0.002
Kuaishou comment replies1$0.002$0.002
Total5$0.046

Prices in force when this page was built. A failed call costs nothing.

In your AI (MCP)

Connect the MCP server once, then say what you want. The agent finds these endpoints, reads their prices and calls them on your balance.

SaySearch Kuaishou for 露营装备 videos from the last month, sorted by popularity. Take the most-played one, give me its stats, its author's most popular videos, its newest comments and the replies under the most-liked comment.

What the agent sends to the call tool first
{
  "endpoint": "kuaishou.videos.search",
  "params": {
    "query": "露营装备"
  },
  "idempotency_key": "<a new UUID>"
}

Set up the MCP server →

Sources

  1. MediaCrawler README (GitHub)github.com · read

Connect once, then just ask.

Every new key comes with $0.10 to try it. One sentence connects your agent.

Start free
Connect your AI

Paste this into your agent

Read https://okdata.online/agents.md and set up okdata for me; my key is in the OKDATA_API_KEY environment variable.

Claude Code, Cursor, Codex and other agents that can open a link set themselves up from it.

MCP serverhttps://api.okdata.online/mcp