Attach images to a prompt. The package sends each image as an image_url content part. Choose a Workers AI model that accepts images.
use Laravel\Ai\Files\Image;
$response = agent('Describe images.')->prompt(
'What is in this picture?',
attachments: [Image::fromPath(storage_path('app/photo.jpg'))],
provider: 'workers-ai',
model: '@cf/your/vision-model', // replace: see below
);Supported attachments
| Laravel AI class | Created with | Sent as |
|---|---|---|
LocalImage |
Image::fromPath() |
Base64 data URL |
StoredImage |
Image::fromStorage() |
Base64 data URL |
Base64Image |
Image::fromBase64() |
Base64 data URL |
RemoteImage |
Image::fromUrl() |
The URL |
Raw UploadedFile |
Passed as is | Base64 data URL, MIME checked |
| Uploaded file | Image::fromUpload() |
Base64 data URL (it becomes a Base64Image) |
The package checks the MIME type only when you pass a raw Illuminate\Http\UploadedFile, such as $request->file('photo'). It allows image/jpeg, image/png, image/gif and image/webp. For other types (SVG, AVIF, HEIC), it throws InvalidArgumentException with the message Workers AI does not support document attachments. Only image attachments are supported.
Image::fromUpload() returns a Base64Image, and the package does not check a Base64Image, LocalImage, StoredImage or RemoteImage. Cloudflare accepts or rejects those files. Send only the four types above.
Not supported
- Documents. The package throws
InvalidArgumentExceptionwith the same message. To use a document, extract its text and put the text in the prompt. - Audio and video.
- Image generation.
Images for Clef and Clairic
Clef and Clairic take images in a different request format. They accept up to 4 inline images, in JPEG, PNG or WebP. They reject remote URLs. See Clef and Clairic.