twikit errors (Cloudflare 403, KEY_BYTE, login 399, rate limits, bans): how do I fix them?

twikit runs X's unofficial web API through your own logged-in account, which triggers five recurring problems: Cloudflare 403 client fingerprinting (even with fresh cookies), Couldn't get KEY_BYTE indices when X edits ondemand.s.js, login errors 399/366 (often 2FA), strict 15-minute rate limits (50 searches per window), and account suspensions even on read-only jobs. Export browser cookies once instead of calling login() repeatedly, patch ON_DEMAND_FILE_REGEX when scripts change, or read public X data without any X account via XTikAPI at $0.002 a call.

Updated 2026-11-25

Common twikit errors and what worked in GitHub issues

Forbidden: status: 403 with Cloudflare block page (issue #396, Nov 2025)

Root cause: TLS / client fingerprinting on httpx, not expired cookies; persists even on the same IP where Chrome works

Workaround reported in issues: Fresh cookies and residential IPs rarely fix it; many switched libraries or APIs

Couldn't get KEY_BYTE indices or 'ClientTransaction' has no attribute 'key' (issue #408, Mar 2026)

Root cause: X changed ondemand.s.js format; regex in transaction.py stopped matching

Workaround reported in issues: Patch only ON_DEMAND_FILE_REGEX to match ,<number>:"ondemand.s" (don't swap the whole file)

Login 400 code 399 (Incorrect. Please try again) or code 366 (LoginFlow not accessible) (issues #276, #227)

Root cause: 2FA challenge or blocked automated login flow

Workaround reported in issues: Disable 2FA or handle TOTP via pyotp, or skip login() entirely and use load_cookies

Account suspended a day later by email (issues #359, #318)

Root cause: Automated login() calls, posting (create_tweet), or non-human access patterns

Workaround reported in issues: Export cookies from Chrome instead of login(), separate read/write accounts, warm up aged accounts

twikit 15-minute rate limits (from ratelimits.md)

search_tweet, search_user

X GraphQL endpoint: SearchTimeline

Limit per 15 min: 50

get_user_tweets (Tweets or Replies)

X GraphQL endpoint: UserTweets / UserTweetsAndReplies

Limit per 15 min: 50

get_user_followers

X GraphQL endpoint: Followers

Limit per 15 min: 50

get_user_by_screen_name

X GraphQL endpoint: UserByScreenName

Limit per 15 min: 95

get_tweet_by_id

X GraphQL endpoint: TweetDetail

Limit per 15 min: 150

get_user_following, get_retweeters, get_user_by_id

X GraphQL endpoint: Following / Retweeters / UserByRestId

Limit per 15 min: 500

follow_user

X GraphQL endpoint: friendships/create

Limit per 15 min: 15

Limits apply per account per 15-minute window (so one account tops out at 200 search pages/hour). Users in issue #100 noted staying under these ceilings still does not prevent bans if X flags the client fingerprint or login behavior.

If you keep using twikit vs switching to an API

If you stay on twikit: log in once in a real browser, save cookies with save_cookies('cookies.json') and reuse load_cookies (as recommended in ToProtectYourAccount.md), stay well below 50 searches per 15 minutes, and never share a reading account with automated posting.

If you only read public X data and want no cookie management, Cloudflare blocks, or regex patches: use x.posts.search (keyword, search_type, cursor), x.posts.list (screen_name), x.accounts.detail, x.comments.list, x.accounts.followers, and x.retweeters.list. Cost: checking 50 accounts twice daily for 30 days = 3,000 calls × $0.002 = $6; monitoring 20 keywords hourly for 30 days = 14,400 calls = $28.80.

Why XTikAPI

  • XTikAPI reads X with 16 endpoints from $0.002 a call, and a failed call is not charged.
  • Fewer tokens for AI: across 10 recorded live X calls (2026-11-18), raw platform JSON is ~63k tokens vs ~21k via XTikAPI REST (66.7% fewer) and ~23k via MCP (63.7% fewer).
  • See before you pay: 192 of 229 endpoints show a recorded real response on their page (10 of 16 for X).
  • One shape: posts, comments and accounts from 19 platforms come back as the same objects, author in author and counts in metrics, so another platform needs no new parser.
  • Free trial: a verified account gets $0.50, no card.

Endpoints

Each with its price; the endpoint page has parameters, fields and a recorded response.

How to do it

Sources

What this page says about other products comes from their own pages and docs, read on 2026-11-25.

More about X

Questions

Will a residential proxy fix twikit's Cloudflare 403?

Usually no: in issue #396 Chrome worked fine on the exact same machine and IP where twikit got 403, pointing to client/TLS fingerprinting rather than IP reputation.

Is login error 399 caused by a wrong password?

Not necessarily: in issue #276 code 399 appeared on valid credentials when two-factor authentication was enabled.

One key. Start now.

19 platforms, 229 endpoints, from $0.002 a call. Errors and timeouts are free.

Start free