# 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

| Error / Symptom | Root cause | Workaround reported in issues |
| --- | --- | --- |
| `Forbidden: status: 403` with Cloudflare block page (issue #396, Nov 2025) | TLS / client fingerprinting on httpx, not expired cookies; persists even on the same IP where Chrome works | 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) | X changed `ondemand.s.js` format; regex in `transaction.py` stopped matching | 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) | 2FA challenge or blocked automated login flow | 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) | Automated `login()` calls, posting (`create_tweet`), or non-human access patterns | Export cookies from Chrome instead of `login()`, separate read/write accounts, warm up aged accounts |

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

| twikit method | X GraphQL endpoint | Limit per 15 min |
| --- | --- | --- |
| `search_tweet`, `search_user` | SearchTimeline | 50 |
| `get_user_tweets` (Tweets or Replies) | UserTweets / UserTweetsAndReplies | 50 |
| `get_user_followers` | Followers | 50 |
| `get_user_by_screen_name` | UserByScreenName | 95 |
| `get_tweet_by_id` | TweetDetail | 150 |
| `get_user_following`, `get_retweeters`, `get_user_by_id` | Following / Retweeters / UserByRestId | 500 |
| `follow_user` | friendships/create | 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

- [X post search API](https://xtikapi.com/apis/x/posts/search) ($0.002 a call): One page of X posts for a search query.
- [X post list API](https://xtikapi.com/apis/x/posts/list) ($0.002 a call): An X account's posts, newest first.
- [X account details API](https://xtikapi.com/apis/x/accounts/detail) ($0.002 a call): An X (Twitter) account profile.
- [X comments API](https://xtikapi.com/apis/x/comments/list) ($0.002 a call): Replies to one X (Twitter) post.
- [X account followers API](https://xtikapi.com/apis/x/accounts/followers) ($0.002 a call): A page of an X account's followers.
- [X reposters API](https://xtikapi.com/apis/x/retweeters/list) ($0.002 a call): Accounts that reposted an X post.

## More about X

- [X API](https://xtikapi.com/apis/x)
- [twscrape errors (404, No account available, XClIdParseError, ct0, bans): how do I fix them?](https://xtikapi.com/answers/twscrape-errors-and-fixes)
- [How much does the X (Twitter) API cost to read posts in 2026, and is there a cheaper way?](https://xtikapi.com/answers/x-api-pricing-alternative)
- [Agent Reach Twitter/X channel stopped working: what changed?](https://xtikapi.com/answers/agent-reach-twitter-channel-broken)
- [Nitter is shutting down: how else can I read X accounts without logging in?](https://xtikapi.com/answers/nitter-shut-down-alternative)
- [Is it legal to collect public social media data?](https://xtikapi.com/answers/is-scraping-public-social-media-data-legal)

## How to do it

- [How to get a user's posts from X (Twitter) with Python](https://xtikapi.com/guides/x-user-posts-python)

## Sources

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

- [twikit issue #396 (Cloudflare 403 even with fresh cookies)](https://github.com/d60/twikit/issues/396)
- [twikit issue #408 (ClientTransaction broken, KEY_BYTE indices)](https://github.com/d60/twikit/issues/408)
- [twikit issue #359 (account suspension)](https://github.com/d60/twikit/issues/359)
- [twikit issue #276 (login error 399)](https://github.com/d60/twikit/issues/276)
- [twikit rate limits table (ratelimits.md)](https://github.com/d60/twikit/blob/main/ratelimits.md)
- [twikit guide: ToProtectYourAccount.md](https://github.com/d60/twikit/blob/main/ToProtectYourAccount.md)

## 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.

---

XTikAPI: one API key for public social media data, prepaid per call. [HTML version](https://xtikapi.com/answers/twikit-errors-and-fixes) · [llms.txt](https://xtikapi.com/llms.txt) · [OpenAPI](https://xtikapi.com/openapi.json)
