Source path: app/Services/Ai/Image/OpenAiImage.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 OpenAiImage implements ImageProvider
{
    public function configured(array $c): bool { return !empty($c['api_key']) && !empty($c['model']); }

    public function generate(string $prompt, string $size, array $c): string
    {
        $res = Http::withToken($c['api_key'])->timeout(150)->post('https://api.openai.com/v1/images/generations', [
            'model' => $c['model'], 'prompt' => $prompt, 'size' => $size, 'n' => 1,
        ])->throw();

        $item = $res->json('data.0');
        return isset($item['b64_json']) ? base64_decode($item['b64_json']) : Http::get($item['url'])->body();
    }
}
Video drivers
