Node.js examples
When to use this page
Use this page for server-side JavaScript or TypeScript integrations.
Install
npm install openai
Create a response
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.QUOTAFLOW_API_KEY,
baseURL: "https://api.quotaflow.ai/openai/v1"
});
const response = await client.responses.create({
model: "gpt-5.5",
input: "Return only: connected",
stream: false
});
console.log(response);
Chat completions compatibility
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.QUOTAFLOW_API_KEY,
baseURL: "https://api.quotaflow.ai/openai/v1"
});
const completion = await client.chat.completions.create({
model: "gpt-5.5",
messages: [{ role: "user", content: "Return only: ready" }]
});
console.log(completion.choices[0]?.message?.content);
Kimi JSON mode chat
Use kimi-k2.7-code on /chat/completions when you need a Chat Completions-shaped coding model with streaming or strict JSON output. GLM glm-5.2 supports non-streaming messages and non-streaming tools; stream: true currently fails closed with 503 pending verified availability evidence, while strict JSON mode returns 400 invalid_request_error.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.QUOTAFLOW_API_KEY,
baseURL: "https://api.quotaflow.ai/openai/v1"
});
const kimiJson = await client.chat.completions.create({
model: "kimi-k2.7-code",
messages: [{ role: "user", content: "Return JSON with status connected." }],
response_format: { type: "json_object" },
stream: false
});
console.log(kimiJson.choices[0]?.message?.content);
Embeddings
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.QUOTAFLOW_API_KEY,
baseURL: "https://api.quotaflow.ai/openai/v1"
});
const embedding = await client.embeddings.create({
model: "text-embedding-3-small",
input: "Quotaflow embeddings are connected."
});
console.log(embedding.data[0]?.embedding.length);
Anthropic-compatible Messages
Use fetch when you want to keep the Anthropic Messages request shape.
const messageResponse = await fetch("https://api.quotaflow.ai/v1/messages", {
method: "POST",
headers: {
"x-api-key": process.env.QUOTAFLOW_API_KEY ?? "",
"anthropic-version": "2023-06-01",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "claude-sonnet-4-6",
max_tokens: 128,
messages: [{ role: "user", content: "Return only: connected" }]
})
});
console.log(await messageResponse.json());
Image generation
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.QUOTAFLOW_API_KEY,
baseURL: "https://api.quotaflow.ai/openai/v1"
});
const image = await client.images.generate({
model: "gpt-image-2",
prompt: "A clean teal API dashboard illustration.",
size: "1024x1024",
response_format: "b64_json"
});
console.log(image.data?.[0]?.b64_json?.slice(0, 24));
Set response_format to url for non-streaming image generation when you want a temporary hosted URL instead of inline base64. Image edits are not part of the active V3 contract.
Video generation
Use fetch for task-based video generation when your SDK version does not expose a video helper yet.
const createResponse = await fetch("https://api.quotaflow.ai/openai/v1/videos", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.QUOTAFLOW_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "seedance-2.0-fast",
prompt: "A cinematic drone shot over a coastal city at sunrise.",
durationSeconds: 4,
resolution: "1080p",
aspectRatio: "16:9"
})
});
const task = await createResponse.json();
console.log(task);
const taskId = task.id ?? task.task_id;
const resultResponse = await fetch(`https://api.quotaflow.ai/openai/v1/videos/${taskId}`, {
headers: { Authorization: `Bearer ${process.env.QUOTAFLOW_API_KEY}` }
});
console.log(await resultResponse.json());