Source path: app/Services/Ai/Image/CloudflareImage.php
Extracted from supplied specification. Review before copying into application.

<?php
namespace App\Services\Ai\Image;

use App\Services\Ai\ImageProvider;
use Illuminate\Support\Facades\Http;

class CloudflareImage implements ImageProvider
{
    public function configured(array $c): bool { return !empty($c['api_key']) && !empty($c['account_id']); }

    public function generate(string $prompt, string $size, array $c): string
    {
        $res = Http::withToken($c['api_key'])->timeout(120)->post(
            "https://api.cloudflare.com/client/v4/accounts/{$c['account_id']}/ai/run/{$c['model']}",
            ['prompt' => $prompt, 'steps' => 4]
        )->throw();

        $b64 = $res->json('result.image');
        if (!$b64) throw new \RuntimeException('Cloudflare returned no image.');
        return base64_decode($b64);
    }
}
