If your app uses the OpenAI Node SDK, the integration is one parameter on client construction — no new package, no wrapper function, no restructuring of how you call the API. Here's the exact code, the environment variable pattern, and notes for the frameworks most Node apps are actually built on.
The Core Change
// Before
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
// After — same SDK, same calls, different baseURL
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: "https://proxy.preto.ai/v1/YOUR-KEY",
});
// Everything below this line is unchanged
const response = await client.chat.completions.create({
model: "gpt-5-mini",
messages: [{ role: "user", content: "Hello" }],
});
Your OpenAI API key stays exactly where it is — Preto forwards the request using your key, it doesn't intercept or replace your credentials.
Use an Environment Variable, Not a Hardcoded URL
// .env
OPENAI_BASE_URL=https://proxy.preto.ai/v1/YOUR-KEY
// your app
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: process.env.OPENAI_BASE_URL, // undefined falls back to SDK default
});
This lets staging point at the proxy while production stays on the direct provider URL until you're confident, and the eventual cutover in production is a config change — no code deploy required.
Streaming Works Unchanged
const stream = await client.chat.completions.create({
model: "gpt-5-mini",
messages: [{ role: "user", content: "Hello" }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
Preto pipes streamed tokens through as they arrive from the provider — your client starts receiving output as soon as it's generated, with negligible added latency to time-to-first-token.
Ready to grab your proxy URL?
Your unique proxy endpoint is waiting in your dashboard.
Copy the Code SnippetOne line. One import change. Your costs appear in Preto immediately.
Framework-Specific Notes
Verifying It's Working
Trigger one real request through your app — whatever call it already makes normally. Two checks confirm success: the response your app receives is unchanged (Preto forwards the provider's response exactly as returned), and the request shows up in your Preto dashboard within about a minute. If both hold, you're done.
TypeScript Types Are Unaffected
Since baseURL is already a documented, typed constructor option on the OpenAI SDK client, there's no type augmentation or `any` casting required — your existing TypeScript setup works exactly as it did before the change.
Running a Python service alongside your Node app? The Python integration guide covers the equivalent setup. And once data starts flowing in, here's what to look at first.
Frequently Asked Questions
Do I need to change my OpenAI Node SDK code to use Preto?
Should I hardcode the proxy URL or use an environment variable?
Does this work with streaming responses?
Does this work in Next.js API routes and server actions?
Grab your proxy URL and connect in the next few minutes.
Your unique endpoint is ready in your dashboard — copy it, set the environment variable, and your first request will show up within a minute.
Copy the Code SnippetQuestions about your specific setup? Reply to your welcome email.