Quick answer
The X (Twitter) API v2 recent search endpoint returns posts from the last seven days with an app-only bearer token created in the developer console (console.x.com). Since February 2026, new developers pay per use with prepaid credits.
X (Twitter) API at a glance
- Pricing
- Pay per use (credits)
- Availability
- Worldwide
- Paper trading
- Not applicable (data only)
- Integration type
- REST + API key
- In AlgoGP
- Design and backtest in AlgoGP, connect the exported code
- Endpoint
GET /2/tweets/search/recent(last 7 days)- Auth
- App-only
Authorization: Bearer <token> - Pricing
- Pay-per-use credits, bought in the developer console
- Used by
filters.sentimentwith sourcesocial
How social sentiment is scored
data_sources.recent_posts(query) asks for up to 100 recent English posts that match news_query, excluding reposts, and the same lexicon scorer as news turns them into a daily score. Recent search only reaches back seven days and X has no archive to replay, so social sentiment is used by live.py only; backtests run without it.
Use X (Twitter) API in AlgoGP
X (Twitter) API is read by the generated data_sources.py. Turn it on from config.json under filters.sentiment. In-app backtests replay news and sentiment from dated, keyless archives, so a key, if any, is only used when the exported live.py runs; store it in the project’s Keys & secrets or a local .env.
| Key | What it is |
|---|---|
TWITTER_BEARER_TOKEN | X (Twitter) API v2 bearer token for the sentiment filter (source "social"); live only. |
.env.New to X (Twitter) API? Follow the step-by-step X (Twitter) API API key guide.
X (Twitter) API: frequently asked questions
Is the X API free?
Not for reading posts at useful volumes. New developers use pay-per-use credits; set a spending cap in the console.
Can I backtest years of X sentiment?
Not with recent search, which covers seven days. Full-archive search is a separate, more expensive product.
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.
X (Twitter) API alternatives
Independent guide. AlgoGP is not affiliated with X (Twitter) API. Limits, prices and availability change; confirm them in the official documentation. Nothing here is investment advice.