Metadata-Version: 2.5
Name: llmbroker
Version: 1.9.0
Project-URL: Homepage, https://andgineer.github.io/llmbroker/
Project-URL: Documentation, https://andgineer.github.io/llmbroker/
Author-email: Andrey Sorokin <andrey@sorokin.engineer>
License: Copyright (c) 2026 Andrey Sorokin (andrey@sorokin.engineer)
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of
        this software and associated documentation files (the “Software”), to deal in
        the Software without restriction, including without limitation the rights to use,
        copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
        Software, and to permit persons to whom the Software is furnished to do so,
        subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
        EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
        OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
        NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
        HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
        WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
        FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
        OTHER DEALINGS IN THE SOFTWARE.
License-File: LICENSE
Keywords: one,two
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.11
Requires-Dist: httpx>=0.28.1
Requires-Dist: pyyaml>=6.0
Requires-Dist: tomli-w>=1.2.0
Provides-Extra: aws
Requires-Dist: aioboto3>=13.0; extra == 'aws'
Provides-Extra: mongodb
Requires-Dist: motor>=3.6.0; extra == 'mongodb'
Provides-Extra: postgres
Requires-Dist: asyncpg>=0.30.0; extra == 'postgres'
Provides-Extra: sqlite
Requires-Dist: aiosqlite>=0.22.1; extra == 'sqlite'
Provides-Extra: vault
Requires-Dist: hvac>=2.0; extra == 'vault'
Description-Content-Type: text/markdown

[![Build Status](https://github.com/andgineer/llmbroker/workflows/CI/badge.svg)](https://github.com/andgineer/llmbroker/actions)
[![Coverage](https://raw.githubusercontent.com/andgineer/llmbroker/python-coverage-comment-action-data/badge.svg)](https://htmlpreview.github.io/?https://github.com/andgineer/llmbroker/blob/python-coverage-comment-action-data/htmlcov/index.html)
# llmbroker

Use multiple free LLM providers through one reliable API. llmbroker selects an
available model, recovers from provider errors and rate limits, and learns which
models work best for each task.

Start with no configuration file, paid subscription, or heavy orchestration
framework. Add production storage, per-user keys, or a specific paid model only
when you need them.

```bash
pip install llmbroker
llmbroker env freetier > .env   # required key names and links to obtain them
```

```python
import llmbroker

broker = llmbroker.Broker()
reply = broker.ask("Explain decorators in one sentence")
print(reply.text)
```

Add any provider keys you have; models without keys are skipped automatically.

| | |
|---|---|
| **Resilient by default** | Automatically tries another model after rate limits and provider failures |
| **Recovery without delays** | Rechecks a failed model alongside a working one; disable with `parallel_recovery=False` |
| **Lower latency on demand** | `fastest_of=2` queries multiple models and returns the first complete reply |
| **Improves with feedback** | `record_quality()` adapts model selection independently for each operation |
| **Complete application API** | Sync and async calls, streaming, chat, tools, and built-in tool loops |
| **Direct premium access** | `Broker(direct=["opus"])` calls a specific paid model through a stable alias |
| **Ready to scale** | SQLite, PostgreSQL, MongoDB, shared journals, per-user keys, and pluggable secrets |
| **Observable** | Pool state, call history, statistics, `trace_id`, and availability alerts |

[Documentation](https://andgineer.github.io/llmbroker/)

<details>
<summary>Development</summary>

Do not forget to run `. ./activate.sh`. It needs [uv](https://github.com/astral-sh/uv) installed.

Use [pre-commit](https://pre-commit.com/#install) hooks for code quality:

    pre-commit install

Install [invoke](https://docs.pyinvoke.org/en/stable/) preferably with [uv tool](https://docs.astral.sh/uv/):

    uv tool install invoke

For a list of available scripts run `invoke --list`; for details on one, `invoke <script> --help`.

The bundled `freetier` preset drifts as providers change their free tiers; refresh
it with `invoke catalog-refresh`, which prints the maintenance runbook
(`src/llmbroker/presets/freetier-refresh-prompt.md`).

Reports:

* [Allure test report](https://andgineer.github.io/llmbroker/builds/tests/)
* [Codecov](https://app.codecov.io/gh/andgineer/llmbroker/tree/main/src%2Fllmbroker)
* [Coveralls](https://coveralls.io/github/andgineer/llmbroker)

> Created with cookiecutter using [template](https://github.com/andgineer/cookiecutter-python-package)

</details>
