> 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.

# TypeScript (Unified Mode)

## Setup

```bash
npm install openai
```

```typescript
import OpenAI from "openai";

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

## Basic chat

```typescript
const response = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-4-6",
  messages: [{ role: "user", content: "Hello!" }],
});

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

## Streaming

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

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

## Tool calling

```typescript
const response = await client.chat.completions.create({
  model: "google/gemini-2.5-flash",
  messages: [{ role: "user", content: "What's the weather in London?" }],
  tools: [
    {
      type: "function",
      function: {
        name: "get_weather",
        description: "Get weather for a city",
        parameters: {
          type: "object",
          properties: {
            city: { type: "string" },
          },
          required: ["city"],
        },
      },
    },
  ],
  tool_choice: "auto",
});

const toolCall = response.choices[0].message.tool_calls?.[0];
if (toolCall) {
  console.log(`${toolCall.function.name}(${toolCall.function.arguments})`);
}
```

## System messages

```typescript
const response = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-4-6",
  messages: [
    { role: "system", content: "You are a code reviewer. Be concise." },
    { role: "user", content: "Review: const x = arr.filter(i => i > 0).length > 0" },
  ],
});
```

## Switching providers

```typescript
const models = [
  "openai/gpt-4o",
  "anthropic/claude-sonnet-4-6",
  "google/gemini-2.5-flash",
];

for (const model of models) {
  const response = await client.chat.completions.create({
    model,
    messages: [{ role: "user", content: "What is 2+2?" }],
  });
  console.log(`${model}: ${response.choices[0].message.content}`);
}
```