Skip to main content
Use the OpenStack OpenAI-compatible gateway as a drop-in model backend for the official OpenAI SDK.
  • Typescript
  • Python
import OpenAI from "openai";

const user = "user_123"; // Stable, pseudonymous user ID

const client = new OpenAI({
  apiKey: process.env.OPENSTACK_API_KEY, // Set your OpenStack API key here
  baseURL: "https://api.openstack.ai/v1", // Change baseURL to OpenStack
  headers: {
    "X-Openstack-User": user // Identify the end user
  }
});

const stream = await client.chat.completions.create({
  model: "gpt-5",
  user: "user_123",
  stream: true,
  messages: [
    { role: "user", content: "Explain usage-based pricing in 2 lines." },
  ],
});

for await (const chunk of stream) {
  const delta = chunk.choices?.[0]?.delta?.content;
  if (delta) process.stdout.write(delta);
}