# OpenAI SDK Examples

Omnius exposes an OpenAI-compatible chat-completions endpoint at `/v1/chat/completions`.

## JavaScript

```ts
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "http://127.0.0.1:11435/v1",
  apiKey: process.env.OMNIUS_REST_API_KEY ?? "local-dev",
});

const response = await client.chat.completions.create({
  model: "qwen3:4b",
  messages: [
    { role: "user", content: "Summarize the current project." },
  ],
});

console.log(response.choices[0]?.message?.content);
```

## JavaScript Realtime Flag

The SDK may not know Omnius-specific fields. Pass them through with a typed escape hatch if needed:

```ts
const response = await client.chat.completions.create({
  model: "qwen3:4b",
  messages: [
    { role: "user", content: "Keep it short enough for TTS." },
  ],
  realtime: true,
  realtime_options: {
    max_history_messages: 8,
    max_tokens: 120,
  },
} as any);
```

## Python

```py
from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:11435/v1",
    api_key="local-dev",
)

response = client.chat.completions.create(
    model="qwen3:4b",
    messages=[{"role": "user", "content": "Return one sentence."}],
)

print(response.choices[0].message.content)
```
