OpenAI
OpenAI JavaScript SDK Integration
Use OpenAI’s JavaScript SDK to integrate with Helicone to log your OpenAI usage.
Proxy Integration (recommended)
1
2
Set HELICONE_API_KEY as an environment variable
HELICONE_API_KEY=<your API key>
3
Modify the base path and add a Helicone-Auth header
Package Integration
1
To get started, install the `helicone-openai` package
npm install @helicone/helicone
2
Set `HELICONE_API_KEY` as an environment variable
export HELICONE_API_KEY=sk-<your-api-key>
You can also set the Helicone API Key in your code (See below)
3
Replace
const { ClientOptions, OpenAI } = require("openai");
with
const { HeliconeAsyncOpenAI as OpenAI,
IHeliconeAsyncClientOptions as ClientOptions } = require("helicone");
4
Make a request
Chat, Completion, Embedding, etc usage is equivalent to OpenAI package.
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
heliconeMeta: {
apiKey: process.env.HELICONE_API_KEY, // Can be set as env variable
// ... additional helicone meta fields
},
});
const chatCompletion = await openai.chat.completion.create({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: "Hello world" }],
});
console.log(chatCompletion.data.choices[0].message);