1

I’m trying to get Gemini to analyze a simple receipt image using the Laravel Http facade, but I keep hitting a 400 “Invalid JSON payload” error.

The request works fine for text-only prompts, but adding the image part breaks it. Here is the snippet:

$res = Http::post($url, [
    'contents' => [[
        'parts' => [
            ['text' => 'What is the total?'],
            ['inline_data' => [
                'mime_type' => 'image/jpeg',
                'data' => base64_encode(file_get_contents($path))
            ]]
        ]
    ]]
]);

Google returns: Unknown name "inline_data": Field 'inline_data' could not be found in request messages.

I’ve triple-checked the nesting based on the docs. Is this an array structure issue, or am I forced to use the /upload/ File API even for small 150kb images?

Any ideas?

Dewald Hugo Answered question