ellm-adapter
One call_llm function for Anthropic, OpenAI and Gemini language models. Switching providers means changing a model name, nothing else.
- The provider comes from the model name.
call_llm("claude-sonnet-5-5", ...)andcall_llm("gpt-6.1-sol", ...)take the same arguments and return the sameLLMResponse. - Structured output from a Pydantic class, validated before it is returned.
- Per-model parameter rules.
temperatureandreasoning_effortare sent only where the model accepts them; anything else is left out and listed indropped_params, so a model switch never breaks a call. - A fallback model. If the first model fails in any way, the same request goes to another one, on any provider.
- Comparable token counts across providers: input includes cached input, output includes thinking.
Install
pip install ellm-adapter
Requires Python 3.10+. Set the API keys of the providers you use: ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY.
Usage
from pydantic import BaseModel
from ellm_adapter import call_llm
class Outline(BaseModel):
title: str
slides: list[str]
response = call_llm(
model="claude-sonnet-5-5",
messages=[{"role": "user", "content": "Write a 5-slide outline on cybersecurity."}],
system_prompt="You are an instructional content expert.",
response_schema=Outline, # optional; without it, use response.text
reasoning_effort="low", # optional
fallback_model="gpt-6.1-sol", # optional
)
outline = response.parsed # an Outline instance
print(response.provider, response.model, response.input_tokens, response.output_tokens)
Parameters
| Parameter | Description |
|---|---|
model |
Required. Must be in the model list (ellm_adapter.MODELS). |
messages |
Required. [{"role": "user" | "assistant", "content": str}, ...] |
system_prompt |
Optional. |
response_schema |
Optional. A Pydantic class. If given, response.parsed is an instance of it. |
temperature |
Optional. Sent only to models that support it. |
reasoning_effort |
Optional. Sent only if the value is one the model accepts (see ellm_adapter.MODELS). |
max_tokens |
Optional. Defaults to the model's maximum. Thinking tokens count toward this limit. |
fallback_model |
Optional. If the first call fails for any reason, the same request is sent to this model. |
timeout |
Optional. Seconds per model call, default 600. With a fallback, each call gets the full timeout. |
Fixed settings: no SDK retries, nothing stored on the provider side (store=False).
Return value: LLMResponse
| Field | Description |
|---|---|
text |
The text the model produced. |
parsed |
The validated object if response_schema was given, otherwise None. |
provider, model |
The provider and model that actually answered. If the fallback was used, these are the fallback's. |
input_tokens |
Total input tokens, including cached ones. |
output_tokens |
Total tokens billed as output, including thinking. |
reasoning_tokens |
The thinking share of output_tokens. None if the provider doesn't report it. |
dropped_params |
Parameters not sent because the model doesn't support them, e.g. ["temperature"]. |
primary_error |
The first model's error if the fallback was used, otherwise None. |
raw |
The provider's raw response. |
Errors
| Error | When |
|---|---|
UnknownModelError |
model or fallback_model is not in the list. No request is sent. |
LLMResponseError |
A response arrived but can't be used. reason: truncated, refused, blocked, invalid_output or other. Token counts are on the error. |
FallbackError |
Both models failed. The primary_error and fallback_error fields hold both errors. |
| SDK errors | Without a fallback, the provider SDK's own error (rate limit, timeout, etc.) is raised as is. |
Supported models
The list is ellm_adapter.MODELS (in ellm_adapter/models.py): for each model, its provider, maximum output tokens, whether it takes temperature, and which reasoning_effort values it accepts. A model that isn't listed can't be called; adding one is a single entry.
Known limitations
- Synchronous, text only: no async client, streaming, tool use or image/file input yet. In async code, call it with
asyncio.to_thread(call_llm, ...). temperatureis never sent to Anthropic models: Anthropic's SDK 2.x removed the parameter.- OpenAI reasoning models accept
temperatureonly withreasoning_effort="none". - Gemini 2.5 models set thinking with a token budget, which isn't supported, so
reasoning_effortis dropped for them. - Claude doesn't enforce constraints such as
minLength,maxLength,minimumandmaximumin Pydantic schemas, and OpenAI doesn't supportdict[str, X]fields. The response is always validated with Pydantic after it arrives.
Development
pip install -e ".[dev]"
python -m unittest discover tests # offline: real SDKs against a local fake server, no keys, no cost
python tests/live_test.py [model ...] # live: real APIs, costs a little, keys from .env
Run the offline tests after any change to the package, and the live test after changing models.py (--all-efforts also tries every listed reasoning_effort value).
To release: bump __version__ in src/ellm_adapter/__init__.py, then python -m build and twine upload dist/*.
License
Apache License 2.0. The full text ships with the package as LICENSE.
Metadata
Release files for ellm-adapter 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ellm_adapter-0.3.1.tar.gz | 20.1 kB | Without provenance | Details for ellm_adapter-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ellm_adapter-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for ellm_adapter-0.3.1-py3-none-any.whl |
Total release size: 35.0 kB
Release files / ellm_adapter-0.3.1.tar.gz
| Download URL | ellm_adapter-0.3.1.tar.gz |
|---|---|
| Size | 20.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
16b5ef62cb6b4b5f2e26f4727d3f672cd6456f9bfbddd70bde573c9b9a925d1d
|
|
BLAKE2b-256 checksum How to use checksums |
0283963173b6695acbf2253b1b162e78644c092cc31bcef663ce21b3d2368be6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Release files / ellm_adapter-0.3.1-py3-none-any.whl
| Download URL | ellm_adapter-0.3.1-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be5ce674f40e551170f0fb1ffbcc77967232cb90f01bcd6d8ca78abc93ffeec7
|
|
BLAKE2b-256 checksum How to use checksums |
0bdb2339599c92c5f56052e32d2abcd512274338647ec1daaeff442e04b48b74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Security for ellm-adapter 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.