How to Get an Official X (Twitter) API Key (Step by Step)
Official X Developer Portal walkthrough: create a project and app, generate the API key, secret, bearer and access tokens, set permissions, and pass approval.

This is the complete walkthrough for getting an official X API key through the X Developer Console: creating the developer account, writing a use-case description that passes review, generating each credential type, setting permissions, and making your first authenticated call. The current public pricing page lists prepaid pay-per-use and custom Enterprise access, with no general public Free tier listed.
TL;DR: Sign in at console.x.com, accept the Developer Agreement, describe your intended use, create a Project and App, and save the credentials the console generates (they are shown once). Add a payment method for pay-per-use billing, then smoke-test the Bearer Token with a single user lookup.
What Is an X API Key (and Why You Need One)?
An X API key is a credential string that identifies your application to X's servers. Without one, every request to the X API gets rejected with a 401 Unauthorized response. "Twitter API key" and "X API key" refer to the same credential, X just rebranded the platform; the underlying auth model is unchanged.
In practice, "X API key" is an umbrella term that maps to several distinct credentials, each used in a different scenario:
- Bearer Token, a single-string credential for app-only read access (search, user lookups, public tweet reads). This is what most developers actually mean when they say "API key".
- API Key & Secret, OAuth 1.0a credentials, used by legacy v1.1 endpoints and some write actions on a single account.
- OAuth 2.0 Client ID & Secret, for the modern PKCE flow where end users authorize your app.
- Access Token & Secret, long-lived credentials tied to one specific account, used to act on that account's behalf (post, like, follow).
For most data-collection use cases, scraping, analytics, dashboards, bots that don't act as users, a Bearer Token is enough. The other credentials only matter when you need user-delegated actions or legacy v1.1 access.
The X Developer Portal Walkthrough
Getting an official Twitter API key requires creating a developer account at console.x.com, accepting the Developer Agreement, describing your intended use case, creating a Project and App, and completing the billing or access steps shown for your account. The setup can generate Bearer, OAuth 1.0a, or OAuth 2.0 credentials depending on the app flow.
Step 1, Sign in to the Developer Console
Go to console.x.com and sign in with your X (Twitter) account.
If you don't have an X account, you'll need to create one first. The developer console requires a standard X account in good standing, and X may ask you to verify contact details during setup.
Step 2, Accept the Developer Agreement
You'll be asked to review and accept the X Developer Agreement and Policy. Read it carefully, your use case description is binding, and any deviation can result in your access being revoked.
Step 3, Describe Your Use Case
X asks how you plan to use the API. Per the current getting-access documentation, you provide basic usage information plus an app name, description, and use case. A strong description covers:
- What you're building (app, bot, analytics tool, research project)
- How you'll use the data (display tweets, analyze sentiment, automate posting)
- Whether you'll display Twitter content to end users
- Whether your app will tweet, retweet, like, or follow on behalf of users
Be specific and honest. Vague descriptions like "I want to use the API for a project" get flagged.
Step 4, Create a Project and App
Once approved, create a Project in the console:
- Give it a name and description
- Select your use case category
- Create an App within the project
Step 5, Generate Your API Keys
Depending on your app's authentication setup, the console can generate up to four credential types:
| Credential | What It's For |
|---|---|
| API Key & Secret | Identifies your app (OAuth 1.0a) |
| Bearer Token | App-only authentication (read endpoints) |
| Access Token & Secret | Acts on behalf of your account (write endpoints) |
| Client ID & Secret | OAuth 2.0 PKCE flow for user authentication |
Save these immediately. They're shown only once. If you lose them, you'll need to regenerate.
Which X API Key Should You Actually Use?
| Use case | Credential | Notes |
|---|---|---|
| Read public tweets and profiles | Bearer Token | Simplest path, app-only auth |
| Post / like / retweet from your own account | Access Token & Secret | Tied to one user |
| Multi-user app (users log in with X) | OAuth 2.0 Client ID + PKCE | Required for any user-delegated action |
| Legacy v1.1 endpoints | API Key & Secret (OAuth 1.0a) | Avoid for new projects |
If you're building a scraper, analytics tool, research project, or dashboard, Bearer Token is the only credential you'll touch. Everything else is for user-facing apps that need to act as a logged-in user.
Step 6, Add a Payment Method
For current public pay-per-use access, complete the credit and billing steps shown in the X Developer Console before making billable calls:
- Go to the Billing section in the Developer Console
- Add a credit card or payment method
- Purchase credits, these are deducted per request
- Optionally set a monthly spending cap to avoid surprise bills
- Enable auto-recharge if you don't want your app to stop when credits run out
Check the billing terms shown in your console for credit validity and recharge behavior; the public pricing page does not publish a universal expiry rule.
Step 7, Make Your First API Call
Test your setup with a simple user lookup:
curl -X GET "https://api.x.com/2/users/by/username/elonmusk" \
-H "Authorization: Bearer YOUR_BEARER_TOKEN"
If you get a JSON response with user data, you're set. If you get a 401 or 403, double-check your Bearer Token.
Common X API Key Errors and What They Mean
When you start integrating, these are the errors you'll actually hit. Knowing what each one means saves hours of guessing:
| Error | What it usually means | How to fix |
|---|---|---|
401 Unauthorized |
Bearer Token wrong, missing, or revoked | Re-copy from the console, ensure the header is exactly Authorization: Bearer ... |
403 Forbidden |
App lacks permission for that endpoint or scope | Check app permissions in the console; some endpoints (DMs, Full-Archive Search) need elevated access |
429 Too Many Requests |
Rate limit hit on this endpoint window, see Twitter API rate limits | Wait until the x-rate-limit-reset timestamp, add exponential backoff in your client |
400 Bad Request |
Missing or malformed parameters | Check the required expansions and *.fields for v2 endpoints |
503 Service Unavailable |
X infrastructure issue (not your fault) | Retry with backoff; persistent 503s usually clear within minutes |
Test Your X API Key in Three Languages
Before integrating into a real app, run a smoke test from your terminal. The same call in three runtimes:
curl:
curl -X GET "https://api.x.com/2/users/by/username/elonmusk" \
-H "Authorization: Bearer YOUR_BEARER_TOKEN"
Python (requests):
import requests
r = requests.get(
"https://api.x.com/2/users/by/username/elonmusk",
headers={"Authorization": "Bearer YOUR_BEARER_TOKEN"},
)
print(r.status_code, r.json())
Node.js (fetch):
const r = await fetch(
"https://api.x.com/2/users/by/username/elonmusk",
{ headers: { Authorization: "Bearer YOUR_BEARER_TOKEN" } }
);
console.log(r.status, await r.json());
A successful response returns {"data": {"id": "...", "name": "...", "username": "..."}}. If you get 401, the token is wrong. If you get 403, the app doesn't have permissions for that endpoint.
What Does the Official API Cost?
The current official X API pricing page lists prepaid pay-per-use and custom Enterprise access, with no general public Free tier listed. Standard Post reads cost $0.005, User reads cost $0.010, standard Post create requests cost $0.015, and DM interaction create requests cost $0.015. The listed 24-hour deduplication period resets at midnight UTC. Pay-per-use access has a 2-million monthly Post-read cap; Enterprise pricing is custom.
| Operation | Cost Per Request |
|---|---|
| Post read (fetch a tweet) | $0.005 |
| User profile lookup | $0.010 |
| Standard Post create (write a Post) | $0.015 |
| DM event read | $0.010 |
| DM send | $0.015 |
| Follow / like / retweet | $0.015 |
There's a 24-hour deduplication window, fetching the same resource twice in one UTC day generally counts as one charge, though X describes deduplication as a soft guarantee.
The pay-per-use model caps at 2 million Post reads per month. Enterprise access is custom priced.
For worked monthly estimates at common volumes, see the Twitter API workload cost examples.
Start building with GetXAPI
$0.05 per 1,000 tweets. $0.10 free credits. No credit card required.
X's Restricted Use Cases (Write Your Application Around These)
X publishes a list of restricted use cases in its developer terms. These are policy restrictions on what the API may be used for, and an application describing one of them is unlikely to be approved:
- Surveillance, tracking users, monitoring protests, investigating groups
- Scraping for AI training, fine-tuning models on X content outside X's own terms
- Competitive analysis, benchmarking X's performance or user metrics
- Spam automation, bulk following, identical cross-account posting
- Sensitive data inference, deriving health, financial, political, or demographic information about users
- Off-platform matching, linking X identities to external databases without consent
Vague use case descriptions also get flagged, so be specific about what you're building even when it's clearly permitted. X does not publish a formal appeal process for declined applications; the practical recourse is re-applying with a clearer, policy-compliant description.
Storing Your X API Key Securely
Never hardcode credentials in your source code. Anyone with access to your repository gets access to your API account. The correct pattern in every language is to read the key from environment variables:
# Set in your shell profile or CI secrets
export X_BEARER_TOKEN="your-bearer-token-here"
import os
import requests
# Read from environment, never from string literals
token = os.environ["X_BEARER_TOKEN"]
response = requests.get(
"https://api.x.com/2/users/by/username/elonmusk",
headers={"Authorization": f"Bearer {token}"}
)
// Node.js: reads from process.env at runtime
const token = process.env.X_BEARER_TOKEN;
if (!token) throw new Error("X_BEARER_TOKEN not set");
const response = await fetch(
"https://api.x.com/2/users/by/username/elonmusk",
{ headers: { Authorization: `Bearer ${token}` } }
);
If you accidentally commit a credential to a public repository, rotate it immediately: open your app in the Developer Console, go to Keys and Tokens, and click Regenerate. Note that regeneration invalidates the old credential at that moment and the new value only exists once generated, so plan it as a coordinated rotation: regenerate, then update your environment variables and redeploy right away, accepting a brief window in which requests with the old token return 401.
Understanding Rate Limits After You Get Your Key
The official X API uses a 15-minute sliding window model. Each endpoint has a fixed number of requests allowed per window, and hitting the cap returns a 429 response with an x-rate-limit-reset header containing the Unix timestamp when the window resets. The Recent Search endpoint allows 450 requests per 15 minutes on standard app-only access, which translates to roughly 9,000 tweets per 15 minutes at 20 tweets per response.
Every response includes x-rate-limit-limit, x-rate-limit-remaining, and x-rate-limit-reset headers. Your client should check x-rate-limit-remaining before each call and implement exponential backoff as it approaches zero. The full per-endpoint table, window mechanics, and 429-handling patterns are covered in the Twitter API rate limits guide.
The cheapest Twitter API. Try it free.
$0.05 per 1,000 tweets. $0.10 free credits. No credit card required.
API Key Management at Team Scale
Teams managing X API keys across environments need four practices: separate development, staging, and production apps within X's allowed structure; immediate rotation on team member offboarding; key storage in a secrets manager rather than shell profiles or shared spreadsheets; and clean per-environment cost attribution.
Separate environments the way X permits. X's developer policy prohibits multiple apps for the same or substantially similar use case, with one exception: up to three apps explicitly designated as development, staging, and production. Use that trio rather than sharing one credential everywhere, and never point test runs at the production app, where they can exhaust credits or consume rate-limit windows that affect live users.
Rotate keys on offboarding. When someone with access to a credential leaves the team, regenerate it immediately. Regeneration invalidates the old value at that moment, so coordinate it: regenerate, update every environment, redeploy, and accept the brief 401 window in between.
Use a secrets manager. For teams of more than two or three people, store credentials in a secrets manager (AWS Secrets Manager, HashiCorp Vault, 1Password Secrets Automation) rather than in individual developers' shell profiles. Secrets managers provide audit logs, access control, and automatic rotation.
Set spending caps. The Developer Console supports monthly spending caps under Billing. Set one before your first production run, not after your first surprise bill.
Troubleshooting After Setup
Three issues come up repeatedly after a successful setup:
Keys that work in development but fail in production. Almost always a missing environment variable in the production runtime. Docker containers, cloud functions, and CI environments all require environment variables to be explicitly declared; a value in your local shell profile does not travel with the deploy.
Keys that suddenly stop working. Check three things in order: whether someone rotated the credential without updating every environment, whether a spending cap was hit, and whether the key was flagged by X's automated ToS systems. The error code distinguishes the cases: 401 is a wrong or revoked credential, 403 is permissions or account status, 429 is rate limiting.
Inconsistent responses between environments. Usually a different API base URL or parameter set per environment. Confirm the base URL and the expansions / *.fields parameters are identical across environments.
A five-line health check at application startup (one minimal authenticated call, abort on failure) prevents the most common production failure: a pipeline that runs for hours and fails at the output stage because the credential died midway.
Frequently Asked Questions
Is the official X API key free in 2026?
The key itself can be generated without a fee, but the current public X pricing page does not list a general public Free tier for usage. It lists prepaid pay-per-use and custom Enterprise access. Check console.x.com for the terms attached to a specific account.
How long does it take to get approved for an X API key?
X does not publish an approval timeline. Some accounts get access quickly, while reports on the X developer forum describe waits of a week or more for some applicants. Clear, policy-compliant use case descriptions are the one factor you control.
What's the difference between an API Key and a Bearer Token?
The API Key & Secret identifies your app under OAuth 1.0a, used for legacy v1.1 endpoints and account-level write actions. The Bearer Token is a single-string credential used for app-only access on v2 read endpoints. Most modern integrations use only the Bearer Token.
Can I use one X API key for multiple projects?
Be careful here: X's developer policy prohibits creating multiple apps for the same or substantially similar use case. The allowed structure is up to three apps designated as development, staging, and production for one use case. Genuinely distinct products with distinct use cases belong in their own approved setup, and reusing one key across unrelated projects shares billing, rate limits, and revocation blast radius.
What if my X API key application gets rejected?
X does not publish a formal appeal process. The practical recourse is re-applying with a clearer use case description that stays outside the restricted use cases. If your use case is public-data collection or analytics, a third-party key is the alternative path, no application required.
How do I rotate or revoke my X API key?
In the developer console, open your app, go to Keys & Tokens, and click "Regenerate" on the credential you want to rotate. The old credential is invalidated immediately and the new value exists only from that moment, so treat it as a coordinated rotation: regenerate, update every environment variable, and redeploy right away. Requests using the old token return 401 during the changeover window.
Can I get X API access without a developer account?
Not through the official portal, every official key is tied to a developer account at console.x.com. Third-party providers cover the public-data subset without a developer account; see the alternative below.
If You'd Rather Skip the Portal
Full disclosure: GetXAPI is our product. If your use case is public-data reads and writes (search, profiles, timelines, followers, posting, DMs) and you don't need OAuth user-delegated flows or a direct contract with X, a GetXAPI API key is generated at signup in about 30 seconds: no developer application, no use-case review, no credit card, $0.10 in signup credits, and a single Bearer header for every endpoint at $0.001 per standard call.
The official portal remains the right path when end users log in with their X account, when you need Enterprise streaming, or when compliance requires platform-direct access.
Developer portal information based on X Developer Docs and X Developer Community. Pricing verified against the X API pricing page on August 4, 2026.
Frequently Asked Questions
Generating the key carries no fee, but the current public X pricing page does not list a general Free tier for usage. It lists prepaid pay-per-use and custom Enterprise access, so making calls requires purchased credits. Check console.x.com for the terms attached to a specific account.
The API Key and Secret identify your app under OAuth 1.0a, used for legacy v1.1 endpoints and account-level write actions. The Bearer Token is a single-string credential for app-only access on v2 read endpoints. Most modern read integrations use only the Bearer Token.
X does not publish a formal appeal process. The practical recourse is re-applying with a clearer use case description that stays outside the restricted use cases listed in X's developer terms, such as surveillance, sensitive-attribute inference, and off-platform identity matching.
X does not publish an approval timeline. Some accounts get access quickly, while reports on the X developer forum describe waits of a week or more for some applicants. A clear, policy-compliant use case description is the one factor applicants control.
Depending on the app's authentication setup, up to four types: API Key and Secret (OAuth 1.0a), Bearer Token (app-only reads), Access Token and Secret (acting as your own account), and OAuth 2.0 Client ID and Secret (PKCE user login). They are shown once at generation, so save them immediately.
Check out similar blogs
More guides on the Twitter/X API, scraping, and pricing.







