darvis / api-x
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.
Requires
- php: ^8.2
- laravel/framework: ^11.0|^12.0|^13.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/mcp: ^1.0
- laravel/pint: ^1.0
- livewire/flux: ^2.11
- livewire/livewire: ^3.7.4|^4.0
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
- phpunit/phpunit: ^11.0|^12.0|^13.0
Suggests
- laravel/mcp: Required for the local MCP server that lets AI agents post (^1.0).
- livewire/flux: Required for the page to post and see the history (^2.11, the free edition is enough).
- livewire/livewire: Required for the page to post and see the history (^3.7.4 or ^4.0).
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-28 06:51:58 UTC
README
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:postfor 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-updateandlist-mentionstools, registered whenlaravel/mcpis 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/mcp1.0 or higher for the MCP server (Laravel Boost installs it)livewire/livewireandlivewire/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.