Engineering

How to Get an X (Twitter) API Key in 2026: Keys, Tokens, Costs

An X API key is really four sets of credentials. Here is how to get them from the Developer Console, which one you need to post for users, and what every request costs.

How to Get an X (Twitter) API Key in 2026: Keys, Tokens, Costs

To get an X (Twitter) API key, sign in at console.x.com with your X account, accept the Developer Agreement, create an app, and copy the credentials it generates. There is no free tier to wait for and no application essay: you get keys in minutes, but every request is billed against prepaid credits. What trips people up is that "the API key" is one of four credential sets, and the one you need to post on behalf of other people is the OAuth 2.0 client ID and secret, not the API key at all.

TL;DR

  • Sign up at console.x.com, accept the Developer Agreement, click New App. Credentials are shown once, so save them immediately.
  • An X app has four credential sets: API key and secret (OAuth 1.0a consumer keys), Bearer token (app-only, public reads), access token and secret (your own account), and OAuth 2.0 client ID and secret (users who connect to your product).
  • To read public data, use the Bearer token. To post as yourself, use your access token and secret. To post for your customers, use OAuth 2.0 Authorization Code with PKCE.
  • OAuth 2.0 access tokens last two hours. Request offline.access to get a refresh token, or your users reconnect every two hours.
  • The X API is pay-per-use: $0.015 per post created, $0.20 if it contains a URL, $0.005 per post read. Full breakdown in our X API pricing guide.
  • 401 means bad or regenerated credentials. 403 means valid auth but no access (wrong scope, app not enrolled). 429 means a rate limit or usage cap.
  • Outstand connects X accounts with OAuth 2.0 PKCE, but X is bring-your-own-key: you register the X app and X bills your credits.

Do you still need a Twitter developer account?

Yes, but it no longer looks like the Twitter developer account of 2022. There is no tiered application, no Elevated access to request, and no Free, Basic or Pro plan for new signups. X's Getting Access guide is three steps: sign in to the Developer Console with your X account, accept the Developer Agreement and Policy, and fill in a short profile describing how you will use the API.

The access model is credit-based. Per X's pricing page, you buy credits up front in the console, set a spending limit, and X deducts credits in real time per request. There are no subscriptions or minimums. If the balance hits zero, requests are blocked until you top up.

New accounts can earn one-time starting credits (up to $70, expiring after three months, still rolling out) per X's free credit incentives page. Don't plan a launch around them.

The full rate card and tier history are in X API pricing in 2026.

How to get a Twitter API key, step by step

  1. Sign in at console.x.com with the X account that should own the app, ideally a company account.
  2. Accept the Developer Agreement and complete the profile.
  3. Click New App. Enter a name, description and use case.
  4. Generate the credentials you need. The console shows them once. Paste them straight into a password manager or secrets vault.
  5. Open the app's User authentication settings if you will act on behalf of users. Enable OAuth 2.0, pick the app type, and add your callback URLs.
  6. Buy credits under Billing and set a spending limit before you make the first call.

Make a test call with the Bearer token to confirm the app works:

bash
1curl "https://api.x.com/2/users/by/username/xdevelopers" \
2  -H "Authorization: Bearer $X_BEARER_TOKEN"

It is billed as a User read: a cent, not nothing.

The four X API credentials and what each one is for

X's Apps documentation lists four credential sets, all on one Keys and tokens page.

Credential

Also called

Auth method

Use it for

API key and secret

Consumer key and secret

OAuth 1.0a

Identifying your app, signing OAuth 1.0a requests, minting a Bearer token

Bearer token

App-only access token

OAuth 2.0 app-only

Reading public data: search, user lookup, timelines

Access token and secret

User tokens

OAuth 1.0a user context

Acting as the account that owns the app

Client ID and secret

OAuth 2.0 credentials

OAuth 2.0 Authorization Code with PKCE

Acting on behalf of users who connect to your product

API key and secret (consumer keys)

X describes the API key and secret as the username and password of your app. On their own they don't let you post anything. They sign OAuth 1.0a requests and can be exchanged for other credentials, such as a Bearer token. It is what most people mean by "twitter api key", and rarely the one they need.

Bearer token

The Bearer token is app-only authentication, based on the OAuth 2.0 client credentials grant. There is no current user, so per X's app-only auth docs it cannot post, read DMs or fetch a user's email. It is the right choice for searching posts, looking up users and reading public timelines. If you lose it, you can mint a new one from your consumer keys:

bash
1curl -u "$X_API_KEY:$X_API_SECRET" \
2  --data 'grant_type=client_credentials' \
3  'https://api.x.com/oauth2/token'

Access token and secret

OAuth 1.0a user tokens for the account that owns the app. The fastest way to build a personal bot, and useless for anyone else's account.

OAuth 2.0 client ID and secret

What a product serving many X accounts needs. X recommends OAuth 2.0 for new projects: it has fine-grained scopes and is required for v2 user-context endpoints. The app type decides whether you get a secret:

  • Web App and Automated App or Bot are confidential clients and receive a client secret.
  • Native App and Single Page App are public clients and rely on PKCE only.

If your token exchange runs on a server, pick Web App.

Which credential do you need?

You want to

Use

Search posts or look up public profiles

Bearer token

Post from your own account with a script

Access token and secret (OAuth 1.0a), or OAuth 2.0 with your own login

Post, reply or DM for your customers' accounts

OAuth 2.0 Authorization Code with PKCE

OAuth 2.0 with PKCE: posting on behalf of users

In outline:

  1. Generate a random code verifier and its SHA-256 code challenge.
  2. Redirect the user to https://x.com/i/oauth2/authorize with response_type=code, your client_id, redirect_uri, scope, a random state, code_challenge and code_challenge_method=S256.
  3. X sends the user back to your callback with a code. Verify state.
  4. POST the code and the original verifier to https://api.x.com/2/oauth2/token. Confidential clients authenticate with HTTP Basic auth using the client ID and secret.
bash
1curl -X POST https://api.x.com/2/oauth2/token \
2  -u "$X_CLIENT_ID:$X_CLIENT_SECRET" \
3  -H "Content-Type: application/x-www-form-urlencoded" \
4  --data-urlencode "grant_type=authorization_code" \
5  --data-urlencode "code=$CODE" \
6  --data-urlencode "redirect_uri=https://yourapp.com/x/callback" \
7  --data-urlencode "code_verifier=$CODE_VERIFIER"

The response carries an access_token, expires_in, the granted scope, and a refresh_token if you asked for offline.access. Per X's PKCE reference, the access token is valid for two hours, and without offline.access no refresh token is issued. Refresh with grant_type=refresh_token on the same endpoint. Always store the refresh token from the latest response rather than reusing the first one.

Scopes

Request only what you use. The common ones for a publishing or engagement product:

Scope

Grants

tweet.read

Posts the user can view

tweet.write

Post and repost for the user

users.read

Accounts the user can view, including their own profile

media.write

Upload media

offline.access

A refresh token, so the connection survives past two hours

follows.read

Followers and following

dm.read / dm.write

Read and send Direct Messages

tweet.moderate.write

Hide and unhide replies

Changing scopes later means users must re-authorize to get tokens with the new scope. DMs carry their own rules and costs, covered in our X DM API guide.

Callback URLs

From X's callback URL rules: the URL must match the allowlist exactly, including trailing slashes; an app can hold at most 10 callback URLs; production must use https://; and local development must use http://127.0.0.1, not localhost. A mismatch returns error code 415, "Callback URL not approved for this client application."

Regenerating and rotating keys

Open the app in the Developer Console, go to Keys and tokens, and click Regenerate next to the credential. Regeneration invalidates the old value immediately, so deploy the new one before or right after you rotate. Bearer tokens and access tokens can also be invalidated programmatically through X's invalidate_token endpoints, per the authentication best practices.

For confidential OAuth 2.0 clients, the token refresh authenticates with the client secret, so if you rotate it, update every service that refreshes tokens at the same time.

Common X API errors and what they mean

X returns a type URI, title and detail in error bodies. See the response codes page.

Status

Typical cause

Fix

401 Unauthorized

Wrong auth method for the endpoint, malformed Authorization header, regenerated keys, expired two-hour OAuth 2.0 token

Check you are sending the right credential type; refresh the user token

403 Forbidden, client-forbidden

App not enrolled or lacking access for the endpoint

Check the app's project and plan in the console

403 Forbidden, missing scope

User token lacks the scope, e.g. posting without tweet.write

Re-run OAuth with the right scopes

429 Too Many Requests

Rate limit or usage cap hit

Wait until x-rate-limit-reset, back off exponentially

A classic first-day failure: the OAuth consent screen works, then the first publish fails with a 403. Our X configuration docs note that a brand-new developer app may not be enrolled on POST /2/tweets, which returns client-not-enrolled. Consent succeeding proves your client ID is valid, not that the app can post.

Rate limits

Credits cap spend; rate limits cap speed. Responses carry x-rate-limit-remaining and x-rate-limit-reset. From X's rate limits page today:

Endpoint

Per app

Per user

POST /2/tweets

10,000 / 24 h

100 / 15 min

GET /2/tweets/search/recent

450 / 15 min

300 / 15 min

The per-app posting limit is shared by every account connected to your app, so a scheduler with many customers on one app should track it alongside the per-user window.

What posting costs

The rates that matter for most twitter integrations, from X's pricing page as of today:

Operation

Price

Post: Create

$0.015 per request

Post: Create (with URL)

$0.200 per request

Post: Create (summoned reply)

$0.010 per request

Interaction: Delete

$0.010 per request

Media Metadata

$0.005 per request

Posts: Read

$0.005 per post returned

User: Read

$0.010 per user returned

So twitter api fees for a thousand plain posts come to $15, and the same thousand posts with links come to $200. Reads are deduplicated per UTC day. Owned Reads at $0.001 apply only when the authenticated user owns the developer app, which a multi-tenant product usually does not. For worked monthly examples and the reply restrictions introduced in 2026, see X API pricing.

Keeping X credentials secure

  • Keep secrets and the Bearer token server-side, never in a mobile app, browser bundle or public repo. X notes bots scrape repos for keys.
  • If a key was ever committed, regenerate it. Deleting it from the latest commit leaves it in history.
  • Encrypt user access and refresh tokens at rest and restrict who can read the table.
  • Use separate apps for development, staging and production, as X recommends.
  • Set a spending limit. On pay-per-use, a leaked key is also a billing incident.
  • Request the minimum scopes. A scheduler does not need dm.read.

How Outstand connects X accounts

X is bring-your-own-key. Outstand runs managed OAuth apps for most networks, but not for X. You register your own X app, enable OAuth 2.0 with the callback https://www.outstand.so/app/api/socials/x/callback, and add its client ID and secret to Outstand, in the dashboard or with the API:

bash
1curl -X POST https://api.outstand.so/v1/social-networks \
2  -H "Authorization: Bearer YOUR_API_KEY" \
3  -H "Content-Type: application/json" \
4  -d '{
5    "network": "x",
6    "client_key": "YOUR_X_CLIENT_ID",
7    "client_secret": "YOUR_X_CLIENT_SECRET"
8  }'

Because the app is yours, X bills your credits, and customers see your app on the consent screen.

What Outstand handles. The OAuth 2.0 Authorization Code flow with PKCE (S256 challenge, signed state, server-side code exchange with your client secret), default scopes of tweet.read, tweet.write, users.read, follows.read, dm.write, media.write and offline.access, token refresh five minutes before the two-hour expiry, chunked media upload, threads, polls and alt text. You can override the scope list when generating the auth URL, for example to add dm.read for DMs.

Once an account is connected, publishing is one request. The accounts array takes the account ID returned by GET /v1/social-accounts:

bash
1curl -X POST https://api.outstand.so/v1/posts \
2  -H "Authorization: Bearer YOUR_API_KEY" \
3  -H "Content-Type: application/json" \
4  -d '{
5    "containers": [
6      { "content": "Shipping notes for v2.3 are out." },
7      { "content": "Biggest change: scheduled posts now retry on 5xx." }
8    ],
9    "accounts": ["YOUR_X_SOCIAL_ACCOUNT_ID"],
10    "scheduledAt": "2026-12-08T15:00:00Z"
11  }'

Each container after the first is published as a reply to the previous one, so this creates a two-post thread. See the X configuration guide for details.

When Outstand is not the better choice. If you only post to X, from one account, a script with your own access token is simpler and avoids another dependency. Outstand earns its place when X is one of several networks, or when you would otherwise build token storage, refresh, media upload and webhooks yourself.

FAQ

Is the X API free in 2026?

No. It is pay-per-use with prepaid credits, and every request, including reads, draws down the balance. See X API pricing.

What is the difference between the X API key and the Bearer token?

The API key and secret identify your app and sign OAuth 1.0a requests. The Bearer token is an app-only token minted from them for reading public data. Neither can post for another user.

Which credentials do I need to post tweets for my users?

The OAuth 2.0 client ID and secret, used in the Authorization Code flow with PKCE, with at least tweet.write, tweet.read, users.read and offline.access. Add media.write to attach images or video.

Why do my X access tokens stop working after two hours?

OAuth 2.0 access tokens expire after two hours. Request offline.access and use the refresh token; without it, users must log in again.

Why do I get a 403 when the OAuth login worked?

Usually the token is missing a scope, or the app is not enrolled for the endpoint, which X reports as client-forbidden or client-not-enrolled. Check the app's settings in the Developer Console.

Does X need app review like Meta or TikTok?

No formal review before your first post, unlike Meta and TikTok. You accept the Developer Agreement and pay as you go. Our approval guide by platform compares the process across networks, and the Instagram API key and YouTube API key guides cover the other two in this series.

Wrapping up

Getting an X API key takes minutes; the OAuth, refresh and billing work around it takes longer. If X is one of several networks you need to post to, Outstand handles the OAuth flow and publishing once you add your X app's keys, and the same POST /v1/posts call reaches every other connected network.