Skip to content

Python HTTPX dari 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": "Привет!"}],
        },
    )
    response.raise_for_status()
    print(response.json()["choices"][0]["message"]["content"])

Untuk httpx.AsyncClient parameter permintaannya sama, tetapi panggilan dilakukan melalui await.

Semua program