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

# OpenAI SDKs

> Use the OpenAI Python and Node.js SDKs with Qai Platform.

The official OpenAI SDKs work as they are. Set the base URL to `https://api.trustqai.com/v1` and use your Qai key.

## Install

```bash Python theme={null}
pip install openai
```

```bash Node.js theme={null}
npm install openai
```

## Configure the client

```python Python theme={null}
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.trustqai.com/v1",
    api_key=os.environ["QAI_API_KEY"],
)
```

```javascript Node.js theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.trustqai.com/v1",
  apiKey: process.env.QAI_API_KEY,
});
```

## Stream a reply

Set `stream` to get the reply as it is generated:

```python Python theme={null}
stream = client.chat.completions.create(
    model="qai/qwen3.8-27b",
    messages=[{"role": "user", "content": "Explain what an API key is in two sentences."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
```

```javascript Node.js theme={null}
const stream = await client.chat.completions.create({
  model: "qai/qwen3.8-27b",
  messages: [{ role: "user", content: "Explain what an API key is in two sentences." }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
```

## Model-specific options

Options that are not part of the OpenAI API, such as switching a model's thinking off, go in `extra_body` in Python and are passed alongside the other fields in Node.js:

```python Python theme={null}
response = client.chat.completions.create(
    model="qai/qwen3.8-27b",
    messages=[{"role": "user", "content": "Hello!"}],
    extra_body={"chat_template_kwargs": {"enable_thinking": False}},
)
```

```javascript Node.js theme={null}
const response = await client.chat.completions.create({
  model: "qai/qwen3.8-27b",
  messages: [{ role: "user", content: "Hello!" }],
  chat_template_kwargs: { enable_thinking: false },
});
```

See [Models](https://docs.trustqai.com/platform/models.md#thinking) for how thinking works.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.