npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@twexapi-dev/x-api-scraper

v0.1.3

Published

Twitter API alternative TypeScript SDK for tweet search, follower scraping, timelines, DMs, communities, lists, trending, and X automation. Agent Skills included. Not affiliated with X Corp.

Downloads

547

Readme

TwexAPI TypeScript SDK: Twitter API for search, followers, DMs, communities & X automation

Use the TwexAPI TypeScript SDK to search tweets, scrape Twitter followers, and read X profiles, timelines, replies, and threads. Send DMs, search communities, fetch lists, articles, hashtags, cashtags, and global trending tweets with generated types and agent Skills. Like, retweet, follow, and post through documented REST routes. It is a Twitter API alternative for apps, scripts, and MCP clients.

API Map | REST API | MCP Guide | Dashboard

Speakeasy generates this SDK.

Pi coding agent package

Install the bundled TwexAPI Skills directly from npm:

pi install npm:@twexapi-dev/x-api-scraper

Pi loads the packaged Skills from skills/:

  • x-api-scraper — routing, safety, SDK, and reference files
  • x-api-scraper-research — bounded public research reads

Import the typed SDK from the same npm package.

Common Twitter & X tasks

| Task | REST Route | Usage | | ------------------------------- | -------------------------------------------------- | ----------------------------------------------- | | Search tweets without the X API | POST /twitter/advanced_search/page | Use keyword queries and paginate with a cursor. | | Search hashtags or cashtags | POST /twitter/hashtags, POST /twitter/cashtags | Filter by tag and sort order. | | Read an X profile | GET /twitter/{screen_name}/about | Look up a user by screen name. | | Read a profile timeline | GET /twitter/{screen_name}/timeline/page | Paginate bounded results. | | Scrape Twitter followers | POST /v3/twitter/users/followers | Use the v3 follower list. | | Scrape following accounts | POST /v3/twitter/users/following | Use the v3 following list. | | Read tweet replies | POST /twitter/tweets/{tweet_id}/replies/page | Paginate replies by tweet id. | | Read a tweet thread | POST /twitter/tweets/thread_by_id | Fetch the thread from a root tweet. | | Send or read DMs | /v3/twitter/send-dm, /v3/twitter/dm-history | Use v3 XChat endpoints. | | Search communities | POST /twitter/community/search | Find communities, then load tweets or members. | | Get global trending tweets | GET /twitter/global-trending/tweets | Filter by country, topic, and content. | | Post or reply | POST /twitter/tweets/create | Confirm the account cookie and payload. |

See api.md for the complete API.

AI agent workflows with MCP

Use the typed REST SDK in application code. Add https://api.twexapi.io/mcp to MCP clients. Follow the MCP guide for current authentication support.

Package & registry trust

Installation

Requires a JavaScript runtime with ECMAScript 2020 and fetch. See RUNTIMES.md.

npm install @twexapi-dev/x-api-scraper

pnpm, bun, and yarn also work.

Usage

See api.md for the complete API.

Get an API key from the TwexAPI dashboard. Pass it as bearerAuth, or set X_API_SCRAPER_KEY.

import { XApiScraper } from "@twexapi-dev/x-api-scraper";

const client = new XApiScraper({
  bearerAuth: process.env.X_API_SCRAPER_KEY,
});

const result = await client.search.advanced({
  searchTerms: ["from:elonmusk"],
  sortBy: "Latest",
  nextCursor: "",
});

Look up a profile and paginate followers:

const about = await client.users.getAbout({ screenName: "elonmusk" });

const followers = await client.users.followers.list({
  screenName: "elonmusk",
});

Keep API keys out of source code, URLs, and logs.

Authentication

This SDK uses HTTP Bearer authentication. Set bearerAuth when creating the client.

Write actions (tweet, follow, like, DM send) also need a Twitter cookie or auth_token on the request. Pass them on the operation input.

Request & response types

The package includes types for every request parameter and response field. Import them directly:

import { XApiScraper } from "@twexapi-dev/x-api-scraper";
import type {
  AdvancedSearchCursorQuery,
  AdvancedSearchCursorResponse,
} from "@twexapi-dev/x-api-scraper/models";

const client = new XApiScraper({
  bearerAuth: process.env.X_API_SCRAPER_KEY,
});

const params: AdvancedSearchCursorQuery = {
  searchTerms: ["from:elonmusk"],
  sortBy: "Latest",
  nextCursor: "",
};
const result: AdvancedSearchCursorResponse = await client.search.advanced(params);

Editors show each method, parameter, and field description from its docstring.

Available Resources and Operations

Available methods

Account

Analysis

Articles

  • fetch - Batch Fetch X Articles
  • markdown - Fetch Article as Markdown

Communities

Dm

Lists

Search

Timelines

Trending

Tweets

Tweets.Actions

Tweets.Engagement

Tweets.Replies

  • page - Get Replies by Page

Users

Users.Followers

Users.Following

  • list - Get Following (v3)

Standalone functions

All of the methods above are also exported as standalone functions for tree-shaking. See FUNCTIONS.md.

Handling errors

XAPIScraperError is the base class for HTTP error responses.

import { XApiScraper } from "@twexapi-dev/x-api-scraper";
import * as errors from "@twexapi-dev/x-api-scraper/models/errors";

const client = new XApiScraper({
  bearerAuth: process.env.X_API_SCRAPER_KEY,
});

try {
  await client.search.advanced({
    searchTerms: ["from:elonmusk"],
    sortBy: "Latest",
    nextCursor: "",
  });
} catch (error) {
  if (error instanceof errors.XAPIScraperError) {
    console.log(error.statusCode);
    console.log(error.body);
  } else {
    throw error;
  }
}

| Property | Type | Description | | ------------------- | ---------- | ------------------ | | error.message | string | Error message | | error.statusCode | number | HTTP status code | | error.headers | Headers | Response headers | | error.body | string | Response body | | error.rawResponse | Response | Raw fetch response |

Network errors include ConnectionError, RequestTimeoutError, and RequestAbortedError. Validation failures may throw HTTPValidationError (422).

Retries

Some operations support retries. The SDK uses exponential backoff by default.

Override retries per request:

import { XApiScraper } from "@twexapi-dev/x-api-scraper";

const client = new XApiScraper({
  bearerAuth: process.env.X_API_SCRAPER_KEY,
});

const result = await client.search.advanced(
  {
    searchTerms: ["from:elonmusk"],
    sortBy: "Latest",
    nextCursor: "",
  },
  {
    retries: {
      strategy: "backoff",
      backoff: {
        initialInterval: 1,
        maxInterval: 50,
        exponent: 1.1,
        maxElapsedTime: 100,
      },
      retryConnectionErrors: false,
    },
  },
);

Or set retryConfig on the client for every operation that supports retries.

Timeouts

Set timeoutMs on the client or on one request. Timed-out requests throw RequestTimeoutError.

const client = new XApiScraper({
  timeoutMs: 20 * 1000,
  bearerAuth: process.env.X_API_SCRAPER_KEY,
});

await client.search.advanced(
  {
    searchTerms: ["from:elonmusk"],
    sortBy: "Latest",
    nextCursor: "",
  },
  {
    timeoutMs: 5 * 1000,
  },
);

Server selection

The default server is https://api.twexapi.io. Override it with server: "production" or serverURL.

const client = new XApiScraper({
  serverURL: "https://api.twexapi.io",
  bearerAuth: process.env.X_API_SCRAPER_KEY,
});

Logging

[!WARNING] Debug logs can include API tokens. Use this only during local development.

Pass debugLogger: console to log requests and responses.

const client = new XApiScraper({
  debugLogger: console,
  bearerAuth: process.env.X_API_SCRAPER_KEY,
});

Custom HTTP client

The SDK uses the global fetch function by default.

Polyfill the global to use another fetch implementation:

import fetch from "my-fetch";

globalThis.fetch = fetch;

Or pass an HTTPClient with a custom fetcher:

import { XApiScraper } from "@twexapi-dev/x-api-scraper";
import { HTTPClient } from "@twexapi-dev/x-api-scraper/lib/http";
import fetch from "my-fetch";

const httpClient = new HTTPClient({ fetcher: fetch });
const client = new XApiScraper({
  httpClient,
  bearerAuth: process.env.X_API_SCRAPER_KEY,
});

Fetch options

Pass RequestInit fields on a request without replacing fetch. Request options take precedence.

await client.search.advanced(
  {
    searchTerms: ["from:elonmusk"],
    sortBy: "Latest",
    nextCursor: "",
  },
  {
    headers: {
      "X-Custom-Header": "value",
    },
  },
);

Proxies

Add runtime-specific proxy settings through a custom HTTPClient fetcher.

Node [docs]

import { XApiScraper } from "@twexapi-dev/x-api-scraper";
import { HTTPClient } from "@twexapi-dev/x-api-scraper/lib/http";
import * as undici from "undici";

const proxyAgent = new undici.ProxyAgent("http://localhost:8888");
const httpClient = new HTTPClient({
  fetcher: (input, init) =>
    fetch(input, { ...init, dispatcher: proxyAgent } as RequestInit),
});

const client = new XApiScraper({
  httpClient,
  bearerAuth: process.env.X_API_SCRAPER_KEY,
});

Bun [docs]

import { XApiScraper } from "@twexapi-dev/x-api-scraper";
import { HTTPClient } from "@twexapi-dev/x-api-scraper/lib/http";

const httpClient = new HTTPClient({
  fetcher: (input, init) =>
    fetch(input, { ...init, proxy: "http://localhost:8888" } as RequestInit),
});

const client = new XApiScraper({
  httpClient,
  bearerAuth: process.env.X_API_SCRAPER_KEY,
});

Deno [docs]

import { XApiScraper } from "npm:@twexapi-dev/x-api-scraper";
import { HTTPClient } from "npm:@twexapi-dev/x-api-scraper/lib/http";

const denoHttp = Deno.createHttpClient({
  proxy: { url: "http://localhost:8888" },
});
const httpClient = new HTTPClient({
  fetcher: (input, init) =>
    fetch(input, { ...init, client: denoHttp } as RequestInit),
});

const client = new XApiScraper({
  httpClient,
  bearerAuth: Deno.env.get("X_API_SCRAPER_KEY"),
});

Semantic versioning

This package follows SemVer with these exceptions:

  1. Static type changes that preserve runtime behavior.
  2. Changes to undocumented internals that remain technically public.
  3. Changes unlikely to affect normal use.

Open an issue with questions, bugs, or suggestions.

Runtime support

Supports these runtimes:

  • Current Chrome, Firefox, Safari, Edge, and other web browsers.
  • Maintained Node.js 18 LTS or later.
  • Deno v1.39 or higher.
  • Bun 1.0 or later.
  • Cloudflare Workers.
  • Vercel Edge Runtime.

See RUNTIMES.md for compiler options and runtime notes.

React Native is not supported.

Request another runtime in a GitHub issue.

Contributing

This repository contains generated code. See CONTRIBUTING.md.

To regenerate the Speakeasy input spec:

node --test tests/build-openapi-sdk.test.mjs
node scripts/build-openapi-sdk.mjs openapi.source.json openapi.sdk.json docs/openapi-prep-report.json docs/openapi-prep-report.md

TwexAPI is an independent third-party service. Not affiliated with X Corp. "Twitter" and "X" are trademarks of X Corp.