true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 60, CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Host: weval-consulting.com'], CURLOPT_POSTFIELDS => json_encode(['message' => $msg, 'mode' => 'fast']), ]); $resp = curl_exec($ch); curl_close($ch); $data = json_decode($resp, true); $text = $data['response'] ?? 'Sovereign AI processing...'; $provider = $data['provider'] ?? 'WEVIA Sovereign'; // Detect format: Anthropic or OpenAI $uri = $_SERVER['REQUEST_URI'] ?? ''; $is_anthropic = strpos($uri, '/v1/messages') !== false || !empty($_SERVER['HTTP_ANTHROPIC_VERSION']) || isset($input['anthropic_version']); if ($is_anthropic) { echo json_encode([ 'id' => 'msg_wevia_' . substr(md5(uniqid()), 0, 12), 'type' => 'message', 'role' => 'assistant', 'content' => [['type' => 'text', 'text' => $text]], 'model' => 'wevia-sovereign-' . preg_replace('/[^a-zA-Z0-9]/', '', $provider), 'stop_reason' => 'end_turn', 'usage' => ['input_tokens' => 100, 'output_tokens' => intval(strlen($text) / 4)], ]); } else { echo json_encode([ 'id' => 'chatcmpl-wevia-' . substr(md5(uniqid()), 0, 8), 'object' => 'chat.completion', 'model' => 'wevia-sovereign-' . preg_replace('/[^a-zA-Z0-9]/', '', $provider), 'choices' => [['index' => 0, 'message' => ['role' => 'assistant', 'content' => $text], 'finish_reason' => 'stop']], 'usage' => ['prompt_tokens' => 100, 'completion_tokens' => intval(strlen($text) / 4)], ]); }