DEV Community

Dal
Dal

Posted on

AI Agents Using X (Twitter) Without API or Browser — Introducing x-use

Persian Version (نسخه فارسی):

• Read on Substack: استفاده هوش مصنوعی و ایجنت‌ها از ایکس (توییتر) بدون نیاز به API و مرورگر

• Read on Dev.to: نسخه فارسی در Dev.to

• Read on Telegra.ph: Instant View (Persian)

GitHub Repository: github.com/dalroot/x-use

License: MIT

Stack: Node.js (Pure HTTPS + GraphQL)


1. The Problem: Why Browser Automation Bottlenecks AI Agents

Connecting AI coding agents (such as Antigravity, Claude Code, or Cursor) to X (formerly Twitter) usually forces developers into one of two painful paths:

  1. Restrictive & Expensive Official APIs: Write-capable API tiers come with strict quotas and high monthly costs.
  2. Heavy Headless Browsers: Tools like Puppeteer and Playwright spin up a full Chromium instance — burning 400 MB+ of RAM per run, adding seconds of cold-start latency, and breaking whenever DOM selectors change.

x-use (xuse / agent-x-use) eliminates both bottlenecks. It is a modular Node.js CLI and SDK that communicates directly with X's GraphQL endpoints over pure https — zero Chromium, zero Puppeteer, zero Playwright, and no official API key required.


2. Modular, Zero-Browser Architecture

Everything in x-use runs over Node's built-in https stack, keeping execution in milliseconds even on low-RAM headless servers:

  • src/auth.js — Resolves auth_token and ct0 from exported browser cookies, environment variables, or ~/.x-use/config.json.
  • src/transport.js — Pure HTTPS transport, optional SOCKS5 / HTTP proxy normalization, and GraphQL error inspection (catching data.errors even on HTTP 200).
  • src/operations/tweets.js — createTweet, replyTweet, postThread, deleteTweet, favoriteTweet, and retweet.
  • src/operations/users.js — getProfile, getUserTweets, and searchTweets.
  • bin/x-use.js — Dual-mode CLI: an interactive parent menu (xuse) for humans, plus deterministic --json output for AI agents.

3. Built Agent-First (--json + SKILL.md)

x-use ships with a ready-to-use SKILL.md so AI agents can immediately operate X without scraping HTML:

# Verify session & proxy connectivity
xuse check --json

# Fetch user profile metadata
xuse profile jack --json

# Publish a single tweet without a browser
xuse tweet "Posted without a browser via x-use" --json

# Publish a full thread from a JSON array
xuse thread ./thread.json --json
Enter fullscreen mode Exit fullscreen mode

Every --json command returns a predictable contract:

{
  "ok": true,
  "data": {
    "tweetId": "2126363786189615433",
    "url": "https://x.com/dallsirvan/status/2126363786189615433"
  }
}
Enter fullscreen mode Exit fullscreen mode

4. Authentication Without an API Key

Instead of an API key, x-use uses your valid X session cookies (auth_token and ct0). You can configure them once via the interactive parent CLI:

xuse setup --cookies ./cookies.json --proxy socks5h://127.0.0.1:10808
Enter fullscreen mode Exit fullscreen mode

Or pass them directly as environment variables (X_AUTH_TOKEN and X_CT0).


5. Quick Start (CLI & Node.js SDK)

git clone https://github.com/dalroot/x-use.git
cd x-use
npm install
npm link   # optional: exposes `xuse`, `x-use`, and `agent-x-use` globally
Enter fullscreen mode Exit fullscreen mode

Using it inside Node.js:

const { XUseClient } = require('x-use');

(async () => {
  const client = new XUseClient({
    cookiesPath: './cookies.json',
    // proxyUrl: 'socks5h://127.0.0.1:10808' // optional
  });

  await client.init();
  const post = await client.createTweet('Hello from x-use!');
  console.log(post.url);
})();
Enter fullscreen mode Exit fullscreen mode

Links & Persian Edition

Top comments (0)