Description
When using Files\Image::fromPath as an attachment with the OpenAI provider,
the API returns a 400 error:
HTTP request returned status code 400:
Invalid 'input[1].content[1].image_url'. Expected a base64-encoded data URL with an image
The same code works correctly with the Gemini provider.
Steps to reproduce
- Create an agent with the OpenAI provider
- Prompt the agent passing an image attachment via
Files\Image::fromPath
$response = (new MyAgent)->prompt(
'Describe this image.',
attachments: [
Files\Image::fromPath('/path/to/image.jpg'),
]
);
Expected behavior
The image is passed correctly to the OpenAI API as a base64-encoded data URL
(data:image/jpeg;base64,...).
Actual behavior
OpenAI rejects the request with a 400 error, suggesting the image is not being
serialized in the format expected by the OpenAI vision API.
Workaround
Bypassing the SDK and calling the OpenAI client directly:
$base64 = base64_encode(file_get_contents($imagePath));
$mimeType = mime_content_type($imagePath);
OpenAI::chat()->create([
'model' => 'gpt-4o-mini',
'messages' => [
[
'role' => 'user',
'content' => [
['type' => 'text', 'text' => 'Describe this image.'],
['type' => 'image_url', 'image_url' => ['url' => "data:{$mimeType};base64,{$base64}"]],
],
],
],
]);
Environment
- Laravel AI SDK version: v0.5.1
- Provider: OpenAI (gpt-4o-mini)
- PHP version: 8.x
- Laravel version: 12.x
Description
When using
Files\Image::fromPathas an attachment with the OpenAI provider,the API returns a 400 error:
The same code works correctly with the Gemini provider.
Steps to reproduce
Files\Image::fromPathExpected behavior
The image is passed correctly to the OpenAI API as a base64-encoded data URL
(
data:image/jpeg;base64,...).Actual behavior
OpenAI rejects the request with a 400 error, suggesting the image is not being
serialized in the format expected by the OpenAI vision API.
Workaround
Bypassing the SDK and calling the OpenAI client directly:
Environment