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

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

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

class OpenAiCompatText implements TextProvider
{
    private const BASE = [
        'groq'       => 'https://api.groq.com/openai/v1',
        'gemini'     => 'https://generativelanguage.googleapis.com/v1beta/openai',
        'openrouter' => 'https://openrouter.ai/api/v1',
        'openai'     => 'https://api.openai.com/v1',
    ];

    public function configured(array $c): bool
    {
        return !empty($c['api_key']) && !empty($c['text_model']) && isset(self::BASE[$c['name'] ?? '']);
    }

    public function complete(string $system, string $prompt, array $c): string
    {
        return Http::withToken($c['api_key'])->timeout(60)
            ->post(self::BASE[$c['name']] . '/chat/completions', [
                'model' => $c['text_model'],
                'messages' => [
                    ['role' => 'system', 'content' => $system],
                    ['role' => 'user', 'content' => $prompt],
                ],
            ])->throw()->json('choices.0.message.content');
    }
}
Jobs (replace the earlier versions)
