Probe candidate endpoints with a short timeout and record whether the host is reachable.
Ask for the minimum key needed and avoid printing full secrets in logs.
Confirm chat, model listing, speech, or image endpoints separately.
Map each task type to the lowest-cost reliable provider that actually worked.
import socket
import ssl
import urllib.error
import urllib.request
socket.setdefaulttimeout(8)
ctx = ssl.create_default_context()
services = {
"Groq": "https://api.groq.com",
"OpenRouter": "https://openrouter.ai/api/v1",
"DeepSeek": "https://api.deepseek.com",
"Mistral": "https://api.mistral.ai/v1",
}
for name, url in services.items():
try:
req = urllib.request.Request(url)
with urllib.request.urlopen(req, context=ctx, timeout=6) as resp:
print(f"{name}: HTTP {resp.status}")
except urllib.error.HTTPError as exc:
print(f"{name}: HTTP {exc.code} (reachable, auth may be required)")
except Exception as exc:
print(f"{name}: not reachable ({exc})")
共 1 个版本