Skip to content

Python HTTPX con NordRouter

python
import os
import httpx

with httpx.Client(timeout=60) as client:
    response = client.post(
        "https://nordrouter.com/v1/chat/completions",
        headers={"Authorization": f"Bearer {os.environ['NORDROUTER_API_KEY']}"},
        json={
            "model": "anthropic/claude-sonnet-4.6",
            "messages": [{"role": "user", "content": "Ciao!"}],
        },
    )
    response.raise_for_status()
    print(response.json()["choices"][0]["message"]["content"])

httpx.AsyncClient usa gli stessi parametri della richiesta, ma le chiamate vengono eseguite con await.

Tutti i programmi