llm-provider-adapter
llm-provider-adapter is a small, synchronous Python library for calling LLM
chat providers through one stable request, response, retry, error, and
telemetry contract.
Version 0.1 supports OpenAI, Claude, DeepSeek, OpenRouter, and LiteLLM. It does not provide an Agent framework, persistence, secret storage, async calls, streaming, multimodal content, or automatic cross-provider fallback.
Install
Python 3.11 or newer is required. Install only the provider SDK you need:
pip install "llm-provider-adapter[openai]>=0.1.0,<0.2.0"
pip install "llm-provider-adapter[claude]>=0.1.0,<0.2.0"
pip install "llm-provider-adapter[deepseek]>=0.1.0,<0.2.0"
pip install "llm-provider-adapter[openrouter]>=0.1.0,<0.2.0"
pip install "llm-provider-adapter[litellm]>=0.1.0,<0.2.0"
Use [all] only when an application must expose every adapter. The core
distribution imports without any provider SDK.
Minimal chat
Credentials, model IDs, and endpoints are always explicit. The library never reads environment variables or persists secrets.
from llm_provider_adapter import ChatRequest
from llm_provider_adapter.providers import OpenAIProvider
provider = OpenAIProvider(api_key="...")
response = provider.chat(
ChatRequest(
model="gpt-5-mini",
messages=[{"role": "user", "content": "Return one short greeting."}],
timeout_seconds=30,
)
)
print(response.content)
No real request is made when using the fake example:
python examples/fake_chat.py
Tool calling
Tools use the OpenAI function-tool shape at the public boundary. Provider
adapters translate it when required and normalize returned calls into
ToolCall(id, name, arguments).
request = ChatRequest(
model="gpt-5-mini",
messages=[{"role": "user", "content": "Weather in Shanghai?"}],
tools=[
{
"type": "function",
"function": {
"name": "weather",
"description": "Read weather for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}
],
tool_choice="auto",
)
Unsupported capabilities fail before the SDK request when possible. Parameters are never silently discarded to make a request succeed.
Errors, retries, and timeout
RetryPolicyowns one bounded retry loop; SDK/LiteLLM retries are disabled.- Authentication, invalid request, capability, and context-limit failures do not retry.
- Any recognized timeout, including an SDK-default timeout when the request
omits
timeout_seconds, is never automatically replayed because the upstream may already have accepted or billed the request. - The library never changes provider automatically.
- Public errors and retry records omit raw SDK exception text, payloads, headers, credentials, and response bodies.
Catch LLMProviderError for normalized provider failures and
MissingProviderExtraError when the selected optional SDK is absent.
Telemetry
Pass an object implementing TelemetryObserver.on_event(event) to a provider.
Request, response, retry, and error events include provider/model identifiers,
counts, status classifications, request IDs, and normalized usage only. They do
not include messages, tool arguments, headers, raw payloads, arbitrary request
metadata, or raw exception text. Observer failures never change the chat call.
Documentation
Development
uv sync --all-extras --all-groups
uv run ruff check .
uv run mypy src tests
uv run pytest -q
uv build
uv run twine check dist/*
The project is licensed under the MIT License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_provider_adapter-0.1.0.tar.gz.
File metadata
- Download URL: llm_provider_adapter-0.1.0.tar.gz
- Upload date:
- Size: 201.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d84fc296a239417aa46616f385b6eab8ec2e53c1f067453ce2a591a036c1aa63
|
|
| MD5 |
caf42a51e0bf0ba531b31e76aebdc7c3
|
|
| BLAKE2b-256 |
28651ad1a33d634640e8e5d1c7bad5534b7b54864e88279f320c52bc925e468d
|
Provenance
The following attestation bundles were made for llm_provider_adapter-0.1.0.tar.gz:
Publisher:
publish.yml on zhanghao1903/llm-provider-adapter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_provider_adapter-0.1.0.tar.gz -
Subject digest:
d84fc296a239417aa46616f385b6eab8ec2e53c1f067453ce2a591a036c1aa63 - Sigstore transparency entry: 2423398312
- Sigstore integration time:
-
Permalink:
zhanghao1903/llm-provider-adapter@19e7526086c8306b5823c17fb4d5e5eba60e800d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/zhanghao1903
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@19e7526086c8306b5823c17fb4d5e5eba60e800d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file llm_provider_adapter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llm_provider_adapter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43a0526133087d6d06897cd781a5732e337345b55b11b79a16c3bf5f4531d868
|
|
| MD5 |
b67339f2c4314dd644be9e118b890ac6
|
|
| BLAKE2b-256 |
22a4426603f9016518690b429c25bedcf20dfb17ca86f2114560813acbb37201
|
Provenance
The following attestation bundles were made for llm_provider_adapter-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on zhanghao1903/llm-provider-adapter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_provider_adapter-0.1.0-py3-none-any.whl -
Subject digest:
43a0526133087d6d06897cd781a5732e337345b55b11b79a16c3bf5f4531d868 - Sigstore transparency entry: 2423398341
- Sigstore integration time:
-
Permalink:
zhanghao1903/llm-provider-adapter@19e7526086c8306b5823c17fb4d5e5eba60e800d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/zhanghao1903
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@19e7526086c8306b5823c17fb4d5e5eba60e800d -
Trigger Event:
workflow_dispatch
-
Statement type: