# Connect OpenAI Node SDK

https://omnimodel.me/apps/openai-node

> 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

1. Use `https://omnimodel.me/v1` as the API host, without `/chat/completions`.
2. The key starts with `key_` and is not paused or revoked; `auth.invalid_key` means the key cannot be used.
3. The model ID matches the [catalog](/catalog) and is in the key's allowed models.
4. `billing.insufficient_credit` means the balance is too low; see [common errors](/docs/errors?lang=en) for more.

## Setup

1. Install the dependency: npm install openai.
2. Point baseURL at the API host below and pass your own key.
3. 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`

```javascript
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.

