A Cloudflare Workers AI provider for Laravel AI
Cloudflare Workers AI in Laravel, with Clef and Clairic.
Run the Laravel AI code you already write on the models Cloudflare hosts: text, embeddings, reranking, images, speech, transcription, Clef decisions and Clairic typed extraction, directly or through AI Gateway.
composer require meirdick/laravel-cf-workersaiAnswers, not generated text
Clef and Clairic are System One models. They don’t generate text. They read your input in one pass and return typed answers with probabilities, so you have nothing to parse.
Clef decides among options you list.
use Laravel\Ai\Classification;
use Laravel\Ai\Classification\Boolean;
$response = Classification::of($ticket)
->question('urgent', new Boolean('Urgent?'))
->classify(provider: 'workers-ai');
$response['urgent']->isTrue();Clairic extracts a value of the type you ask for, or null.
use Meirdick\WorkersAi\Extraction;
use Meirdick\WorkersAi\Extraction\Number;
$invoice = Extraction::of($text)
->field('total', new Number(unit: 'USD'))
->extract();
$invoice['total']->value();All of Laravel AI
Text, tools, embeddings, reranking, images, speech and transcription, with the Laravel AI code you already write.
Direct or gateway
One config key adds AI Gateway logs, caching and rate limits, and your calling code stays the same.
Cloudflare failures handled
A token cap, an exception on an empty answer, retries for edge errors, and neuron figures.
Needs PHP 8.3 and laravel/ai 0.9 to 1.3, and Clef needs laravel/ai 1.0 or later. MIT license.