Keys / X
TWITTER_BEARER_TOKEN
The app-only Bearer Token your app sends as Authorization: Bearer <token> to read public data from the X API.
- Expires
- never; it works until you regenerate or invalidate it
- API
- create with the API key and secret; invalidate with OAuth 1.0a
Get it
Create one on console.x.com. The steps aren't recorded yet.
Set it
TWITTER_BEARER_TOKEN=...
No official SDK reads it on its own. X's Java SDK names TWITTER_BEARER_TOKEN in its README, but your app passes it in; the Python and TypeScript XDKs take it as bearer_token and bearerToken. Or keep it out of .env with keypin: keypin run -- npm run dev
Replace it
- An app has one Bearer Token at a time, and a new one stops the old one. Plan for a short gap.
- In the Developer Console, open the app's Keys and tokens and click Regenerate next to the Bearer Token. X shows it once. Or call
POST oauth2/invalidate_token, thenPOST oauth2/token. - Deploy it everywhere that reads
TWITTER_BEARER_TOKEN. Requests with the old token fail until then.
Set rotate_every on the key in keypin.toml and a rotated date on its vault item, and keypin status shows when it's due.
Sources, checked 2026-11-16
- X: Using and generating an app-only Bearer Token
- X: App only authentication and OAuth 2.0 Bearer Token
- X: Authentication best practices, regenerate API keys and tokens
- X: OAuth API reference (oauth2/token, oauth2/invalidate_token)
- X: Developer Console
- X Ads API: step-by-step guide, keys and tokens don't expire
- twitter-api-java-sdk: names TWITTER_BEARER_TOKEN
- xdk-python: bearer_token option
- xdk-typescript: bearerToken option