Twitter API KeyX API KeyX Developer PortalBearer TokenOAuth

How to Get an Official X (Twitter) API Key (Step by Step)

Official X Developer Portal walkthrough: create an app, generate the API key, secret, bearer and access tokens, set permissions, and make your first call.

GetXAPI··Updated August 16, 2026
Step-by-step guide to getting an official X (Twitter) API key in the Developer Console

This is the complete walkthrough for getting an official X API key through the X Developer Console: creating the developer account, describing your intended use, 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 an 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 an 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. The description is binding under the Developer Agreement, and X enforces its terms after the fact, so an inaccurate description puts the access at risk.

Step 4, Create an App

With the developer account created, click New App in the console and enter the app details: a name, a description, and your use case. The console generates your credentials when the app is created.

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:

  1. Go to the Billing section in the Developer Console
  2. Add a credit card or payment method
  3. Purchase credits, these are deducted per request
  4. Optionally set a monthly spending cap to avoid surprise bills
  5. 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 3-million monthly Post-read cap; Enterprise pricing is custom.

Operation Price Billed per
Post read (fetch a tweet) $0.005 Returned Post resource
User profile lookup $0.010 Returned User resource
Standard Post create (write a Post) $0.015 Request
DM event read $0.010 Returned DM event resource
DM send $0.015 Request
Follow / like / retweet $0.015 Request

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 3 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; building on one of them risks enforcement action and revoked access:

  • 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

Be specific about what you're building even when it's clearly permitted; the use-case description is binding under the Developer Agreement. X does not publish a formal appeal process for access enforcement, so staying clearly outside these restrictions is the practical safeguard.

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

Official X API rate limits are set per endpoint and per auth context. Most windows are 15 minutes, but some endpoints carry 24-hour caps, Post create (10,000 per 24 hours at the app level) and DM send (1,440 per 24 hours) being the notable ones. Hitting a 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.

Is there an approval wait for an X API key?

The current getting-access documentation describes no review step: you create a developer account, create an app, and the console generates credentials at app creation. X publishes no approval requirement or completion timeline. Older X developer forum threads describe waits under earlier access processes; treat those as historical rather than a property of the current documented flow.

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 project and app setup, and reusing one key across unrelated projects shares billing, rate limits, and revocation blast radius.

What if X restricts or revokes my API access?

X does not publish a formal appeal process. Access is governed by the Developer Agreement and the restricted use cases in X's developer terms, so staying clearly outside those restrictions is the factor you control. If your use case is public-data collection or analytics, a third-party key is the alternative path, no developer account 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 account, no app setup, 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 16, 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. Access is governed by the Developer Agreement and the restricted use cases listed in X's developer terms, such as surveillance, sensitive-attribute inference, and off-platform identity matching. Staying clearly outside those restrictions and keeping your use case description accurate is the factor you control.

The current getting-access documentation describes no review step: you create a developer account, create an app, and the console generates credentials at app creation. X publishes no approval requirement or completion timeline. Older X developer forum threads describe waits under earlier access processes; treat those as historical.

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.

Surrealist figure in blue reading a book on stepped terrain under orange suns and magenta clouds
Hashtag SearchX API

How to Search Tweets by Hashtag with the X API

Tested X API hashtag queries: how the # operator differs from a plain keyword, combining hashtags, Top versus Latest, filters that work, and cursor pagination.

GetXAPI·
Surreal collage of snow mountains under orange suns and purple clouds on a deep blue field
X API ObjectsTweet Object

X (Twitter) API Object Reference: Tweet and User Fields

Every field on the X API v2 Post and User objects, plus Media, Poll and Place: type, what it holds, the auth it needs, nested keys and enum values.

GetXAPI·
Abstract orange beam descending onto blue mountain terrain, suggesting pushed event delivery
Twitter WebhooksX Activity API

X (Twitter) Webhooks: Setup, the CRC Check and Limits

How X delivers real-time events over webhooks, what the Challenge-Response Check actually asks for, the requirements that silently reject a URL, and the per-tier limits.

GetXAPI·
Abstract blue and orange landscape of monolithic blocks reflected in still water
X API ErrorsTwitter API Error Codes

X (Twitter) API Error Codes: Reference and Retry Rules

X API status codes, error type URIs and the numeric codes behind them, with the cause and the fix for each, plus the partial-error case that returns HTTP 200.

GetXAPI·
Diagnosing Twitter X API 403 Forbidden and 401 Unauthorized errors, with the cause and fix for each
Twitter APIX API

Twitter API 403 Forbidden and 401 Unauthorized: Every Cause and Fix

Why the X API returns 403 Forbidden or 401 Unauthorized, how to tell the two apart, and a fix for each cause. Covers tier gating, app permissions, OAuth, and X error codes.

GetXAPI·
The best Twitter and X API alternatives in 2026 compared across managed APIs, scraping marketplaces, and open-source libraries
Twitter APIX API

The Best Twitter (X) API Alternatives in 2026, Compared

The best Twitter / X API alternatives in 2026, ranked and compared: managed pay-per-call APIs, web-data marketplaces, and open-source libraries, with real per-1,000-tweet costs.

GetXAPI·
How to like a tweet via API in 2026: a single call to the favorite endpoint, no X developer account required
Twitter APIX API

How to Like a Tweet via API in 2026 (No Dev Account)

Like (favorite) tweets programmatically via API in 2026 without an X developer account. The auth_token model, working curl, Python, and Node code, and per-call cost.

GetXAPI·
Best Twitter and X tools of 2026 by category: data APIs, schedulers, analytics, and monitoring
Twitter ToolsX Tools

The Best Twitter/X Tools in 2026, by Category

The best Twitter/X tools of 2026 for creators, marketers, and developers, spanning scheduling, analytics, scraping, monitoring, AI writers, and data APIs.

GetXAPI·

Featured in

Where GetXAPI's data and pricing get cited.

Indie Hackers: The hidden line item in your AI side project: X data
Indie Hackers·Jun 2026

The hidden line item in your AI side project: X data

Indie Hackers post on the often-overlooked cost of X data for AI side projects, citing GetXAPI as the usage-based way to pull live Twitter data without a five-figure X developer contract.

Read on Indie Hackers
Big News Network: How Companies Are Learning to Read Market Mood in Real Time
Big News Network·Jun 2026

How Companies Are Learning to Read Market Mood in Real Time

Editorial feature on Big News Network examining how companies read market mood from X in real time, citing GetXAPI as the usage-based Twitter API that prices live social listening by the call instead of a five-figure annual contract.

Read on Big News Network
Business Newswire: How Companies Are Learning to Read Market Mood in Real Time
Business Newswire·Jun 2026

How Companies Are Learning to Read Market Mood in Real Time

Syndicated feature on Business Newswire on how companies read market mood from X in real time, citing GetXAPI as the usage-based Twitter API that prices live social listening by the call.

Read on Business Newswire
SIIT: Working with Twitter/X Data: A Practical Skill for IT Students and Professionals in 2026
SIIT·Jul 2026

Working with Twitter/X Data: A Practical Skill for IT Students and Professionals in 2026

Guide on SIIT (Scholars International Institute of Technology) on collecting live Twitter/X data as a practical developer skill, citing GetXAPI as the per-call Twitter data API that makes it affordable without an X developer account.

Read on SIIT
Programming Insider: Adding Twitter/X Data to Your App in 2026: A Developer's Integration Guide
Programming Insider·Jul 2026

Adding Twitter/X Data to Your App in 2026: A Developer's Integration Guide

Developer integration guide on Programming Insider covering how to add live Twitter/X data to an app in 2026, comparing the official X API v2 with a key-based REST approach and citing GetXAPI as the low-cost per-call option with no developer-account approval.

Read on Programming Insider
TechBullion: 6 Twitter/X Scraping Solutions for Every Budget
TechBullion·Jul 2026

6 Twitter/X Scraping Solutions for Every Budget

Roundup on TechBullion of the leading Twitter/X scraping solutions, ranking GetXAPI first as the cheapest option at $0.001 per call (about $0.05 per 1,000 tweets) with clean JSON output and no monthly minimum.

Read on TechBullion
SpeakRJ: The Data Bill Behind Every Social Analytics Tool
SpeakRJ·Jun 2026

The Data Bill Behind Every Social Analytics Tool

Editorial piece on SpeakRJ examining the underlying data costs behind social analytics tools, citing GetXAPI as the usage-based way to source live X data by the call.

Read on SpeakRJ
AI Journal: What Is AI Sentiment Analysis, and What Does Each Layer Cost?
AI Journal·Aug 2026

What Is AI Sentiment Analysis, and What Does Each Layer Cost?

Explainer in AI Journal breaking sentiment analysis into its data, model and reporting layers and what each costs to run, citing GetXAPI for pulling public X posts on pay-per-call pricing.

Read on AI Journal
The Silicon Review: Why Enterprise AI Agents Still Cannot Read Social Data
The Silicon Review·Aug 2026

Why Enterprise AI Agents Still Cannot Read Social Data

Analysis piece in The Silicon Review on why enterprise agents reach internal systems easily but struggle with public social data, citing GetXAPI's MCP server and data-as-a-service model as one route to close the gap.

Read on The Silicon Review