Skip to content

Node.js OpenAI SDK ​

The official OpenAI Node SDK accepts a custom baseURL, so you can route every call through Corveil with two lines of config.

Mode ​

Direct mode only.

1. Install ​

bash
npm install openai

2. Minimal example ​

typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://your-corveil-host/v1",
  apiKey: "sk-citadel-your-key-here",
});

const resp = await client.chat.completions.create({
  model: "or-claude-haiku-4.5",
  messages: [{ role: "user", content: "Hello from Corveil" }],
});
console.log(resp.choices[0].message.content);

const emb = await client.embeddings.create({
  model: "openai/text-embedding-3-small",
  input: ["Hello from Corveil"],
});
console.log(emb.data[0].embedding.slice(0, 3));

An org admin enables the embedding model under AI Gateway → Providers → Catalog before the embeddings call succeeds. The catalog names are openai/text-embedding-3-small, openai/text-embedding-3-large, and openai/text-embedding-ada-002, with the openai/ prefix. To send the bare OpenAI name (text-embedding-3-small) unchanged, the admin clicks Add OpenAI embedding aliases under AI Gateway → Providers → Aliases.

Troubleshooting ​

  • CORS errors in the browser: Don't call Corveil directly from a browser context — route through your own server
  • Network errors with self-signed certs: Configure Node's NODE_EXTRA_CA_CERTS to include your CA bundle