Skip to main content

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

  • RetryPolicy owns 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

llm_provider_adapter-0.1.0.tar.gz (201.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_provider_adapter-0.1.0-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

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

Hashes for llm_provider_adapter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d84fc296a239417aa46616f385b6eab8ec2e53c1f067453ce2a591a036c1aa63
MD5 caf42a51e0bf0ba531b31e76aebdc7c3
BLAKE2b-256 28651ad1a33d634640e8e5d1c7bad5534b7b54864e88279f320c52bc925e468d

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_provider_adapter-0.1.0.tar.gz:

Publisher: publish.yml on zhanghao1903/llm-provider-adapter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llm_provider_adapter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_provider_adapter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43a0526133087d6d06897cd781a5732e337345b55b11b79a16c3bf5f4531d868
MD5 b67339f2c4314dd644be9e118b890ac6
BLAKE2b-256 22a4426603f9016518690b429c25bedcf20dfb17ca86f2114560813acbb37201

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page