meirdick/laravel-cf-workersai is a Cloudflare Workers AI provider for the Laravel AI SDK. Install it, add a workers-ai entry to config/ai.php, and your Laravel AI calls run on the models Cloudflare hosts: text, embeddings, reranking, images, speech, transcription, Clef decisions and Clairic typed extraction. You can call Cloudflare directly or route through AI Gateway.
What you can do
| Task | API | Default model |
|---|---|---|
| Generate text, call tools, stream | agent() |
@cf/meta/llama-3.3-70b-instruct-fp8-fast |
| Create embeddings | Embeddings::for() |
@cf/baai/bge-large-en-v1.5 |
| Answer typed questions about an input | Classification::of(), Str::decide() |
@cf/cloudflare/clef |
| Read or predict typed values from an input | Extraction::of() |
@cf/cloudflare/clairic |
| Order documents by relevance | Reranking::of() |
@cf/baai/bge-reranker-base |
| Generate images | Image::of() |
@cf/black-forest-labs/flux-2-klein-4b |
| Turn text into speech | Audio::of() |
@cf/deepgram/aura-2-en |
| Turn audio into text | Transcription::of() |
@cf/openai/whisper-large-v3-turbo |
| Read PDF, Word and Excel files | Markdown::of(), convert_documents |
Cloudflare’s /ai/tomarkdown |
| Search the web from a tool call | CloudflareWebSearch |
Cloudflare’s Web Search API |
Clef works through Laravel AI’s own classification API. Laravel AI has no API for Clairic, so the package adds one, Extraction. See Clef and Clairic.
What the package adds
Laravel AI’s openai-compatible driver can call a Cloudflare URL. That’s enough if you only generate text with one model and every agent sets #[MaxTokens]. This package also:
- Sends a 4096 token cap by default. With no cap, Cloudflare stops most models at 256 tokens.
- Throws
EmptyResponseExceptionwhen a reasoning model returns HTTP 200 with no text, so a silent failure doesn’t look like an empty answer. - Sends
reasoning_effort, which Laravel AI doesn’t have. - Reports the neurons (Cloudflare’s billing unit) on every model call, with the
WorkersAiUsageReportedevent. - Retries HTTP 429 and Cloudflare edge errors, and maps them so Laravel AI failover works.
- Sends the second token that an authenticated AI Gateway needs.
- Calls Clef, Clairic, images, speech, transcription and reranking, which the
openai-compatibledriver can’t reach on Cloudflare.
How it reaches Cloudflare
Calls go directly to Workers AI, or through AI Gateway if you want logs, caching and rate limits. Your calling code is the same either way; only the config differs. See Direct and gateway routes.
Requirements
- PHP 8.3 or later.
laravel/ai0.9 to 1.3. Clef needs 1.0 or later.- A Cloudflare account and an API token.
Next steps
- Install the package with the Quickstart.
- Choose a connection with Direct and gateway routes.
- See every config key in Configuration.