To get started, you can use 1Router via API like this:
Copy
fetch("https://1router.com/api/v1/chat/completions", { method: "POST", headers: { "Authorization": `Bearer ${1ROUTER_API_KEY}`, "HTTP-Referer": `${YOUR_SITE_URL}`, // Optional, for including your app on 1router.com rankings. "X-Title": `${YOUR_SITE_NAME}`, // Optional. Shows in rankings on 1router.com. "Content-Type": "application/json" }, body: JSON.stringify({ "model": "meta-llama/llama-3.1-405b-instruct", "messages": [ { "role": "user", "content": "What is the meaning of life?" } ] })});
You can also use 1Router with OpenAIβs client API:
Copy
import OpenAI from "openai";const openai = new OpenAI({ baseURL: "https://1router.com/api/v1", apiKey: $ROUTER_API_KEY, defaultHeaders: { "HTTP-Referer": $YOUR_SITE_URL, // Optional, for including your app on 1router.com rankings. "X-Title": $YOUR_SITE_NAME, // Optional. Shows in rankings on 1router.com. }});async function main() { const completion = await openai.chat.completions.create({ model: "meta-llama/llama-3.1-405b-instruct", messages: [ { "role": "user", "content": "What is the meaning of life?" } ] }); console.log(completion.choices[0].message);}main();