OpenAI SDK
Using the OpenAI SDK with Forge as a drop-in replacement.
OpenAI SDK Integration
Optima Forge is a drop-in replacement for the OpenAI API. Change two lines — base URL and API key — and your existing OpenAI SDK code works with Forge's intelligent routing, memory, and security.
JavaScript / TypeScript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.FORGE_API_KEY,
baseURL: "https://api.optima-forge.com/v1",
});
const completion = await client.chat.completions.create({
model: "auto", // or any specific model like "gpt-4o"
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is the meaning of life?" },
],
});
console.log(completion.choices[0].message.content);
Python
from openai import OpenAI
client = OpenAI(
api_key="forge_sk_your_key",
base_url="https://api.optima-forge.com/v1",
)
completion = client.chat.completions.create(
model="auto",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the meaning of life?"},
],
)
print(completion.choices[0].message.content)
Streaming
const stream = await client.chat.completions.create({
model: "auto",
messages: [{ role: "user", content: "Tell me a story." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
Function Calling
const response = await client.chat.completions.create({
model: "auto",
messages: [{ role: "user", content: "What's the weather in Paris?" }],
tools: [{
type: "function",
function: {
name: "get_weather",
description: "Get current weather for a location",
parameters: {
type: "object",
properties: {
location: { type: "string", description: "City name" }
},
required: ["location"],
},
},
}],
});
Migration Checklist
- Replace
OPENAI_API_KEYwithFORGE_API_KEY - Set
baseURL/base_urltohttps://api.optima-forge.com/v1 - Optionally change
modelto"auto"for intelligent routing - Optionally add
forgeextensions for memory, security, and caching - All existing OpenAI SDK features (streaming, function calling, vision) work unchanged