How to Search for Tweets Using an API: Complete Guide with Code Examples
Searching for tweets programmatically is one of the most valuable capabilities a developer can have. Whether you need to build a social listening dashboard, run sentiment analysis on brand mentions, or extract Twitter data for market research - it all starts with a reliable tweet search API. In this guide, you will learn how to search tweets using the Sorsa API (/v3/search-tweets), master advanced query operators for precise data extraction, and build production-ready scripts in Python and JavaScript that handle pagination, filtering, and error handling.
Sorsa API is a developer-friendly alternative to the official X (formerly Twitter) API. It provides read-only access to public X data with simple API-key authentication, no OAuth flow, and no approval process. If you have ever struggled with Twitter API rate limits, pricing tiers, or the complexity of getting approved - Sorsa gives you the same search power with a fraction of the setup.
Why Search Tweets Programmatically?
The X (Twitter) search bar is great for casual browsing, but it falls short when you need to collect data at scale, apply complex filters, or integrate tweet data into your own applications. A tweet search API unlocks use cases that manual searching simply cannot handle: Social listening and brand monitoring. Track what people say about your company, product, or competitors across the entire platform. Instead of refreshing a search tab, you get structured JSON data delivered straight to your pipeline - ready for dashboards, alerts, or analysis. Market research and trend analysis. Identify emerging conversations in any niche - crypto, AI, finance, health, gaming. By combining keyword search with engagement filters (like minimum likes or retweets), you can surface the signal from the noise and spot trends before they hit mainstream. Sentiment analysis. Feed tweet text into NLP models to gauge public opinion on a topic, product launch, or event. The search API gives you the raw text and engagement metrics; your model does the rest. Lead generation and sales intelligence. Find people asking for recommendations, complaining about a competitor, or looking for solutions your product offers. A well-crafted search query is essentially a lead magnet. Academic and journalistic research. Researchers and journalists regularly need to collect public discourse around events, policies, or social phenomena. A programmable search endpoint makes this repeatable and auditable.The Search Tweets Endpoint: Request and Parameters
To search for tweets with Sorsa API, send a POST request to:ApiKey: YOUR_API_KEY (case-sensitive). No Bearer tokens, no OAuth dance.
Request Body (JSON)
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Your search keywords. Supports all native X search operators. |
order | string | No | "popular" (default) - matches the “Top” tab in X search. "latest" - chronological, newest first. |
next_cursor | string | No | Pagination cursor from a previous response. Omit on the first request. |
Minimal cURL Example
Understanding the Response
The API returns a JSON object with two fields: an array of tweet objects and a pagination cursor.tweets array comes with the full text, all engagement metrics (likes, retweets, replies, quotes, views, bookmarks), language tag, and the complete profile of the author embedded in the user object. This means a single API call gives you both content data and author data - no need for a second request to look up who posted the tweet.
The next_cursor string is your key to pagination. When it is present, more results are available. When it is null or absent, you have reached the end.
For a full breakdown of every field in the Tweet and User objects, see Response Format.
Advanced Query Operators: Precision Search for X Data
Thequery field is not just a keyword box. It supports the full range of native X search operators, giving you the same filtering power as the search bar on x.com - and more, because you can combine them programmatically.
Keywords and Phrases
artificial intelligence- matches tweets containing ANY of these words"artificial intelligence"- matches the EXACT phrase onlyAI machine learning- matches tweets containing both “AI” and one of “machine”/“learning”
User-Based Operators
from:elonmusk- tweets posted by a specific accountto:openai- tweets replying to a specific account@sorsa_app- tweets mentioning a specific account
Engagement Filters (Minimum Thresholds)
min_faves:100- only tweets with at least 100 likesmin_retweets:50- only tweets with at least 50 retweetsmin_replies:10- only tweets with at least 10 replies
crypto min_faves:500 will surface only the most engaged-with crypto tweets - perfect for trend analysis or influencer discovery.
Content Filters
filter:links- only tweets containing URLsfilter:media- only tweets with images or videosfilter:images- only tweets with imagesfilter:videos- only tweets with videos-filter:replies- exclude replies (show only original tweets)-filter:retweets- exclude retweets-filter:links- exclude tweets with links (useful for removing bot/spam content)
Language and Date Range
lang:en- only English tweets (use any ISO 639-1 code:es,fr,de,ja, etc.)since:2026-01-01- tweets posted on or after this dateuntil:2026-03-01- tweets posted before this date
Exclusion and Boolean Logic
crypto -scam -airdrop- search for “crypto” but exclude tweets containing “scam” or “airdrop”(bitcoin OR ethereum) min_faves:100 lang:en- English tweets about bitcoin or ethereum with 100+ likes
Real-World Query Examples
Here are practical query strings for common use cases: Brand monitoring:For the complete list of available operators, see our Search Operators Reference.
Pagination: How to Collect Thousands of Tweets
A single search request returns one page of results (typically around 20 tweets). To collect larger datasets - hundreds or thousands of tweets - you use cursor-based pagination. The logic is straightforward:- First request: Send your query and order. Do not include
next_cursor. - Read the cursor: The response contains a
next_cursorstring. - Next request: Send the same query, same order, but add the
next_cursorvalue you just received. - Repeat until
next_cursorisnull, empty, or absent - that means you have fetched all available results.
For a deep dive into pagination patterns, see Pagination.
Code Examples: Python and JavaScript
Below are production-ready scripts that search for tweets, handle pagination automatically, and collect results into a usable data structure. Both examples use the correct POST method and response keys.Python: Search and Paginate
JavaScript (Node.js): Search and Paginate
Full Working Example: Export Tweet Search Results to CSV
A common pipeline is: search tweets, paginate through results, then export everything to a CSV file for analysis in Excel, Google Sheets, or a data science notebook. Here is a complete Python script that does exactly that.max_pages to control how deep you scrape. At roughly 20 tweets per page, max_pages=50 will give you around 1,000 tweets.
Tips for Effective Tweet Searching
Start withorder: "popular" for research, switch to "latest" for monitoring. The popular sort surfaces high-engagement content - great for trend analysis and finding influencers. The latest sort gives you chronological data - essential for real-time alerts and complete data collection within a time window.
Use engagement filters to cut through noise. Searching for a broad keyword like "AI" will return millions of results, most of them low-effort posts. Adding min_faves:10 or min_retweets:5 dramatically improves signal quality without losing important content.
Combine -filter:replies with -filter:retweets for original content only. When you want to analyze what people are actually saying (not just reacting to), this combo strips away noise and gives you only original tweets.
Add lang:xx directly in the query string. If your analysis or LLM pipeline expects English text, always include lang:en in the query. This is more reliable than filtering post-hoc, because the API handles language detection on its side.
Respect rate limits. Sorsa API allows 20 requests per second per API key. The time.sleep(0.1) in the examples above keeps you well within this limit. For high-volume scraping jobs, see Rate Limits for throttling strategies.
Use date ranges for historical analysis. Combine since: and until: operators to search within a specific window - great for studying reactions to events, product launches, or campaigns.
Sorsa Search vs. Other Twitter/X Data APIs
If you have worked with the official X API v2, you know the pain: OAuth 2.0 setup, developer portal approval, limited search history (7 days on Basic, 30 on Pro), and pricing that starts at $100/month and quickly climbs to thousands. Sorsa API simplifies this dramatically:- No OAuth. A single API key in a header. You can be making search requests within 60 seconds of signing up.
- No approval process. Create an account, get your key, start searching.
- Full search operator support. Every operator that works in the X search bar works in the Sorsa
queryfield. - Consistent response format. Every tweet comes with all engagement metrics and full author profile. No need to specify
tweet.fieldsorexpansions. - Simple POST-based interface. No URL parameter length limits. Your complex Boolean queries go safely in the JSON body.
Next Steps
- Search Operators Reference - full list of Boolean operators and filters you can use in the
queryfield. - Search Mentions Guide - track direct @mentions of any account with the dedicated
/mentionsendpoint and its rich filter set. - Pagination - deep dive into cursor-based pagination for large-scale data collection.
- Response Format - complete schema reference for Tweet and User objects.
- API Reference - full specification for all 38 Sorsa API endpoints.