Python urllib с NordRouter
urllib входит в Python и не требует установки пакета.
python
import json
import os
from urllib.request import Request, urlopen
body = json.dumps({
"model": "anthropic/claude-sonnet-4.6",
"messages": [{"role": "user", "content": "Привет!"}],
}).encode("utf-8")
request = Request(
"https://nordrouter.com/v1/chat/completions",
data=body,
headers={
"Authorization": f"Bearer {os.environ['NORDROUTER_API_KEY']}",
"Content-Type": "application/json",
},
method="POST",
)
with urlopen(request, timeout=60) as response:
data = json.load(response)
print(data["choices"][0]["message"]["content"])