Try Depot: Bring ultra-fast, remote Docker builds directly to your Laravel workflow

Prism Workers AI — A Cloudflare Workers AI Provider for Prism PHP

Last updated on by

Prism Workers AI — A Cloudflare Workers AI Provider for Prism PHP image

Prism Workers AI is a Cloudflare Workers AI provider for Prism PHP and the Laravel AI SDK. It routes requests through Cloudflare's AI Gateway /compat endpoint.

  • Generate natural language text, structured outputs, and stream responses.
  • Create vector representations using Cloudflare embedding models.
  • Automate tool execution with support for complex, multi-step workflows.
  • Extract and utilize reasoning content from supported reasoning models.
  • Maintain conversation context using session affinity for prompt prefix caching.
  • Compatible with Prism PHP and Laravel AI SDK's agent() helper.

Text Generation and Streaming

Generate text using any Workers AI model through Prism's fluent API:

use Prism\Prism\Facades\Prism;
 
$response = Prism::text()
->using('workers-ai', 'workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast')
->withPrompt('Hello!')
->asText();

Streaming works the same way:

$stream = Prism::text()
->using('workers-ai', 'workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast')
->withPrompt('Tell me a story')
->asStream();

Embeddings

Unlike Prism's built-in xAI driver, this package supports embeddings:

$response = Prism::embeddings()
->using('workers-ai', 'workers-ai/@cf/baai/bge-large-en-v1.5')
->fromInput('Hello world')
->generate();

Tool Calling

The package supports tool calling with multi-step workflows. Workers AI requires content to always be present on assistant messages, even when empty during tool call responses — this package handles that automatically:

$response = Prism::text()
->using('workers-ai', 'workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast')
->withTools([$weatherTool])
->withMaxSteps(3)
->withPrompt('What is the weather?')
->asText();

Reasoning Models with Thinking Content

The package extracts reasoning content from reasoning models such as Kimi K2.5. The reasoning chain is available alongside the final response:

$response = Prism::text()
->using('workers-ai', 'workers-ai/@cf/moonshotai/kimi-k2.5')
->withMaxTokens(2000)
->withPrompt('What is 15 * 37?')
->asText();
 
$response->text; // "555"
$response->steps[0]->additionalContent['thinking'];
// "The user is asking for the product of 15 and 37..."

When streaming, you receive thinking events before the text output:

$stream = Prism::text()
->using('workers-ai', 'workers-ai/@cf/moonshotai/kimi-k2.5')
->withMaxTokens(2000)
->withPrompt('Explain briefly why the sky is blue.')
->asStream();
 
foreach ($stream as $event) {
// ThinkingStartEvent, ThinkingEvent (deltas), ThinkingCompleteEvent
// then TextStartEvent, TextDeltaEvent, TextCompleteEvent
}

Set withMaxTokens(2000) or higher when using reasoning models, since reasoning tokens count against the limit.

Laravel AI SDK Integration

If you're using laravel/ai, the package also registers a workers-ai driver:

use function Laravel\Ai\agent;
 
$response = agent(instructions: 'You are a helpful assistant.')
->prompt('Hello!', provider: 'workers-ai');

You can learn more about this package on GitHub at meirdick/prism-workers-ai.

Note: the package requires PHP 8.2+ and Prism PHP ^0.99, with optional support for Laravel AI SDK ^0.3.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
Prism Workers AI — A Cloudflare Workers AI Provider for Prism PHP image

Prism Workers AI — A Cloudflare Workers AI Provider for Prism PHP

Read article
Take the Pain Out of Data Imports with Laravel Ingest image

Take the Pain Out of Data Imports with Laravel Ingest

Read article
Liminal: A Browser-Based IDE for Laravel Powered by WebAssembly image

Liminal: A Browser-Based IDE for Laravel Powered by WebAssembly

Read article
NativePHP v3.1: The Biggest Performance Leap Yet image

NativePHP v3.1: The Biggest Performance Leap Yet

Read article
Prompt Deck: Manage AI Prompts as Versioned Files in Laravel image

Prompt Deck: Manage AI Prompts as Versioned Files in Laravel

Read article
Laravel Prompts v0.3.15 Adds Streaming, Tasks, Autocomplete, and More image

Laravel Prompts v0.3.15 Adds Streaming, Tasks, Autocomplete, and More

Read article