'Message vide', 'provider' => 'error']); exit; } // Call sovereign-api:4000 directly (12 providers, 0 EUR) $ch = curl_init('http://127.0.0.1:4000/v1/chat/completions'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 14, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_POSTFIELDS => json_encode([ 'model' => 'auto', 'messages' => [ ['role' => 'system', 'content' => 'Tu es WEVIA, IA souveraine de WEVAL Consulting, cabinet transformation digitale a Casablanca. Reponds en francais, professionnel et concis.'], ['role' => 'user', 'content' => $msg] ], 'max_tokens' => 800, 'temperature' => 0.3, ]) ]); $resp = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $time_ms = round(curl_getinfo($ch, CURLINFO_TOTAL_TIME) * 1000); curl_close($ch); if ($code === 200) { $d = json_decode($resp, true); $text = $d['choices'][0]['message']['content'] ?? ''; $prov = $d['provider'] ?? 'sovereign'; if ($text) { echo json_encode([ 'response' => $text, 'provider' => $prov, 'thinking' => ['Analyse en cours...'], 'duration_ms' => $time_ms ]); exit; } } echo json_encode(['response' => 'Tous les providers sont occupes. Reessayez.', 'provider' => 'busy', 'duration_ms' => $time_ms]);