Search
Search tweets, users, media, and more across Twitter. Most of these support Search operators.
search.tweets(query, opts?)
Search for tweets (Top results). Uses the GraphQL SearchByRawQuery query with product: "Top".
| Option | Type | Description |
|---|---|---|
query | string | Search query (supports Twitter search operators) |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.querySource | string | Query source (default "typed_query") |
opts.product | string | Override the product type (default "Top") |
opts.withMediaGridTweet | boolean | Return media results as grid tweets (default false) |
opts.ads | boolean | Keep promoted tweets (default false) |
opts.variables | object | Additional GraphQL variables |
Search results can contain ads. They are left out unless you pass opts.ads, see Ads.
const { tweets, nextCursor } = await client.search.tweets("javascript");
// With search operators
const { tweets: elonTweets } = await client.search.tweets("from:elonmusk AI");
// Paginate
const page2 = await client.search.tweets("javascript", { cursor: nextCursor });search.latest(query, opts?)
Search for tweets sorted by latest (chronological). Uses the GraphQL SearchByRawQuery query with product: "Latest".
| Option | Type | Description |
|---|---|---|
query | string | Search query |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.querySource | string | Query source (default "typed_query") |
opts.variables | object | Additional GraphQL variables |
const { tweets } = await client.search.latest("breaking news");search.users(query, opts?)
Search for user profiles. Uses the GraphQL SearchByRawQuery query with product: "People".
| Option | Type | Description |
|---|---|---|
query | string | Search query |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.querySource | string | Query source (default "typed_query") |
opts.variables | object | Additional GraphQL variables |
const { users } = await client.search.users("elon");search.media(query, opts?)
Search for tweets containing media (images, videos, GIFs). Uses the GraphQL SearchByRawQuery query with product: "Media".
| Option | Type | Description |
|---|---|---|
query | string | Search query |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.querySource | string | Query source (default "typed_query") |
opts.variables | object | Additional GraphQL variables |
const { tweets } = await client.search.media("cute cats");search.lists(query, opts?)
Search for Twitter lists. Uses the GraphQL listsSearchQuery query. Results are in lists.
| Option | Type | Description |
|---|---|---|
query | string | Search query |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const { lists } = await client.search.lists("tech news");search.postList(query, opts?)
Search tweets with the lighter selection x.com uses for embedded post lists. Uses the GraphQL postListQuery query.
search.typeaheadGraphql(query, opts?)
Get search box suggestions through GraphQL. Uses the globalSearchTypeaheadQuery query. Pass { cashtag: true } to include tickers.
const { items } = await client.search.typeaheadGraphql("nasa");search.mentionTypeahead(query, opts?) / search.tagPeopleTypeahead(query)
Suggest users to @mention in the composer, or to tag in a photo. Both return parsed users.
search.hashtagTypeahead(query, opts?)
Suggest hashtags. Returns strings like "#NASA".
search.recentUsers(userIds)
Get the users behind your recent searches by ID. Uses the GraphQL recentSearchesUsersQuery query.
search.typeahead(query, params?)
Get typeahead/autocomplete suggestions. Uses the v1.1 search/typeahead endpoint. Returns events, users, topics, and lists matching the query.
| Param | Type | Description |
|---|---|---|
query | string | Search query |
params.src | string | Source context (default "search_box") |
params.result_type | string | Types to return (default "events,users,topics,lists") |
const suggestions = await client.search.typeahead("elon");
console.log(suggestions.users);
console.log(suggestions.topics);search.communities(query, opts?)
Search for posts within communities globally. Uses the GraphQL topCommunitiesPostSearchQuery query.
| Option | Type | Description |
|---|---|---|
query | string | Search query |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const { tweets } = await client.search.communities("web development");search.communitiesLatest(query, opts?)
Search for the latest posts within communities globally. Uses the GraphQL latestCommunitiesPostSearchQuery query.
| Option | Type | Description |
|---|---|---|
query | string | Search query |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const { tweets } = await client.search.communitiesLatest("open source");search.gifs(query, params?)
Search for GIFs via the v1.1 foundmedia/search endpoint. Returns GIF items with thumbnail, preview, and original image URLs.
| Param | Type | Description |
|---|---|---|
query | string | Search query |
params.cursor | string | Pagination cursor |
Response:
| Field | Type | Description |
|---|---|---|
items | array | Array of GIF items |
cursor | string? | Cursor for the next page, or null |
Each item in items has:
| Field | Type | Description |
|---|---|---|
id | string | Unique item ID (e.g. "giphy_04DMYESomjb6BCBNB8") |
item_type | string | Always "gif" |
provider | object | Provider info (name, display_name - e.g. "giphy", "riffsy" for Tenor) |
url | string | Canonical URL of the GIF |
alt_text | string | Alt text / description |
original_image | object | Full-size image (url, width, height, byte_count, still_image_url) |
preview_image | object | Preview image (same shape as original_image) |
thumbnail_images | array | Array of thumbnail images (same shape as original_image) |
const { items, cursor } = await client.search.gifs("funny cat");
console.log(items[0].original_image.url); // GIF URL
console.log(items[0].alt_text); // "Funny Cat GIF"
console.log(items[0].provider.name); // "giphy" or "riffsy" (Tenor)
// Paginate
const page2 = await client.search.gifs("funny cat", { cursor });search.gifSearch(query, opts?)
Search GIFs through GraphQL, which is what the x.com composer uses now. Uses the gifPickerButtonQuery query. Items come back as Twitter sends them, so the provider ID is in provider.id and not provider.name like in search.gifs.
| Param | Type | Description |
|---|---|---|
query | string | Search query |
opts.variables | object | Additional GraphQL variables |
Response: { items, cursor, raw }. The query returns one page of about 50 items, so cursor is null.
const { items } = await client.search.gifSearch("cat");
console.log(items[0].id, items[0].full_image.url);search.gifCategory(category?, opts?)
List the GIFs of a category through GraphQL. The category defaults to "trending", which goes through gifPickerButtonQuery like the first screen of the x.com GIF picker. Other categories use the legacy GifEnumerateCategory query, which the web client no longer calls. The options and response match search.gifSearch.
const { items } = await client.search.gifCategory();search.cashtags(query, opts?)
Search stock and crypto tickers, as in the cashtag autocomplete on x.com. Uses the GraphQL cashtagTypeaheadQuery query. Each suggestion has an asset with smart_tag (such as "$TSLA"), name, logo_url and a quote with price, market cap and 24 hour change. Prices are split into units and nanos.
| Param | Type | Description |
|---|---|---|
query | string | Ticker or company name |
opts.count | number | Number of suggestions (default 20) |
opts.exact | boolean | Only the exact ticker, through cashtagAttachmentsExactMatchQuery |
opts.variables | object | Additional GraphQL variables |
const [first] = await client.search.cashtags("TSLA");
const { price } = first.asset.quote;
console.log(first.asset.smart_tag, Number(price.units) + price.nanos / 1e9);search.adaptive(query, params?)
Perform an "adaptive search" via the v2 API. Uses the v2 search/adaptive endpoint. Returns raw search results with full tweet and user objects.
Warning
This hasn't been fully tested yet and may have some quirks. It also doesn't support all the operators and features of the normal GraphQL search.
Using the normal search methods over this one is recommended for most use cases unless you have a specific reason for needing to use v2 search or want to experiment with it.
| Param | Type | Description |
|---|---|---|
query | string | Search query |
params.count | number | Number of results (default 20) |
params.query_source | string | Query source (default "typed_query") |
params.pc | number | Promoted content flag (default 1) |
params.spelling_corrections | number | Enable spelling corrections (default 1) |
const results = await client.search.adaptive("machine learning", { count: 50 });Full example
// Search tweets with different modes
const { tweets: top } = await client.search.tweets("React vs Vue");
const { tweets: latest } = await client.search.latest("React vs Vue");
const { tweets: mediaTweets } = await client.search.media("React vs Vue");
// Search for users
const { users: devs } = await client.search.users("javascript developer");
// Get autocomplete suggestions
const suggestions = await client.search.typeahead("type");
// Search for GIFs
const { items: gifs, cursor: gifCursor } = await client.search.gifs("celebration");
console.log(gifs[0].original_image.url);
// Search with the v2 adaptive endpoint
const adaptive = await client.search.adaptive("web development", { count: 30 });
// Search within communities
const { tweets: communityResults } = await client.search.communities("open source");
// Advanced search with operators
const { tweets: advanced } = await client.search.tweets(
'from:github "open source" min_faves:100 lang:en since:2025-01-01',
);
// Paginate through results
let cursor;
for (let i = 0; i < 5; i++) {
const page = await client.search.tweets("javascript", { count: 20, cursor });
// process page.tweets...
cursor = page.nextCursor;
if (!cursor) break;
}
// Find lists about a topic
const { tweets: listResults } = await client.search.lists("machine learning");