Open source · All four tools
laravel-cf-workersai
liveCloudflare Workers AI and AI Gateway for the Laravel AI SDK.
laravel-cf-workersai is a Composer driver for laravel/ai, for Laravel developers. Run text, embeddings, reranking, images, speech, transcription, classification and structured extraction on Cloudflare with the same Laravel AI calls you use for any other provider.
Laravel quickstart ↗GitHub ↗prism-workers-ai ↗
composer require meirdick/laravel-cf-workersai
The problem
To call Cloudflare Workers AI directly from PHP, you write your own HTTP client. When you turn on AI Gateway, you keep separate URLs and auth headers. Cloudflare's API default of 256 tokens cuts long answers short. Classification and extraction models need their own parsers.
How it works
- No files to publish. Laravel's package discovery registers the driver when you install it.
- Direct or AI Gateway behind one config. Give
account_idalone to call Workers AI directly. Addgateway, with gateway authentication, to send the same calls through AI Gateway. - Token default fixed, System One models mapped. The driver sets max tokens to 4096, so answers are not cut at 256 tokens. It maps Cloudflare's System One models onto Laravel's own calls: Clef for decisions with probabilities, and Clairic for typed extraction.
Workers AIAI GatewayClefClairic
Coverage
| Capabilities | 8 | text, embeddings, reranking, images, speech, transcription, Clef decisions with probabilities, Clairic extraction |
| laravel/ai versions | 5 | tested from v0.9 to v1.3 |
| Default max tokens | 4096 | Cloudflare's default is 256 |
| prism-workers-ai | Packagist | sibling package, featured on Laravel News |
Install and use
1. Require the package
Laravel discovers it on install.
composer require meirdick/laravel-cf-workersai
2. Add the provider to your Laravel AI config
'workers-ai' => [
'driver' => 'workers-ai',
'key' => env('CLOUDFLARE_AI_API_TOKEN'),
'account_id' => env('CLOUDFLARE_ACCOUNT_ID'),
'gateway' => env('CLOUDFLARE_AI_GATEWAY'), // optional
],
3. Call the Laravel AI SDK as usual
use function Laravel\Ai\agent;
$response = agent('You are a helpful assistant.')
->prompt('Say hi.', provider: 'workers-ai');
Questions
Do I install laravel-cf-workersai or prism-workers-ai?
Install laravel-cf-workersai if your app uses laravel/ai (v0.9 to v1.3). If your app uses Prism, install prism-workers-ai.
Do I rewrite my AI calls to move from direct Workers AI to AI Gateway?
No. Add gateway and gateway authentication to the one config entry. Every existing call then goes through AI Gateway, with no change to application code.
Do Clef and Clairic need a custom Cloudflare API?
No. You use Laravel's standard classification and structured-output methods. The driver maps Clef's answers and probabilities onto Laravel's classification questions, and sends structured schemas to Clairic.
The other tools
Also running coding or personal agents on Cloudflare? See the overview. For the platform gaps, read the RFC.
The lessons across all four tools, and the model behind them.What I learned →