# OpenAI Node SDK

> Point the OpenAI Node / TypeScript SDK at TokRouter with baseURL, including streaming and a security note.

```bash
npm install openai
```

```ts

const client = new OpenAI({
  apiKey: process.env.TOKROUTER_API_KEY!,
  baseURL: 'https://api.tokrouter.dev/v1',
})

const resp = await client.chat.completions.create({
  model: 'gpt-5.4-mini',
  messages: [{ role: 'user', content: 'Explain SSE in one sentence' }],
})
console.log(resp.choices[0].message.content)
```

## Streaming

```ts
const stream = await client.chat.completions.create({
  model: 'claude-sonnet-5',
  messages: [{ role: 'user', content: 'Write a four-line poem' }],
  stream: true,
})

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

<Callout type="warn" title="Do not use the key in the browser">
`dangerouslyAllowBrowser` is fine for local experiments only: a key bundled into the frontend lets any
visitor spend your balance. In production, hold the key on your backend and proxy the request.
</Callout>
