The Search API

The Twitter Search API is part of Twitter’s REST API. It allows queries against the indices of recent or popular Tweets and behaves similarly to, but not exactly like the Search feature available in Twitter mobile or web clients, such as search. The Twitter Search API searches against a sampling of recent Tweets published in the past 7 days.

Before getting involved, it’s important to know that the Search API is focused on relevance and not completeness. This means that some Tweets and users may be missing from search results. If you want to match for completeness you should consider using a Streaming API instead.

A detailed reference on this API endpoint can be found at GET search/tweets.

How to build a query

The best way to build a query and test if it’s valid and will return matched Tweets is to first try it at As you get a satisfactory result set, the URL loaded in the browser will contain the proper query syntax that can be reused in the API endpoint. Here’s an example:

  1. We want to search for Tweets referencing @twitterapi account. First, we run the search on
  2. Check and copy the URL loaded. In this case, we got:
  3. Replace “” with “” and you will get:
  4. Execute this URL to do the search in the API

Please note that the API requires that the request be authenticated (check Authentication & Authorization documentation for more details on this). Also note that the search results at may return historical results, while the Search API usually only serves Tweets from the past week.

Query operators

The query can have operators that modify its behavior. the available operators are:

Operator Finds Tweets...
watching now containing both “watching” and “now”. This is the default operator.
“happy hour” containing the exact phrase “happy hour”.
love OR hate containing either “love” or “hate” (or both).
beer -root containing “beer” but not “root”.
#haiku containing the hashtag “haiku”.
from:interior sent from Twitter account “interior”.
list:NASA/astronauts-in-space-now sent from a Twitter account in the NASA list astronauts-in-space-now
to:NASA a Tweet authored in reply to Twitter account “NASA”.
@NASA mentioning Twitter account “NASA”.
politics filter:safe containing “politics” with Tweets marked as potentially sensitive removed.
puppy filter:media containing “puppy” and an image or video.
puppy -filter:retweets containing “puppy”, filtering out retweets
puppy filter:native_video containing “puppy” and an uploaded video, Amplify video, Periscope, or Vine.
puppy filter:periscope containing “puppy” and a Periscope video URL.
puppy filter:vine containing “puppy” and a Vine.
puppy filter:images containing “puppy” and links identified as photos, including third parties such as Instagram.
puppy filter:twimg containing “puppy” and a link representing one or more photos.
hilarious filter:links containing “hilarious” and linking to URL.
puppy url:amazon containing “puppy” and a URL with the word “amazon” anywhere within it.
superhero since:2015-12-21 containing “superhero” and sent since date “2015-12-21” (year-month-day).
puppy until:2015-12-21 containing “puppy” and sent before the date “2015-12-21”.
movie -scary :) containing “movie”, but not “scary”, and with a positive attitude.
flight :( containing “flight” and with a negative attitude.
traffic ? containing “traffic” and asking a question.

Please, make sure to URL encode these queries before making the request. There are several online tools to help you to do that, or you can search at and copy the encoded URL from the browser’s address bar. The table below shows some example mappings from search queries to URL encoded queries:

Search query URL encoded query
#haiku #poetry %23haiku+%23poetry
“happy hour” :) %22happy%20hour%22%20%3A%29

Note that the space character can be represented by “%20” or “+” sign.

Additional parameters

There is a set of additional parameters that allows a better control of the search results. The GET search/tweets documentation has detailed information about the usage of the parameters, this section will only give a brief description of their capabilities:

  • Result Type: just like results, the result_type parameter selects whether the result set will be represented by recent or popular Tweets, or even a mix of both.
  • Geolocalization: the search operator “near” isn’t available in the API, but there is a more precise way to restrict your query by a given location using the geocode parameter specified with the template “latitude,longitude,radius”, for example, “37.781157,-122.398720,1mi”. When conducting geo searches, the search API will first attempt to find Tweets which have lat/long within the queried geocode, and in case of not having success, it will attempt to find Tweets created by users whose profile location can be reverse geocoded into a lat/long within the queried geocode, meaning that is possible to receive Tweets which do not include lat/long information.
  • Language: the lang parameter restricts Tweets to the given language.
  • Iterating in a result set: parameters such count, until, since_id, max_id control iteration through search results, since it could be a large set of Tweets. The Working with Timelines documentation is a rich and illustrative tutorial to learn how to use these parameters to achieve the best efficiency and reliability when processing result sets.

Rate limits

The GET search/tweets endpoint is rate limited similarly to other methods. See REST API Rate Limiting for information on that model.

Best practices

  • Ensure all parameters are properly URL encoded.
  • Limit your searches to 10 keywords and operators.
  • Queries can be limited due to complexity. If this happens, the Search API will respond with the error: {"error":"Sorry, your query is too complex. Please reduce complexity and try again."}.
  • The Search API is not complete index of all Tweets, but instead an index of recent Tweets. The index includes between 6-9 days of Tweets.

Example searches

When you are following an event that’s currently happening, you would be interested in search for recent Tweets using the event hashtag:

When you want to know what Tweets are coming from a specific location, with a specific language: