Search by

darvis / api-x

darvis

Post to X (Twitter) from Laravel: posts with an image, replies and your mentions through the X API v2, a setup wizard, artisan commands and an MCP server so Claude and other AI agents can post and reply for you.

v1.4.0 2026-09-28 06:49 UTC

This package is auto-updated.

Last update: 2026-09-28 06:51:58 UTC


README

Latest Version Tests PHP License

A Laravel package that posts short updates, with one optional image, to X (formerly Twitter) through the X API v2, reads the posts that mention you and replies to them. Call it from PHP, from the command line, or let an AI agent such as Claude do it through a local MCP server. No SDK: every call goes through Laravel's built-in HTTP client.

Unofficial and independent: this is not an official X product and is not affiliated with X Corp.

Features

  • A setup wizard, php artisan x:install, that explains every step and writes .env
  • One call to post a text with a JPEG, PNG, GIF or WebP image, from a local path or a URL
  • php artisan x:post for scripts and the terminal
  • Read the posts that mention your account (x:mentions) and reply to them (--reply-to)
  • A local MCP server with post-update and list-mentions tools, registered when laravel/mcp is installed
  • A page to post from the browser with the history of every post, when Livewire and Flux are installed
  • Checks the text the way X counts it before anything is sent or billed, up to 25,000 characters for accounts with an X subscription
  • Refuses links by default, because X bills posts with a link at a much higher rate
  • A daily limit and a dry run mode, so an agent cannot run up a bill
  • Ships a Laravel Boost guideline and skill

Requirements

  • PHP 8.2 or higher
  • Laravel 11, 12 or 13
  • An X developer app with Read and Write permissions and API credit
  • laravel/mcp 1.0 or higher for the MCP server (Laravel Boost installs it)
  • livewire/livewire and livewire/flux (free edition) for the page

Installation

composer require darvis/api-x

Run the setup wizard. It explains how to create the X app, writes the four OAuth 1.0a keys of your own account to .env, checks them with X, sets the safety limits and adds the MCP server:

php artisan x:install

Or put the keys in .env yourself:

X_CONSUMER_KEY=your-consumer-key
X_CONSUMER_SECRET=your-consumer-secret
X_ACCESS_TOKEN=your-access-token
X_ACCESS_TOKEN_SECRET=your-access-token-secret

Installation & configuration has every step and every config key.

Quick start

php artisan x:post "Working on something new" --image=storage/app/screenshot.png --dry-run
use Darvis\ApiX\XClient;

$result = app(XClient::class)->post('Working on something new', storage_path('app/screenshot.png'));

$result->url(); // https://x.com/i/web/status/...

Read who mentioned you and answer one of them:

$mention = app(XClient::class)->mentions(limit: 5)[0];

app(XClient::class)->post('Thanks, glad it helps!', replyTo: $mention->id);

For an AI agent, add php artisan mcp:start x as a stdio MCP server. See the MCP server and Mentions and replies pages.

Documentation

The full documentation is at arviddejong.github.io/api-x.

Changelog

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md.

Security

See SECURITY.md.

License

MIT. See LICENSE.