Loading...
Last updated on
The @gensx/openai package provides a pre-wrapped version of the OpenAI SDK for GenSX, making it easy to use OpenAI’s API with GenSX functionality.
To install the package, run the following command:
npm install @gensx/openai openai
You can use this package in two ways:
Simply replace your OpenAI import with the GenSX version:
// Instead of:
// import { OpenAI } from 'openai';
// Use:
import { OpenAI } from "@gensx/openai";
// Create a client as usual
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
// All methods are automatically wrapped with GenSX functionality
const completion = await client.chat.completions.create({
model: "gpt-4.1-mini",
messages: [{ role: "user", content: "Hello!" }],
});
// Use embeddings
const embedding = await client.embeddings.create({
model: "text-embedding-3-small",
input: "Hello world!",
});
// Use responses
const response = await client.responses.create({
model: "gpt-4.1-mini",
messages: [{ role: "user", content: "Hello!" }],
});
If you already have an OpenAI instance, you can wrap it with GenSX functionality:
import { OpenAI } from "openai";
import { wrapOpenAI } from "@gensx/openai";
// Create your OpenAI instance as usual
const client = wrapOpenAI(
new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
}),
);
// Now all methods are wrapped with GenSX functionality
const completion = await client.chat.completions.create({
model: "gpt-4.1-mini",
messages: [{ role: "user", content: "Hello!" }],
});
The package exports:
OpenAI
- A drop-in replacement for the OpenAI client that automatically wraps all methods with GenSX functionalitywrapOpenAI
- A function to manually wrap an OpenAI instance with GenSX functionalityAll methods from the OpenAI SDK are supported and automatically wrapped with GenSX functionality, including:
The wrapped methods maintain the same interface as the original OpenAI SDK, so you can use them exactly as you would with the standard OpenAI client.