> ## Documentation Index
> Fetch the complete documentation index at: https://docs.restacked.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI SDK

Use the OpenStack OpenAI-compatible gateway as a drop-in model backend for the official OpenAI SDK.

<Tabs>
  <Tab title="Typescript">
    ```ts theme={null}
    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);
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from openai import OpenAI
    import os

    client = OpenAI(api_key=os.environ["OPENSTACK_API_KEY"], base_url="https://api.openstack.ai/v1")

    with client.chat.completions.create(
        model="openai/gpt-4o-mini",
        user="user_123",
        stream=True,
        messages=[{"role": "user", "content": "Explain usage-based pricing in 2 lines."}],
    ) as stream:
        for event in stream:
            delta = event.choices[0].delta.content if event.choices and event.choices[0].delta else None
            if delta:
                print(delta, end="")
    ```
  </Tab>
</Tabs>
