> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://doc.enterpriserouter.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://doc.enterpriserouter.com/_mcp/server.

# OpenAI (Native Mode)

## Setup

Install the OpenAI SDK:

```bash
pip install openai
```

Configure the client to point at your gateway:

```python
from openai import OpenAI

client = OpenAI(
    api_key="sk-proxy-YOUR_KEY_HERE",
    base_url="https://api.enterpriserouter.com/openai/v1"
)
```

That's it. Use the client exactly as you would with OpenAI directly.

## Basic chat completion

```python
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain quantum computing in one paragraph."}
    ]
)

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

## Streaming

```python
stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a haiku about APIs."}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
```

## Function calling

```python
import json

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get the current weather for a location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string", "description": "City name"}
                },
                "required": ["location"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
    tools=tools,
    tool_choice="auto"
)

tool_call = response.choices[0].message.tool_calls[0]
print(f"Function: {tool_call.function.name}")
print(f"Arguments: {tool_call.function.arguments}")
```

## TypeScript

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "sk-proxy-YOUR_KEY_HERE",
  baseURL: "https://api.enterpriserouter.com/openai/v1",
});

const response = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hello!" }],
});

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

### Streaming (TypeScript)

```typescript
const stream = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Write a haiku about APIs." }],
  stream: true,
});

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

## Supported models

All OpenAI models work through native mode, including:

* `gpt-4o`, `gpt-4o-mini`
* `gpt-5.4`, `gpt-5.4-mini`, `gpt-5.4-nano`
* `o3`, `o3-mini`, `o4-mini`

Any new model OpenAI releases will work automatically — the gateway proxies requests without modification.