OmniRoute/examples/quickstart/nodejs_axios.js
Diego Rodrigues de Sa e Souza c1e30b7676
Release v3.8.51
Release v3.8.51 — 2,022 documented changes (235 features, 1,454 fixes, 333 maintenance) from 1,973 cycle commits and 301 external contributors; full changelog in CHANGELOG.md → [3.8.51]. Full ci.yml matrix green on 2f42a9ac (57 checks).
2026-09-29 19:58:13 -03:00

30 lines
896 B
JavaScript

/**
* OmniRoute Quickstart — Node.js (axios)
* =======================================
* Run: npm install axios
* node nodejs_axios.js
*/
const axios = require("axios");
// Your local OmniRoute server — started with: npx omniroute
const API_URL = "http://localhost:20128/v1/chat/completions";
const headers = {
"Content-Type": "application/json",
Authorization: "Bearer dummy-key", // Any string works for free/keyless providers
};
const data = {
model: "auto", // Zero-config routing, works out of the box — no sign-up needed
stream: false,
messages: [{ role: "user", content: "Hello! What can you do?" }],
};
axios
.post(API_URL, data, { headers })
.then((res) => console.log(res.data.choices[0].message.content))
.catch((err) => {
console.error("Error:", err.message);
if (err.response) console.error("Server replied:", err.response.data);
});