"NO_KEY", "code" => 0]; $h = array_merge(["Content-Type: application/json", "Authorization: Bearer $key"], $headers); $ch = curl_init($url); curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data, CURLOPT_HTTPHEADER => $h, CURLOPT_TIMEOUT => 8, CURLOPT_SSL_VERIFYPEER => false]); $r = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $d = @json_decode($r, true); $err = $d["error"]["message"] ?? ""; return ["status" => $code === 200 ? "OK" : ($code === 429 ? "RATE_LIMITED" : "FAIL"), "code" => $code, "error" => substr($err, 0, 60)]; } $test_data = '{"model":"test","messages":[{"role":"user","content":"hi"}],"max_tokens":5}'; // Test each provider $providers = [ ["name" => "Groq", "key_name" => "GROQ_KEY", "url" => "https://api.groq.com/openai/v1/chat/completions", "data" => '{"model":"llama-3.3-70b-versatile","messages":[{"role":"user","content":"hi"}],"max_tokens":5}', "renew" => "https://console.groq.com/keys", "free" => true], ["name" => "Cerebras", "key_name" => "CEREBRAS_API_KEY", "url" => "https://api.cerebras.ai/v1/chat/completions", "data" => '{"model":"llama3.1-8b","messages":[{"role":"user","content":"hi"}],"max_tokens":5}', "renew" => "https://cloud.cerebras.ai/platform", "free" => true], ["name" => "Gemini", "key_name" => "GEMINI_KEY", "url" => "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions", "data" => '{"model":"gemini-2.5-flash","messages":[{"role":"user","content":"hi"}],"max_tokens":5}', "renew" => "https://aistudio.google.com/apikey", "free" => true], ["name" => "SambaNova", "key_name" => "SAMBANOVA_KEY", "url" => "https://api.sambanova.ai/v1/chat/completions", "data" => '{"model":"DeepSeek-V3.2","messages":[{"role":"user","content":"hi"}],"max_tokens":5}', "renew" => "https://cloud.sambanova.ai/apis", "free" => true], ["name" => "DeepSeek", "key_name" => "DEEPSEEK_KEY", "url" => "https://api.deepseek.com/chat/completions", "data" => '{"model":"deepseek-chat","messages":[{"role":"user","content":"hi"}],"max_tokens":5}', "renew" => "https://platform.deepseek.com/api_keys", "free" => false], ["name" => "Mistral", "key_name" => "MISTRAL_KEY", "url" => "https://api.mistral.ai/v1/chat/completions", "data" => '{"model":"open-mistral-7b","messages":[{"role":"user","content":"hi"}],"max_tokens":5}', "renew" => "https://console.mistral.ai/api-keys", "free" => true], ["name" => "OpenRouter", "key_name" => "OPENROUTER_KEY", "url" => "https://openrouter.ai/api/v1/chat/completions", "data" => '{"model":"meta-llama/llama-3.3-70b-instruct:free","messages":[{"role":"user","content":"hi"}],"max_tokens":5}', "renew" => "https://openrouter.ai/keys", "free" => true], ["name" => "HuggingFace", "key_name" => "HF_TOKEN", "url" => "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3", "data" => '{"inputs":"hi","parameters":{"max_new_tokens":5}}', "renew" => "https://huggingface.co/settings/tokens", "free" => true], ]; // GitHub special test $gh_key = ""; if (preg_match("/GITHUB_TOKEN=(.+)/", $env, $m)) $gh_key = trim($m[1]); $gh_ch = curl_init("https://api.github.com/user"); curl_setopt_array($gh_ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ["Authorization: Bearer $gh_key", "User-Agent: WEVIA"], CURLOPT_TIMEOUT => 5, CURLOPT_SSL_VERIFYPEER => false]); $gh_r = curl_exec($gh_ch); $gh_code = curl_getinfo($gh_ch, CURLINFO_HTTP_CODE); $gh_headers = curl_getinfo($gh_ch); $results[] = ["name" => "GitHub", "status" => $gh_code === 200 ? "OK" : "EXPIRED", "code" => $gh_code, "renew" => "https://github.com/settings/tokens", "key_name" => "GITHUB_TOKEN", "critical" => true]; // DeepSeek Web special $ds_web = @file_get_contents("http://localhost:8901/api/health"); $ds_d = @json_decode($ds_web, true); $results[] = ["name" => "DeepSeek Web", "status" => $ds_d ? "ACTIVE" : "DOWN", "code" => $ds_d ? 200 : 0, "renew" => "chat.deepseek.com → F12 → cookie", "unlimited" => true]; // Ollama $ollama = @file_get_contents("http://localhost:11434/api/tags"); $ol_d = @json_decode($ollama, true); $ol_cnt = count($ol_d["models"] ?? []); $results[] = ["name" => "Ollama Local", "status" => $ol_cnt > 0 ? "OK" : "DOWN", "code" => 200, "models" => $ol_cnt, "unlimited" => true]; foreach ($providers as $p) { $key = ""; if (preg_match("/" . $p["key_name"] . "=(.+)/", $env, $m)) $key = trim($m[1]); $r = testKey($p["name"], $p["url"], $key, $p["data"]); $r["name"] = $p["name"]; $r["renew"] = $p["renew"]; $r["key_name"] = $p["key_name"]; $r["free"] = $p["free"]; $r["has_key"] = strlen($key) > 5; $results[] = $r; } $ok = count(array_filter($results, fn($r) => $r["status"] === "OK" || $r["status"] === "ACTIVE" || $r["status"] === "RATE_LIMITED")); echo json_encode(["providers" => $results, "ok" => $ok, "total" => count($results), "ts" => date("c")], JSON_PRETTY_PRINT);