---
title: SDKs
description: Use the official OpenAI, Anthropic and Google Gen AI SDKs with a Lovely Router API key: pass the base URL and key when you create the client.
---

Lovely Router serves the OpenAI, Anthropic and Gemini APIs in their native formats, so the official SDKs work as they are. Pass the base URL and your key when you create the client. Everything else stays as in the vendor's docs. You need an [API key](/app/keys) first.

The **cURL / SDK** tab under **Use in tools** on the [API keys](/app/keys) page has ready-made samples with your key filled in.

## OpenAI SDK

```python title="Python"
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://lovelyrouter.com/v1",
    api_key=os.environ["LOVELY_API_KEY"],
)
response = client.chat.completions.create(
    model="gpt-6.1-sol",
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)
```

```js title="Node.js"
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://lovelyrouter.com/v1',
  apiKey: process.env.LOVELY_API_KEY,
});
const response = await client.chat.completions.create({
  model: 'gpt-6.1-sol',
  messages: [{ role: 'user', content: 'Hello' }],
});
console.log(response.choices[0].message.content);
```

Chat Completions accepts every text model, so the same client can call `claude-sonnet-5.5` or `gemini-3.1-pro`.

## Anthropic SDK

```python title="Python"
import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://lovelyrouter.com",
    api_key=os.environ["LOVELY_API_KEY"],
)
message = client.messages.create(
    model="claude-sonnet-5.5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(message.content[0].text)
```

```js title="Node.js"
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  baseURL: 'https://lovelyrouter.com',
  apiKey: process.env.LOVELY_API_KEY,
});
const message = await client.messages.create({
  model: 'claude-sonnet-5.5',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello' }],
});
console.log(message.content[0].text);
```

## Google Gen AI SDK

```python title="Python"
import os
from google import genai
from google.genai import types

client = genai.Client(
    api_key=os.environ["LOVELY_API_KEY"],
    http_options=types.HttpOptions(base_url="https://lovelyrouter.com"),
)
response = client.models.generate_content(model="gemini-3.1-pro", contents="Hello")
print(response.text)
```

```js title="Node.js"
import { GoogleGenAI } from '@google/genai';

const ai = new GoogleGenAI({
  apiKey: process.env.LOVELY_API_KEY,
  httpOptions: { baseUrl: 'https://lovelyrouter.com' },
});
const response = await ai.models.generateContent({ model: 'gemini-3.1-pro', contents: 'Hello' });
console.log(response.text);
```

More on each format: [Anthropic Messages](/docs/models/anthropic), [OpenAI Chat Completions](/docs/models/openai), [Gemini](/docs/models/gemini).

## Troubleshooting

| Symptom | Fix |
| --- | --- |
| `401` with `Missing API key` | The client isn't sending the key. Check that `LOVELY_API_KEY` is set in the environment your code runs in. |
| `401` with `Invalid or revoked API key` | The key is mistyped, truncated or revoked. Paste it again, or create a new one. |
| `404` with `Model '...' is not available` | The model id doesn't exist. Copy an id from `GET /v1/models` or the [model list](/models). |
| `404` on a path containing `/v1/v1/` | The Anthropic SDK adds `/v1` itself. Pass `https://lovelyrouter.com` as its base URL; only the OpenAI SDK takes `https://lovelyrouter.com/v1`. |
| `402` | Your balance is empty or the key reached its spend limit. See [Credits & billing](/docs/account/billing). |

Every other status is covered in [Errors](/docs/api/errors).
