Skip to content
cheapxapi

How to get a Twitter API key.

There are two routes. The official one: create a developer account in the X Developer Console, create an app, and save the API key and secret, bearer token and access tokens it generates. They are shown once, and requests need prepaid credits.

The quicker one: sign up with a third-party X API and copy a single key, which works in one request header.

The two routes, step by step.

Official X API

4 steps · 4 kinds of credentials · credits before the first call

  1. Create a developer account

    Sign in to the X Developer Console (console.x.com) with your X account, accept the Developer Agreement and Policy, and describe how you will use the API.

  2. Create an app

    Choose New App and enter a name, description and use case. The console generates the app’s credentials.

  3. Save the credentials

    Copy every key and token straight away: the console shows each one once. Losing one means regenerating it, which invalidates the old value.

  4. Buy credits

    The X API is pay-per-use, so requests need prepaid credits in the console before they succeed.

cheapxapi

3 steps · 1 key · $1 to try

  1. Sign up

    Use Google or an email address. No card, no application form.

  2. Copy the key

    The dashboard shows your key once, on your first visit. New accounts get a $1 promotional credit, subject to automated abuse checks.

  3. Send it as a header

    Put the key in the x-api-key header of each request.

Get your API key

Which official credential you actually need.

The console hands you several credentials at once. For reading public data, the bearer token is the only one you send. The others matter when you sign requests or act as a user.

X API credentials and what each is for
CredentialWhat it doesUse it for
API key and secretIdentify your app. Used to generate tokens and to sign OAuth 1.0a requests.Signing requests, minting tokens
Bearer tokenApp-only access to public data.Searching posts, looking up users, trends
Access token and secretAct as the account that owns the app (OAuth 1.0a).Testing, personal bots
Client ID and secretOAuth 2.0 for acting on behalf of other users, with scopes.Posting, liking, following, DMs for your users

Source: X developer documentation, “Getting access”.

Your first request with each key.

The same lookup, NASA’s profile, on both. The official API charges $0.010 per user returned; cheapxapi charges $0.0006 per request.

Official X API · bearer token

curl "https://api.x.com/2/users/by/username/NASA" \
  -H "Authorization: Bearer $BEARER_TOKEN"

cheapxapi · x-api-key

curl "https://api.cheapxapi.com/twitter/user/info?userName=NASA" \
  -H "x-api-key: YOUR_KEY"

Fields returned: Get user profile.

Keep the key safe.

  • Read it from an environment variable. Never hardcode a key in source code.
  • Keep it out of git. Add credential files to .gitignore, and check history before making a repository public.
  • Never put it in a URL. URLs end up in logs and browser history. cheapxapi rejects keys sent as query parameters.
  • Rotate it when in doubt. Generating a new cheapxapi key stops the old one at once; regenerating X credentials invalidates the old values.

Questions.

Is a Twitter API key free?

Creating an X developer account, an app and its keys costs nothing. Using them does: the X API is pay-per-use, so requests draw on credits you buy first. A cheapxapi key is also free and comes with a $1 promotional credit, subject to automated abuse checks.

What is the difference between the API key and the bearer token?

The API key and secret identify your app and are used to create tokens and sign OAuth 1.0a requests. The bearer token is what you actually send for app-only requests that read public data, in the Authorization header.

Where do I find my X API key and secret?

In the X Developer Console, under the app you created. They are displayed only when generated, so if you did not save them you have to regenerate them, which makes the old values stop working.

Do I need a developer account to use the X API?

For the official API, yes: keys come from an app in your developer account. Third-party APIs such as cheapxapi issue their own key on signup and need no X developer account.

Wondering what the official key costs to use? Is the X API free?