SDKs
Onlist provides official SDKs for Python and JavaScript/TypeScript. They wrap the
OpenAI client, so every chat.completions, embeddings, and images call works
out of the box with zero configuration: the base URL and auth header are handled
for you.
You do not need an SDK to use Onlist. Any OpenAI-compatible client works with
a base URL swap (see Quickstart and
Tool Configuration). The SDKs add convenience: auto-configured
endpoints, ONLIST_API_KEY env var support, and a typed marketplace namespace
for browsing models and providers.
Python
Install
pip install onlist
Usage
from onlist import Onlist
client = Onlist() # reads ONLIST_API_KEY env var
response = client.chat.completions.create(
model="anthropic/claude-sonnet-4",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
Authentication
The client looks for a key in this order:
api_keyconstructor parameterONLIST_API_KEYenvironment variableOPENAI_API_KEYenvironment variable (fallback for easy migration)
# Explicit key
client = Onlist(api_key="sk-...")
# Or set the env var
# export ONLIST_API_KEY=sk-...
client = Onlist()
Provider routing
Use extra_body to pass the provider object:
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
extra_body={"provider": {"sort": "price"}},
)
Streaming
stream = client.chat.completions.create(
model="anthropic/claude-sonnet-4",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True,
)
for chunk in stream:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)
JavaScript / TypeScript
Install
npm install @onlist/sdk
Usage
import { Onlist } from "@onlist/sdk";
const client = new Onlist(); // reads ONLIST_API_KEY env var
const response = await client.chat.completions.create({
model: "anthropic/claude-sonnet-4",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);
Authentication
The client looks for a key in this order:
apiKeyconstructor parameterONLIST_API_KEYenvironment variableOPENAI_API_KEYenvironment variable (fallback for easy migration)
// Explicit key
const client = new Onlist({ apiKey: "sk-..." });
// Or set the env var
// export ONLIST_API_KEY=sk-...
const client = new Onlist();
Provider routing
Pass the provider field directly:
const response = await client.chat.completions.create({
model: "openai/gpt-4o",
messages: [{ role: "user", content: "Hello" }],
provider: { sort: "price" },
});
Streaming
const stream = await client.chat.completions.create({
model: "anthropic/claude-sonnet-4",
messages: [{ role: "user", content: "Tell me a story" }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) process.stdout.write(content);
}
Marketplace API
Both SDKs expose a marketplace namespace for browsing the Onlist catalog
programmatically.
# List models with pricing
models = client.marketplace.models.list(limit=10)
for m in models.data:
print(f"{m.id}: ${m.pricing.prompt}/M input tokens")
# Get a specific model with all provider offers
detail = client.marketplace.models.get("anthropic/claude-sonnet-4")
for offer in detail.providers:
print(f"{offer.name}: ${offer.price_input_usd}/M input")
# List providers
providers = client.marketplace.providers.list()
for p in providers.items:
print(f"{p.name} ({p.listing_count} models)")Migration from OpenAI
Replace the import and constructor. All existing method calls stay the same.
- from openai import OpenAI
+ from onlist import Onlist
- client = OpenAI(api_key="sk-...")
+ client = Onlist(api_key="sk-...")Migration from OpenRouter
Drop the baseURL override entirely.
- from openai import OpenAI
+ from onlist import Onlist
- client = OpenAI(
- base_url="https://openrouter.ai/api/v1",
- api_key=os.environ["OPENROUTER_API_KEY"],
- )
+ client = Onlist()