Connect OpenAI Node SDK
The official Node SDK; only baseURL and apiKey change.
Use cases
Good for calling models from Node.js servers. The official SDK needs only baseURL and apiKey changed. Do not use it directly in the browser, or visitors will see your key.
Tips
Read the key from a server-side environment variable; never commit it or ship it in frontend bundles.
If it cannot connect
- Use
https://omnimodel.me/v1as the API host, without/chat/completions. - The key starts with
key_and is not paused or revoked;auth.invalid_keymeans the key cannot be used. - The model ID matches the catalog and is in the key's allowed models.
billing.insufficient_creditmeans the balance is too low; see common errors for more.
Setup
- Install the dependency: npm install openai.
- Point baseURL at the API host below and pass your own key.
- Never ship the key to a browser; proxy the call through your own backend.
Settings
- API host:
https://omnimodel.me/v1 - API key:
YOUR_API_KEY - Model:
MODEL_ID
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://omnimodel.me/v1",
});
const resp = await client.chat.completions.create({
model: "MODEL_ID",
messages: [{ role: "user", content: "你好" }],
});
console.log(resp.choices[0].message.content);
FAQ
- Can I use it in the browser?
- Not recommended. Browser code exposes your key to visitors; call from your server and return results to the frontend.
- Does it support streaming?
- Yes. Pass stream: true and iterate over the chunks as the SDK documents.