# Keep the OpenAI SDK, change two fields

> Override baseURL and apiKey. Model ids are owner/model strings across 406+ models.

Override baseURL and apiKey, keep the SDK

**Slug**: `openai-sdk`  
**URL**: https://anyrouter.dev/use-cases/openai-sdk  
**Markdown**: https://anyrouter.dev/use-cases/openai-sdk.md  
**Short link**: https://anyrouter.dev/u/openai-sdk  

## Why use this

The official openai package looks vendor-locked. It is not — it only needs a compatible base URL.

## Set it up

1. Keep openai installed.
2. Set baseURL to https://anyrouter.dev/api/v1 and apiKey to your sk-ar key.
3. Use model "anyrouter/free" or "anyrouter/auto" for the first call.

## Code

### OpenAI SDK

```ts
import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://anyrouter.dev/api/v1",
  apiKey: process.env.ANYROUTER_API_KEY,
})

const res = await client.chat.completions.create({
  model: "anyrouter/free",
  messages: [{ role: "user", content: "Say hello in one sentence." }],
})
console.log(res.choices[0]?.message.content)
```

## Related

- [ai-sdk](https://anyrouter.dev/use-cases/ai-sdk)
- [unify-api](https://anyrouter.dev/use-cases/unify-api)
- [virtual-presets](https://anyrouter.dev/use-cases/virtual-presets)
