OpenAI-compatible is the most popular choice because many SDKs and frameworks support it out of the box. Simply change `baseURL` to cheapkeyai.com and use your API key.
Installation
npm install openai
Initialize Client
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: process.env.CHEAPKEYAI_API_KEY,
baseURL: "https://cheapkeyai.com/v1"
});
const result = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }]
});
console.log(result.choices[0].message.content);
Chat Completions
const stream = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Write a guide to deploy a React app." }],
stream: true
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
const result = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{
role: "user",
content: [
{ type: "text", text: "Describe this image." },
{ type: "image_url", image_url: { url: "https://example.com/image.png" } }
]
}]
});
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Weather in London?" }],
tools: [{
type: "function",
function: {
name: "get_weather",
description: "Get weather by city",
parameters: {
type: "object",
properties: { location: { type: "string" } },
required: ["location"]
}
}
}]
});
Responses API
curl https://cheapkeyai.com/v1/responses \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5-mini",
"input": "Create an SEO checklist for docs."
}'
Images API
const image = await openai.images.generate({
model: "gpt-image-1",
prompt: "Modern docs dashboard, natural lighting",
size: "1024x1024"
});
Videos API
Video generation is typically an asynchronous task. After creating a task, poll the status endpoint until it completes to retrieve the resulting URL.
Embeddings, Rerank, Moderations
- Embeddings are used for search, RAG, and clustering.
- Rerank is used to reorder documents by relevance.
- Moderations are used to check input or output content.
Error Handling
try {
await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello" }]
});
} catch (error) {
console.error(error.status, error.message);
}