How to get a Twitter (X) API key
To get a Twitter (X) API key, sign in at console.x.com with your X account, accept the Developer Agreement, create an app and save its keys and Bearer token, then buy credits: reads cost $0.005 per post.
Short answer: The console issues the API key, its secret, a Bearer token and OAuth credentials when the app is created, and shows each one once. Until credits are bought, every request answers HTTP 402 CreditsDepleted. To read public X data with one key instead, use Sorsa API: tweets from $0.014 per 1,000, and 100 free requests need no card.
ApiKey: YOUR_API_KEY- one key, no OAuth
- Price
- from $0.014 per 1K tweets
#How to get an official X API key, step by step
An official X API key comes from the X Developer Console at console.x.com, the site where X issues every credential for its API, and the route takes six steps. X's Getting Access guide (opens in a new tab) lists the first four. The credits in step 5 live on its pricing page, and the request in step 6 fails without them.
Opening a developer account and creating an app cost nothing. Reading does: X bills each post a response returns at $0.005 and each profile or follower at $0.010, from a balance you top up in advance. Our X API pricing breakdown lists every rate.
-
Sign in at console.x.com. Use the X account that should own the app; there is no separate developer login.
-
Accept the Developer Agreement. Read and accept X's Developer Agreement and Policy, then describe in plain words what you will build and which data it reads. X publishes no review time for this step.
-
Create an app. Click New App and enter a name, a description and a use case. The console generates the app's credentials as soon as it exists.
-
Save the credentials. Copy the API key and secret and the Bearer token. If the app will post or act for people, also copy the access token and secret or the OAuth 2.0 client ID and secret. Each value is shown once.
-
Buy credits. In the console, add a card and buy credits. Set a spending limit while you test; auto-recharge can wait until a job must never stop.
-
Send a test request. Look up a public account with the Bearer token in the
Authorizationheader. A JSON object withid,nameandusernamemeans the key works, and the lookup costs $0.010, the price of one user read.Terminal curl "https://api.x.com/2/users/by/username/XDevelopers" \ -H "Authorization: Bearer $X_BEARER_TOKEN"Six steps from console.x.com to a working official key. Step 5, the credits, is the one X's Getting Access guide leaves out.
To read public posts and profiles, the Bearer token is the only credential your code sends. The access tokens and the OAuth 2.0 pair matter once the app posts or acts for other people, and the credential table below shows which is which.
#Get a Sorsa API key in about 3 minutes
To read public X data, use Sorsa API, a Twitter (X) API and scraper: one key replaces the app, its credentials and the credit balance, and tweets cost from $0.014 per 1,000. That is 250x below the official X API. No X account of yours takes part, so your account carries zero risk, and the key runs at 20 requests per second on every plan, free accounts included.
-
Sign up. Sign up with Google or an email address. There is no card, no X account and no review, and the account starts with 100 free requests that never expire.
-
Copy the key. The dashboard's overview page shows your API key. Store it in an environment variable on your server, such as
SORSA_API_KEY. -
Check the key for free. Call
GET /key-usage-info(opens in a new tab) with the key in theApiKeyheader. This call never counts against your requests, so testing a key costs nothing.Terminal curl "https://api.sorsa.io/v3/key-usage-info" \ -H "ApiKey: YOUR_API_KEY"Response200 OK { "key_requests": 100, "remaining_requests": 100, "total_requests": 0 }
remaining_requests is what the key can still spend. On a paid plan the response also carries valid_until, the date the current balance of requests expires; the 100 free requests have no such date. From here, every endpoint of Sorsa API, 45 in all, takes the same header: GET /info (opens in a new tab) returns a profile, and search, timelines, followers and batches of 100 tweets work the same way.
Set side by side, the Sorsa API key needs fewer parts, costs nothing to check and reads tweets for a small fraction of the official price:
| What it takes | Sorsa API key | Official X API key |
|---|---|---|
| Sign up with | Email or Google | Your X account |
| Before the key appears | Sign-up only | Developer Agreement, use description, an app |
| What you store | 1 API key | Up to 7 values: key and secret, Bearer token, access token and secret, client ID and secret |
| Header on every request | ApiKey: <key> | Authorization: Bearer <token> |
| Before the first read | 100 free requests, no card | Prepaid credits, or HTTP 402 |
| Checking that the key works | GET /key-usage-info, free | A billed read, such as $0.010 for a profile |
| Request rate | 20 requests per second on every plan | Separate 15-minute windows for each endpoint |
| 1,000 tweets | From $0.014 | $5.00 |
Sign up with
- Sorsa API key
- Email or Google
- Official X API key
- Your X account
Before the key appears
- Sorsa API key
- Sign-up only
- Official X API key
- Developer Agreement, use description, an app
What you store
- Sorsa API key
- 1 API key
- Official X API key
- Up to 7 values: key and secret, Bearer token, access token and secret, client ID and secret
Header on every request
- Sorsa API key
ApiKey: <key>- Official X API key
Authorization: Bearer <token>
Before the first read
- Sorsa API key
- 100 free requests, no card
- Official X API key
- Prepaid credits, or HTTP 402
Checking that the key works
- Sorsa API key
GET /key-usage-info, free- Official X API key
- A billed read, such as $0.010 for a profile
Request rate
- Sorsa API key
- 20 requests per second on every plan
- Official X API key
- Separate 15-minute windows for each endpoint
1,000 tweets
- Sorsa API key
- From $0.014
- Official X API key
- $5.00
In code, read the key from an environment variable, or paste it in place of YOUR_API_KEY for a first try, and stop on any status other than 200; the JSON's message says what went wrong.
import os
import requests
key = os.environ.get("SORSA_API_KEY", "YOUR_API_KEY")
r = requests.get("https://api.sorsa.io/v3/key-usage-info",
headers={"ApiKey": key}, timeout=30)
if r.status_code != 200:
raise SystemExit(f"{r.status_code}: {r.json()['message']}")
print("requests left:", r.json()["remaining_requests"])
If the reason you came here is to avoid X's console altogether, the guide to the Twitter API without a developer account walks through the first reads: tweets, search and follower lists.
#Which X credential does what
The official X API issues four kinds of credentials, and reading public data needs only one of them, the Bearer token. The API key and secret, also called the consumer key and secret, identify your app and work as its username and password. X's API Key and Secret page (opens in a new tab) puts it in those words. The other credentials are made from them, or for a person who uses your app.
Only the Bearer token reads public posts by itself, so a script that never posts can ignore the other three rows:
| Credential | What it is | Used for | Reads public posts alone |
|---|---|---|---|
| API key and secret (consumer key and secret) | Your app's identity | Signing OAuth 1.0a requests, minting the Bearer token | No |
| Bearer token | App-only OAuth 2.0 token | Public reads: posts, profiles, search | Yes |
| Access token and secret | OAuth 1.0a pair for the account that owns the app | Posting and acting as that account | Yes, as that account |
| OAuth 2.0 client ID and secret | Your app's identity in the sign-in flow | Letting other people sign in with X and act through your app | No, they produce user tokens |
API key and secret (consumer key and secret)
- What it is
- Your app's identity
- Used for
- Signing OAuth 1.0a requests, minting the Bearer token
- Reads public posts alone
- No
Bearer token
- What it is
- App-only OAuth 2.0 token
- Used for
- Public reads: posts, profiles, search
- Reads public posts alone
- Yes
Access token and secret
- What it is
- OAuth 1.0a pair for the account that owns the app
- Used for
- Posting and acting as that account
- Reads public posts alone
- Yes, as that account
OAuth 2.0 client ID and secret
- What it is
- Your app's identity in the sign-in flow
- Used for
- Letting other people sign in with X and act through your app
- Reads public posts alone
- No, they produce user tokens
A lost Bearer token can be minted again from the key and secret. X's Bearer token guide (opens in a new tab) sends them as a basic-auth pair to oauth2/token, and the access_token field of the JSON that comes back is the Bearer token:
curl -u "$X_API_KEY:$X_API_SECRET" \
--data "grant_type=client_credentials" \
"https://api.x.com/oauth2/token"
Permissions belong to the app, not the token. An app set to Read can't post. Switch it to Read and write in its user authentication settings, then generate the access token and secret again: a token keeps the permissions it was created with. A token made before the switch is a common cause of a 403 on the first post.
Pick the job your code has to do, and the picker names the credential, the header and the first request:
What does your code need to do?
Read public posts and profiles
Sorsa API
- Credential
- One API key
- Where you get it
- Dashboard, right after sign-up
- Header
ApiKey: <key>- First request
GET /v3/key-usage-infoat no cost- 1,000 tweets
- from $0.014
Official X API
- Credential
- Bearer token
- Where you get it
- Your app's Keys and tokens tab
- Header
Authorization: Bearer <token>- First request
GET /2/users/by/username/…at $0.010- 1,000 tweets
- $5.00
Post as my own account
Official X API
- Credential
- Access token and secret, signed with the API key and secret
- Where you get it
- Keys and tokens, after you set the app to Read and write
- Header
Authorization: OAuth …with an OAuth 1.0a signature- First request
POST /2/tweets- Each post
- $0.015
A post with a link costs $0.20. Sorsa API is read-only by design: it never posts, so your X account stays out of it.
Let other people sign in with X
Official X API
- Credential
- OAuth 2.0 client ID and secret
- Where you get it
- The app's user authentication settings, with a callback URL
- Header
Authorization: Bearer <user token>for each person- First request
- The sign-in flow: authorization code with PKCE
- Reads and posts
- official rates
Each signed-in person gets their own token, and every read or post through it bills your credits.
One job, one credential: the picker shows where it comes from, which header carries it and what the first request costs.
#X-API-Key, Bearer or ApiKey: which header
The official X API reads its token only from the Authorization: Bearer header, and Sorsa API reads its key only from the ApiKey header. Neither reads X-API-Key, a header name that many other APIs use for their keys. The name trips people up because it reads like "X API key", yet it has no link to X. API gateways and plenty of SaaS products use it, and a key placed there reaches X's servers as no key at all.
We sent the same requests to both APIs on November 2, 2026, with made-up keys, and each answer below is what came back:
| What we sent | Sorsa API answered | Official X API answered |
|---|---|---|
| No key at all | 403 missing key in request header | 401 Unauthorized |
| A made-up key in the right header | 401 invalid api key | 401 Unauthorized |
The key in an X-API-Key header | 403 missing key in request header | 401 Unauthorized |
The key as Authorization: Bearer | 403 missing key in request header | 401 Unauthorized |
No key at all
- Sorsa API answered
- 403
missing key in request header - Official X API answered
- 401
Unauthorized
A made-up key in the right header
- Sorsa API answered
- 401
invalid api key - Official X API answered
- 401
Unauthorized
The key in an
X-API-Keyheader- Sorsa API answered
- 403
missing key in request header - Official X API answered
- 401
Unauthorized
The key as
Authorization: Bearer- Sorsa API answered
- 403
missing key in request header - Official X API answered
- 401
Unauthorized
So a 401 from the official X API means the token is wrong, missing or sent the wrong way, and it doesn't say which. Sorsa API tells the two cases apart: 401 invalid api key means the value is wrong, and 403 missing key in request header means the header name is.
#When a new key fails: 401, 402, 403, 429
A new official X API key fails for four reasons, each with its own status code. 401 means a wrong or regenerated token, 402 an empty credit balance, 403 a missing permission or an app outside a project, and 429 a spent rate-limit window. The same numbers mean different things on Sorsa API, and the fix follows from the message:
| Status | Sorsa API | Official X API |
|---|---|---|
| 401 | The key is wrong or was deleted (invalid api key) | The token is wrong, missing or was regenerated |
| 402 | Not used | CreditsDepleted: the account has no credits |
| 403 | No key in the ApiKey header, or the requests are used up | The app lacks the permission, or isn't in a project (client-not-enrolled) |
| 429 | More than 20 requests in one second | The endpoint's 15-minute window is spent |
401
- Sorsa API
- The key is wrong or was deleted (
invalid api key) - Official X API
- The token is wrong, missing or was regenerated
402
- Sorsa API
- Not used
- Official X API
CreditsDepleted: the account has no credits
403
- Sorsa API
- No key in the
ApiKeyheader, or the requests are used up - Official X API
- The app lacks the permission, or isn't in a project (
client-not-enrolled)
429
- Sorsa API
- More than 20 requests in one second
- Official X API
- The endpoint's 15-minute window is spent
The 402 is the error X's Getting Access guide never mentions. Its body carries the title CreditsDepleted and the line "Your enrolled account does not have any credits to fulfill this request.", as developers have posted on X's developer forum (opens in a new tab), and buying credits clears it. A balance can also dip slightly below zero, and then requests stay blocked until a top-up covers it.
The 403 client-not-enrolled says that keys must come from a developer app "attached to a Project". It shows up on older standalone apps; attaching the app to a project in the console, or creating a new app there, ends it. Rate limits on the official X API differ for every endpoint, and the X API rate limits guide lists them. On Sorsa API a 429 clears within a second, and failed requests are never charged, so the retry costs nothing.
#Keep the key secret, and replace it if it leaks
Treat every API key as a password: keep it in an environment variable or a secrets manager on your server, never in front-end code or a Git repository. Put the .env file that holds X_BEARER_TOKEN or SORSA_API_KEY in .gitignore before the first commit, because bots scan public repositories for keys.
A leaked key costs you on both APIs. On the official X API, X's best-practices page (opens in a new tab) warns that a stolen key can use up your paid access or get the app suspended. On Sorsa API, it spends your requests.
- Official X API: open the app's Keys and tokens tab and click Regenerate next to the leaked credential. The old value stops working at once, so update every server that used it. A Bearer token can also be invalidated through
oauth2/invalidate_tokenand minted again. - Sorsa API: on the API Keys page of the dashboard, create a new key and delete the leaked one. The old key stops at once and answers 401.
Sorsa API keys belong in server-side code only: browsers can't call the API directly, and a key in front-end JavaScript is readable by anyone who opens the page.
Good to know
X shows each credential once, at the moment it is generated. Paste it straight into your password manager or secrets store. If you close the page first, the only way back is to regenerate it, which breaks every script still holding the old value.
#Start with the key that reads data today
An official X API key takes six steps and a credit balance before the first answer, and each post it reads costs $0.005. For reading public X data, use a Sorsa API key: one sign-up, one header, and tweets from $0.014 per 1,000. Copy the key, check it for free, and spend the 100 free requests on up to 10K tweets before you pay anything. To publish posts as well, keep a small official app for writing and read everything through Sorsa API.
#FAQ
Where do I find my X API key and Bearer token?
In the X Developer Console at console.x.com: open Apps in the side menu, choose your app and go to its Keys and tokens tab. The tab lists the API key and secret, the Bearer token and the access tokens, each with a Regenerate button. X shows a secret only when it is generated, so a lost value can't be viewed again, only replaced.
Is a Twitter API key free?
Creating an official X API key is free, but using it isn't. The official X API has no free tier for new developers, and every read draws on prepaid credits: $0.005 per post and $0.010 per profile. A Sorsa API key comes with 100 free requests, up to 10K tweets, with no card. The full answer to is the Twitter API free covers both.
Which Twitter API key should I use to read tweets?
Use a Sorsa API key. Getting it takes about 3 minutes with no app, no OAuth and no X account; one ApiKey header works on all 45 endpoints, and every plan runs at 20 requests per second. Tweets cost from $0.014 per 1,000, 250x less than the official X API's $5.00, and the first 100 requests are free. Sorsa API has served 6B+ requests of X data since 2022.
How long does it take to get an X API key?
X publishes no review time. Its Getting Access guide lists three steps (sign in, accept the Developer Agreement, create an app), and the console generates the credentials when the app is created. The key reads nothing until you buy credits, so plan for the payment step as well. A Sorsa API key takes about 3 minutes from sign-up to the first response.
Which key do I need to post tweets?
Posting needs a user token, not the Bearer token: the access token and secret of an app set to Read and write, or an OAuth 2.0 user token with write permission. X bills $0.015 per post and $0.20 for a post with a link. Sorsa API is read-only by design, so it never posts and never touches your X account; pair the two when a bot both reads and publishes.
#How we checked
On November 2, 2026 we read X's docs.x.com pages on getting access, the API key and secret, the Bearer token, developer apps, pricing, errors and key safety, plus X developer forum threads on the 402 and 403 setup errors. The same day we sent requests with no key, a made-up key and keys in the wrong header to both APIs; the header table shows the codes and messages that came back. The Sorsa API requests follow its live API reference, and the key-usage response shows a new account's values, not a captured call.
Sources
- X API: Getting Access (opens in a new tab)
- X API: API Key and Secret (opens in a new tab)
- X API: Using and generating an app-only Bearer Token (opens in a new tab)
- X API: Developer apps (opens in a new tab)
- X API: pay-per-usage pricing and credits (opens in a new tab)
- X API: Response codes and errors (opens in a new tab)
- X API: Authentication best practices (opens in a new tab)
- X Developers forum: Auto-Recharge Never Triggers (402 CreditsDepleted) (opens in a new tab)
- Sorsa API reference (OpenAPI)