Undici с NordRouter
Современный Node.js использует Undici в основе встроенного fetch.
js
import { request } from "undici";
const { statusCode, body } = await request(
"https://nordrouter.com/v1/chat/completions",
{
method: "POST",
headers: {
authorization: `Bearer ${process.env.NORDROUTER_API_KEY}`,
"content-type": "application/json",
},
body: JSON.stringify({
model: "anthropic/claude-sonnet-4.6",
messages: [{ role: "user", content: "Привет!" }],
}),
},
);
const text = await body.text();
if (statusCode !== 200) throw new Error(text);
console.log(JSON.parse(text).choices[0].message.content);