-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Expand file tree
/
Copy pathnodejs_axios.js
More file actions
30 lines (25 loc) · 896 Bytes
/
Copy pathnodejs_axios.js
File metadata and controls
30 lines (25 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* 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);
});