Skip to content

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Twitter Streaming API by ScrapeBadger

Get API key Docs MCP server Pricing

Twitter Streaming API

Get new tweets from X pushed to you as they are posted, without an X developer account or its monthly tiers. With the Twitter Streaming API you create stream monitors that watch up to 100 accounts each, or filter rules that run an X search query on a schedule, and every new tweet arrives as JSON at your webhook (an HTTPS POST signed with HMAC-SHA256) or on a WebSocket at wss://scrapebadger.com/v1/twitter/stream. This repo has a runnable Python, Node.js and cURL example for the main operations.

The create examples change your ScrapeBadger account: a monitor or filter rule starts as soon as you create it and is billed while it runs, so delete the ones you don't need. For the same reason only the read-only calls (query validation and rates) have recorded responses; the docs show the rest.

What does a Twitter streaming API do?

A Twitter streaming API watches X for new tweets that match what you care about, such as posts from a list of accounts or tweets matching a search query, and sends each one to your app as it is found. Traders use it for news and signals, brands for mentions and support, and newsrooms for breaking news. Here you set it up once and receive every new tweet by webhook or WebSocket, without polling search yourself.

Contents

Quick start

  1. Create a free ScrapeBadger account. You get 1,000 free credits, no card needed.

  2. Copy your API key from the dashboard and export it:

    export SCRAPEBADGER_API_KEY="your_api_key"
  3. Make your first request: create a stream monitor.

cURL

curl -sS --max-time 120 -X POST "https://scrapebadger.com/v1/twitter/stream/monitors" \
  -H "X-API-Key: $SCRAPEBADGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "NASA accounts", "usernames": ["NASA", "NASAWebb", "Space_Station"], "webhook_url": "https://example.com/webhooks/tweets", "filter_types": ["original", "quote"]}'

Python (pip install requests)

import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.post(
    "https://scrapebadger.com/v1/twitter/stream/monitors",
    headers={"X-API-Key": API_KEY},
    json={"name": "NASA accounts", "usernames": ["NASA", "NASAWebb", "Space_Station"], "webhook_url": "https://example.com/webhooks/tweets", "filter_types": ["original", "quote"]},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js (18+, no dependencies)

const response = await fetch('https://scrapebadger.com/v1/twitter/stream/monitors', {
  method: 'POST',
  headers: { 'X-API-Key': process.env.SCRAPEBADGER_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'NASA accounts', usernames: ['NASA', 'NASAWebb', 'Space_Station'], webhook_url: 'https://example.com/webhooks/tweets', filter_types: ['original', 'quote'] }),
  signal: AbortSignal.timeout(120000),
});
if (!response.ok) {
  throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
console.log(JSON.stringify(await response.json(), null, 2));

Every endpoint below has the same three versions in examples/, and the real response it returned is in output-samples/.

Endpoints

Base URL: https://scrapebadger.com. Authenticate with the X-API-Key header. Credits are charged only for successful requests.

Endpoint What it returns Credits per request Docs
POST /v1/twitter/stream/monitors Create stream monitor Free Docs
GET /v1/twitter/stream/monitors List stream monitors Free Docs
GET /v1/twitter/stream/monitors/{monitor_id} Get stream monitor Free Docs
PATCH /v1/twitter/stream/monitors/{monitor_id} Update stream monitor Free Docs
DELETE /v1/twitter/stream/monitors/{monitor_id} Delete stream monitor Free Docs
POST /v1/twitter/stream/webhooks Configure webhook on a monitor Free Docs
GET /v1/twitter/stream/webhooks List webhooks Free Docs
DELETE /v1/twitter/stream/webhooks/{webhook_id} Remove webhook from monitor Free Docs
GET /v1/twitter/stream/billing-logs List billing logs Free Docs
POST /v1/twitter/stream/webhooks/test Test webhook delivery Free Docs
POST /v1/twitter/stream/filter-rules Create filter rule Free Docs
GET /v1/twitter/stream/filter-rules List filter rules Free Docs
GET /v1/twitter/stream/filter-rules/{rule_id} Get filter rule Free Docs
PATCH /v1/twitter/stream/filter-rules/{rule_id} Update filter rule Free Docs
DELETE /v1/twitter/stream/filter-rules/{rule_id} Delete filter rule Free Docs
POST /v1/twitter/stream/filter-rules/validate Validate search query Free Docs
GET /v1/twitter/stream/filter-rules-pricing Get filter rule per-poll rates Free Docs

Common parameters

Parameter Description Default
page Page number on list endpoints (monitors, filter rules, billing logs), starting at 1. 1
page_size Items per page on list endpoints. 20

Examples by endpoint

Each example prints the JSON response. The Python versions are below; Node.js and cURL versions are linked under each one.

Create a stream monitor

Create a new stream monitor to watch Twitter accounts in real-time. The monitor starts right away and is billed per account per day while it is active. Pause it with the update example or remove it with the delete example.

POST /v1/twitter/stream/monitors · Credits: Free · Docs

Parameter Required Type Default Description
name Yes string Your label for the monitor, e.g. NASA accounts
usernames Yes array X handles to watch, without @, up to 100 per monitor
webhook_url string HTTPS URL that receives a POST for every new tweet (optional; you can use the WebSocket instead)
webhook_secret string Secret used to sign webhook deliveries. If you leave it out, one is generated and returned once.
filter_types array Tweet types to deliver, any of original, reply, retweet, quote (default all)
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.post(
    "https://scrapebadger.com/v1/twitter/stream/monitors",
    headers={"X-API-Key": API_KEY},
    json={"name": "NASA accounts", "usernames": ["NASA", "NASAWebb", "Space_Station"], "webhook_url": "https://example.com/webhooks/tweets", "filter_types": ["original", "quote"]},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL

Validate a filter query

Validate a Twitter search query string. Check a query's syntax before you create a rule. Nothing is created and nothing is billed.

POST /v1/twitter/stream/filter-rules/validate · Credits: Free · Docs

Parameter Required Type Default Description
query Yes string An X search query, with operators such as from:, to:, lang:, -is:retweet, has:media and OR
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.post(
    "https://scrapebadger.com/v1/twitter/stream/filter-rules/validate",
    headers={"X-API-Key": API_KEY},
    json={"query": "(NASA OR Artemis) lang:en -is:retweet"},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (1 KB)

Create a filter rule

Create a new query-based tweet filter rule. The rule starts right away and every check is billed. Remove it with DELETE /v1/twitter/stream/filter-rules/{rule_id}. Up to 50 rules per API key.

POST /v1/twitter/stream/filter-rules · Credits: Free · Docs

Parameter Required Type Default Description
tag Yes string Your label for the rule, unique per API key, e.g. NASA mentions
query Yes string An X search query, with operators such as from:, to:, lang:, -is:retweet, has:media and OR
interval_seconds Yes number How often the query is checked, from 0.1 to 86400 seconds. Each check is billed, see Pricing.
max_results_per_poll integer 20 Most tweets returned by one check, up to 20
webhook_url string HTTPS URL that receives a POST for every new tweet (optional; you can use the WebSocket instead)
webhook_secret string Secret used to sign webhook deliveries. If you leave it out, one is generated and returned once.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.post(
    "https://scrapebadger.com/v1/twitter/stream/filter-rules",
    headers={"X-API-Key": API_KEY},
    json={"tag": "NASA mentions", "query": "(NASA OR Artemis) lang:en -is:retweet", "interval_seconds": 60, "max_results_per_poll": 20, "webhook_url": "https://example.com/webhooks/tweets"},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL

List your stream monitors

List all stream monitors for the authenticated API key.

GET /v1/twitter/stream/monitors · Credits: Free · Docs

Parameter Required Type Default Description
status string Only return monitors or rules with this status, e.g. active or paused
page integer 1 Page number, starting at 1
page_size integer 20 Items per page
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/twitter/stream/monitors",
    headers={"X-API-Key": API_KEY},
    params={
        "status": "active",
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL

Get a stream monitor

Get a single stream monitor by ID.

GET /v1/twitter/stream/monitors/{monitor_id} · Credits: Free · Docs

Parameter Required Type Default Description
monitor_id Yes string ID of the monitor, returned when you create it
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

monitor_id = "YOUR_MONITOR_ID"

response = requests.get(
    f"https://scrapebadger.com/v1/twitter/stream/monitors/{monitor_id}",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL

Pause or change a monitor

Partially update a stream monitor. A paused monitor stops billing. Send {"status": "active"} to resume it, or change usernames, webhook_url or filter_types the same way.

PATCH /v1/twitter/stream/monitors/{monitor_id} · Credits: Free · Docs

Parameter Required Type Default Description
monitor_id Yes string ID of the monitor, returned when you create it
name string Your label for the monitor, e.g. NASA accounts
usernames array X handles to watch, without @, up to 100 per monitor
status string Only return monitors or rules with this status, e.g. active or paused
webhook_url string HTTPS URL that receives a POST for every new tweet (optional; you can use the WebSocket instead)
webhook_secret string Secret used to sign webhook deliveries. If you leave it out, one is generated and returned once.
filter_types array Tweet types to deliver, any of original, reply, retweet, quote (default all)
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

monitor_id = "YOUR_MONITOR_ID"

response = requests.patch(
    f"https://scrapebadger.com/v1/twitter/stream/monitors/{monitor_id}",
    headers={"X-API-Key": API_KEY},
    json={"status": "paused"},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL

Delete a monitor

Delete a stream monitor and all its logs.

DELETE /v1/twitter/stream/monitors/{monitor_id} · Credits: Free · Docs

Parameter Required Type Default Description
monitor_id Yes string ID of the monitor, returned when you create it
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

monitor_id = "YOUR_MONITOR_ID"

response = requests.delete(
    f"https://scrapebadger.com/v1/twitter/stream/monitors/{monitor_id}",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2) if response.content else response.status_code)

Node.js · cURL

List your filter rules

List all filter rules for the authenticated API key.

GET /v1/twitter/stream/filter-rules · Credits: Free · Docs

Parameter Required Type Default Description
status string Only return monitors or rules with this status, e.g. active or paused
page integer 1 Page number, starting at 1
page_size integer 20 Items per page
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/twitter/stream/filter-rules",
    headers={"X-API-Key": API_KEY},
    params={
        "status": "active",
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL

Add a webhook to a monitor

Configure a webhook delivery URL on a stream monitor. The signing secret is returned only in this response. A monitor has one webhook; delete the old one before you add another.

POST /v1/twitter/stream/webhooks · Credits: Free · Docs

Parameter Required Type Default Description
monitor_id Yes string ID of the monitor, returned when you create it
url Yes string HTTPS URL that receives the webhook POSTs
secret string Secret used to sign webhook deliveries. If you leave it out, one is generated and returned once.
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.post(
    "https://scrapebadger.com/v1/twitter/stream/webhooks",
    headers={"X-API-Key": API_KEY},
    json={"monitor_id": "YOUR_MONITOR_ID", "url": "https://example.com/webhooks/tweets"},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL

Send a test webhook

Sends a test payload (type is test) to the monitor's webhook URL and returns the delivery result, so you can check your receiver and signature check before real tweets arrive.

POST /v1/twitter/stream/webhooks/test · Credits: Free · Docs

Parameter Required Type Default Description
monitor_id Yes string ID of the monitor, returned when you create it
import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.post(
    "https://scrapebadger.com/v1/twitter/stream/webhooks/test",
    headers={"X-API-Key": API_KEY},
    json={"monitor_id": "YOUR_MONITOR_ID"},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL

Get filter rule rates

The current filter rule rates, in credits for a check that finds nothing and per tweet a check returns.

GET /v1/twitter/stream/filter-rules-pricing · Credits: Free · Docs

import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/twitter/stream/filter-rules-pricing",
    headers={"X-API-Key": API_KEY},
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (1 KB)

Example output

A real response from POST /v1/twitter/stream/filter-rules/validate, trimmed to the first items of each list. The full response is in output-samples/validate-query.json.

{
  "valid": true,
  "query": "(NASA OR Artemis) lang:en -is:retweet",
  "error": null
}

Use it with AI agents (MCP)

ScrapeBadger runs a hosted MCP server, so Claude, Cursor, ChatGPT and other agents can call the Twitter/X endpoints as tools, with no code.

  • Claude (claude.ai or Claude Desktop): Settings → Connectors → Add custom connector → https://mcp.scrapebadger.com/mcp, then sign in. No API key needed.
  • Cursor, VS Code, Windsurf and other clients: add this server to your MCP config:
{
  "mcpServers": {
    "scrapebadger": {
      "url": "https://mcp.scrapebadger.com/mcp?apis=twitter",
      "headers": { "Authorization": "Bearer YOUR_SCRAPEBADGER_API_KEY" }
    }
  }
}

Then ask:

Create a ScrapeBadger filter rule that watches for tweets mentioning NASA's Artemis mission in English, checked every 5 minutes, and tell me what it will cost per day.

Setup guides for each client are in the MCP docs.

Use cases

Use case What you collect Endpoints
News and trading signals Every new tweet from a list of official, company or market accounts, on your webhook or WebSocket Create a stream monitor, List your stream monitors, Pause or change a monitor
Brand and keyword monitoring New tweets that match a search query, such as your brand without retweets Validate a filter query, Create a filter rule, List your filter rules
Alerts and support Mentions and replies sent to your webhook, to route into Slack, a ticket system or a database Add a webhook to a monitor, Send a test webhook
Cost planning The current per-check rates, to choose a rule's interval before you create it Get filter rule rates

Pricing

Streaming is billed while a monitor or rule runs, not per request; credits are deducted every 60 seconds.

  • Stream monitors cost credits per watched account per day, cheaper per account as the monitor grows: 1,111 credits for 1 to 6 accounts, 889 from 7, 667 from 21, 444 from 51 and 222 from 501 accounts. The Twitter Streaming API page shows the current rates.

  • Filter rules cost 0.8 credits for a check that finds nothing and 1 credit per tweet a check returns. Every returned tweet is charged, also one an earlier check already returned (it's delivered only once), so a rule's daily cost is checks per day times credits per check. GET /v1/twitter/stream/filter-rules-pricing returns the current rates.

  • When your balance gets low, active monitors and rules pause with status_reason: "insufficient_credits" and resume after you top up.

  • Creating, listing, changing and deleting monitors, rules and webhooks is free; you pay while a monitor or rule runs.

  • New accounts get 1,000 free credits. After that, pay as you go or pick a monthly plan. Credits on pay-as-you-go never expire.

See ScrapeBadger pricing for the price per credit on each plan.

Errors

Errors come back as JSON with a detail field (and an error code on some).

Status Meaning What to do
400 / 422 A parameter is missing or invalid Check the parameter table for the endpoint
401 Missing, invalid or expired API key Send the key in the X-API-Key header
402 Out of credits Top up or upgrade in the dashboard
403 The key can't call this API, or the request came from an IP the key doesn't allow Check the key's scopes and IP allowlist
404 The item, page or profile doesn't exist (or is no longer public) Check the ID; not billed
429 Over your account's max concurrency Wait Retry-After (1 s) and retry; run fewer calls in parallel (concurrency)
502 / 503 / 504 The target site failed or timed out on this attempt Not billed. Retry with backoff

Long calls can run asynchronously: send Prefer: respond-async and poll the returned request_id (async requests).

FAQ

How do tweets reach me?

By webhook, WebSocket or both. A webhook gets an HTTPS POST per tweet with an X-Signature-256 HMAC-SHA256 header; answer 2xx within 10 seconds, and failed deliveries are retried up to 3 times with backoff. On the WebSocket (wss://scrapebadger.com/v1/twitter/stream, key in the x-api-key header) every monitor and rule of the key arrives on one connection, up to 5 connections per key; reply to each ping with {"type": "pong"}. Tweets aren't stored or replayed, so keep your own log.

What's the difference between a stream monitor and a filter rule?

A stream monitor watches specific accounts (up to 100 per monitor) and delivers their tweets, replies, retweets and quotes, billed per account per day. A filter rule runs any X search query at the interval you choose (up to 50 rules per key), billed per check. Use monitors for fixed account lists and rules for keywords, hashtags and mentions.

How much does it cost?

Monitors cost credits per account per day and filter rules cost credits per check; see Pricing. You get 1,000 free credits when you sign up, then pay as you go or pick a plan on the pricing page.

Is it legal to monitor Twitter/X?

The API delivers public tweets that anyone can see on X. Collecting public data is generally lawful in most jurisdictions, but tweets contain personal data, so check the rules that apply to how you store and use them (for example GDPR), and ask a lawyer if you're unsure. Protected accounts are not available.

Can I get tweets I missed while my server was down?

Webhook deliveries are retried, WebSocket messages are not. To fill a gap, search the window you missed with the Twitter Scraper API (for example from:NASA since:2026-12-01); those calls are billed as normal requests.

Other languages

These examples use plain HTTP. Official SDKs wrap every endpoint with types and retries:

Language Repository Install
Python scrape-badger/scrapebadger-python pip install scrapebadger
Node.js / TypeScript scrape-badger/scrapebadger-node npm install scrapebadger
Go scrape-badger/scrapebadger-go
Java scrape-badger/scrapebadger-java
C# scrape-badger/scrapebadger-csharp
PHP scrape-badger/scrapebadger-php
Ruby scrape-badger/scrapebadger-ruby
Rust scrape-badger/scrapebadger-rust
Kotlin scrape-badger/scrapebadger-kotlin
Swift scrape-badger/scrapebadger-swift
Dart scrape-badger/scrapebadger-dart
C++ scrape-badger/scrapebadger-cpp

There is also a CLI (pip install scrapebadger-cli) and an n8n node.

Related scrapers

Learn more

Disclaimer

ScrapeBadger is an independent tool and is not affiliated with, endorsed by, or in any way officially connected with X Corp. (formerly Twitter, Inc.) or any of its subsidiaries or affiliates. The names Twitter, X, and related trademarks are the property of their respective owners, used here only to describe the platform this scraper works with. This repository only covers publicly available data. You are responsible for how you use the data you collect and for following the laws that apply to you.

License

MIT. The examples are free to copy into your own projects.