Source path: app/Services/Ai/Image/TogetherImage.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 TogetherImage 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
    {
        [$w, $h] = array_map('intval', explode('x', $size));
        $res = Http::withToken($c['api_key'])->timeout(120)->post('https://api.together.xyz/v1/images/generations', [
            'model' => $c['model'], 'prompt' => $prompt, 'width' => $w, 'height' => $h,
            'steps' => 4, 'n' => 1, 'response_format' => 'b64_json',
        ])->throw();
        return base64_decode($res->json('data.0.b64_json'));
    }
}
