Use the OpenAI Node.js SDK with InferGate
Set up the OpenAI JavaScript SDK for InferGate in Node.js with a custom baseURL, environment variable key and a gpt-5.5 Responses request.
Install the server-side SDK
Use a supported Node.js version. Save the example as request.mjs so Node uses ESM. This code belongs on a server, not in a browser bundle.
npm install openai@latest
export INFERGATE_API_KEY="YOUR_INFERGATE_API_KEY"
node request.mjsRequest text
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.INFERGATE_API_KEY,
baseURL: "https://api.useinfergate.com/v1",
});
const response = await client.responses.create({
model: "gpt-5.5",
input: "Reply with one sentence about API design.",
max_output_tokens: 256,
});
console.log(response.output_text);Integrate into an application
Catch request exceptions at your application boundary, retain the request ID and inspect completion status and usage. Keep the key in your deployment secret store. Use the base URL checklist if requests reach the wrong host.
Node.js setup: compare the failure layers
| Layer or outcome | Expected value or observation | Action |
|---|---|---|
| Runtime | Server-side Node.js | Do not expose the key through browser code |
| Module | request.mjs or ESM configuration | Import errors occur before an API request |
| Client option | baseURL | Capitalization differs from Python |
| Result | response.output_text and response.status | Inspect completion and usage |
Frequently asked questions
Why does Node reject the import statement?
Use an .mjs file or configure the project for ESM. Match the example to the module system used by the application. This error is separate from API authentication.
Should I use a public environment variable for the key?
No. Keep the credential available only to server code. Framework variables exposed to browser bundles are not appropriate for a private API key.
How do I select a different current model?
Change the model field to an exact identifier returned by your authenticated catalog. Keep the client endpoint fixed and verify the returned identity.
Continue your integration
Review prepaid pricing · Read API documentation · Get Started