How do I convert an X (Twitter) username to its user ID (rest_id)?
Look the user up by handle and read the numeric ID from the result: X's official API does it with GET /2/users/by/username/:username, which needs a developer account, and in twscrape the maintainer pointed to api.user_by_login("name") and its id (issue 26, July 2023). XTikAPI's x.accounts.detail takes screen_name and returns the account with its ID, $0.002 a call; it also takes rest_id to go the other way.
Updated 2026-11-23
Three ways
X API v2
Call: GET /2/users/by/username/:username
Needs: A developer app and bearer token; counts against your plan
twscrape
Call: user = await api.user_by_login("x"), then user.id
Needs: Logged-in X accounts in a pool
XTikAPI
Call: x.accounts.detail with screen_name
Needs: An API key
The user ID never changes when someone renames their handle, so store the ID, not the name.
Bulk conversion
- Call
x.accounts.detailonce per handle withscreen_name(no @). - Save the returned
idwith the handle. - Use the ID for later calls:
x.posts.listtakesrest_id, so a renamed account still resolves.
Cost: 5,000 handles × $0.002 = $10. A handle that doesn't exist fails and isn't charged.
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).
- Spending you control: a failed call or a timeout is not charged (charged: false), X-Max-Price caps one call, and the same Idempotency-Key within 24 hours is never billed twice.
- 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-23.
More about X
- X API
- Agent Reach Twitter/X channel stopped working: what changed?
- twikit errors (Cloudflare 403, KEY_BYTE, login 399, rate limits, bans): how do I fix them?
- twscrape errors (404, No account available, XClIdParseError, ct0, bans): how do I fix them?
- snscrape returns blocked (404) for Twitter: what still works?
- Is it legal to collect public social media data?
Questions
Is rest_id the same as the user ID?
Yes: rest_id is the name X's web GraphQL uses for the numeric user ID.
One key. Start now.
19 platforms, 229 endpoints, from $0.002 a call. Errors and timeouts are free.
Start free