Integrations
SDKs
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 first.
The cURL / SDK tab under Use in tools on the API keys page has ready-made samples with your key filled in.
OpenAI SDK#
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)Chat Completions accepts every text model, so the same client can call claude-sonnet-5.5 or gemini-3.1-pro.
Anthropic SDK#
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)Google Gen AI SDK#
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)More on each format: Anthropic Messages, OpenAI Chat Completions, 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. |
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. |
Every other status is covered in Errors.