Before you start
- An X account with a verified email (and phone)
- A payment method for pay-per-use credits
Create your X (Twitter) API API key
- 1
Open the developer console
Sign in at console.x.com with your X account and accept the developer agreement, describing your use case (e.g. market sentiment research).
- 2
Create a Project and an App
Create a Project, then an App inside it. Name them after the bot (e.g.
algogp-sentiment). - 3
Generate the bearer token
Open the App’s Keys and tokens tab and generate the Bearer Token (app-only authentication). Copy it now; it is not shown again.
- 4
Add credits and a limit
In billing, buy a small amount of credits and set a monthly spending limit so a runaway loop cannot overspend.
Test the key
Before wiring the key into a strategy, make one request by hand. It separates “the key is wrong” from “my code is wrong”.
curl -s -H "Authorization: Bearer $TWITTER_BEARER_TOKEN" \
"https://api.x.com/2/tweets/search/recent?query=bitcoin%20-is:retweet&max_results=10"data array of posts means the token works. 401 is a bad token; 402/403 points to credits or access level.Add the key to your AlgoGP project
- 1
Open your project’s APIs & keys tab
Open the strategy project and select APIs & keys in the workspace tabs.
- 2
Paste each value
Paste the values into
TWITTER_BEARER_TOKENand click Save. Values are encrypted at rest, never shown again and never written into code or exports. - 3
Run locally with the same names
Exported projects read the same names from
.env(copy.env.example). Keep.envout of version control.
TWITTER_BEARER_TOKEN=paste-your-value-hereToken safety
A bearer token can spend your credits. Keep it in AlgoGP Keys & secrets (stored as TWITTER_BEARER_TOKEN) or .env, and regenerate it from the same tab if it leaks.
Frequently asked questions
Do I need the API key and secret, or just the bearer token?
For reading public posts, only the bearer token. The consumer key/secret and user tokens are for acting on behalf of an account.
Add X (Twitter) API signals to a strategy
Combine price rules with news and sentiment filters, test them point-in-time so nothing leaks from the future, and export the code.
- Sentiment filters that block entries on bad news
- Point-in-time replay in every backtest
- Exported Python reads the same feed live
Free plan, no card required.
AlgoGP is not affiliated with X (Twitter) API. Menus get renamed from time to time; if a label differs, the official documentation has the current path.