darvis / api-x
Post to X (Twitter) from Laravel: posts with an image through the X API v2, a setup wizard, an artisan command and an MCP server so Claude and other AI agents can post 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-24 09:39:04 UTC
README
A Laravel package that posts short updates, with one optional image, to X (formerly Twitter) through the X API v2. Call it from PHP, from the command line, or let an AI agent such as Claude post for you 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- A local MCP server with a
post-updatetool, 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
- 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/...
For an AI agent, add php artisan mcp:start x as a stdio MCP server. See the
MCP server page.
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.