Skip to content

Python HTTPX 通过 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"])

对于 httpx.AsyncClient 请求设置相同,但通过 await 调用.

所有的程序