pai-llm-config
Unified configuration management for LLM applications.
One YAML file to manage all your LLM providers, models, API keys, and parameters. Works with OpenAI, Anthropic, Azure, LiteLLM, DSPy, LangChain, and more.
If this project helps you, please consider giving it a star. It helps others discover it too.
Features
- Multi-provider — OpenAI, Anthropic, Azure, LiteLLM, and any OpenAI-compatible endpoint (DeepSeek, Gemini, Ollama, vLLM, etc.)
- Two-layer adapters — L1 outputs plain dicts (zero extra deps), L2 returns real SDK clients with key rotation
- Model aliases — Reference models by semantic names (
smart,fast,cheap) instead ofgpt-4o - Multi-key pool — Automatic key rotation with priority / round_robin / least_used / random strategies
- Framework integration — One-step client creation for DSPy, LiteLLM; params output for LangChain, OpenAI SDK, etc.
- Streaming — Built-in streaming wrappers with automatic usage reporting (OpenAI + Anthropic, sync + async)
- Multi-environment — Profile-based config (dev / staging / prod) with inheritance
- Type-safe — Pydantic validation, full IDE autocompletion
Install
pip install pai-llm-config
# With optional SDK support
pip install pai-llm-config[openai] # OpenAI SDK
pip install pai-llm-config[anthropic] # Anthropic SDK
pip install pai-llm-config[litellm] # LiteLLM
pip install pai-llm-config[all] # Everything
Quick Start
1. Create llm-config.yaml in your project root:
version: "1"
providers:
openai:
type: openai
api_key: ${OPENAI_API_KEY}
models:
gpt-4o:
provider: openai
model: gpt-4o
temperature: 0.7
max_tokens: 4096
aliases:
smart: gpt-4o
2. Use it:
from pai_llm_config import config
# L2: One-line client creation with key rotation
client = config.openai_client("smart")
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
Usage
Config Loading
from pai_llm_config import LLMConfig, config
# Global singleton (recommended) — auto-discovers llm-config.yaml
model = config.get("smart")
# Or use LLMConfig directly
cfg = LLMConfig.default() # Cached singleton
cfg = LLMConfig.load() # Fresh instance
cfg = LLMConfig.load(profile="production", config_path="config/llm.yaml")
L1: Parameter Output (Zero Extra Dependencies)
from pai_llm_config import config
# OpenAI SDK format
params = config.params("smart")
# -> {"model": "gpt-4o", "api_key": "sk-xxx", "base_url": "https://...", "temperature": 0.7, ...}
# LiteLLM format (provider/model prefix + api_base)
params = config.litellm_params("smart")
# -> {"model": "openai/gpt-4o", "api_key": "sk-xxx", "api_base": "https://...", ...}
# DSPy format
params = config.dspy_params("smart")
# -> {"model": "openai/gpt-4o", "api_key": "sk-xxx", "api_base": "https://...", ...}
L2: SDK Client Factory
from pai_llm_config import config
# Type-safe client creation with built-in key rotation
client = config.openai_client("smart") # -> openai.OpenAI
client = config.anthropic_client("reasoning") # -> anthropic.Anthropic
client = config.async_openai_client("smart") # -> openai.AsyncOpenAI
client = config.async_anthropic_client("reasoning") # -> anthropic.AsyncAnthropic
# Auto-dispatch by provider type
client = config.create_client("smart") # -> openai.OpenAI or anthropic.Anthropic
Framework Integration
from pai_llm_config import config
# DSPy — one step, returns configured dspy module
dspy = config.dspy_client("smart")
qa = dspy.ChainOfThought("question -> answer")
result = qa(question="What is pai-llm-config?")
# LiteLLM — returns litellm.Router
client = config.litellm_client("smart")
response = client.completion(model="smart", messages=[...])
# LangChain — use params() output
from langchain_openai import ChatOpenAI
chat = ChatOpenAI(**config.params("smart"))
Streaming
from pai_llm_config import config
# OpenAI streaming with automatic usage reporting
stream = config.stream_openai_chat("smart", messages=[{"role": "user", "content": "Tell a story"}])
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
# Anthropic streaming
with config.stream_anthropic_chat("reasoning", messages=[...], max_tokens=1024) as stream:
for text in stream.text_stream:
print(text, end="")
# Auto-dispatch
stream = config.stream_chat("smart", messages=[...])
Multi-Key Rotation
providers:
openai:
type: openai
api_keys:
- key: ${OPENAI_KEY_1}
alias: "primary"
priority: 1
daily_limit_usd: 5.0
- key: ${OPENAI_KEY_2}
alias: "secondary"
priority: 2
daily_limit_usd: 10.0
key_strategy: priority # priority | round_robin | least_used | random
# L2 clients automatically rotate keys — zero code changes
client = config.openai_client("smart")
# Monitor key pool health
pool = config.key_pool("openai")
print(pool.status())
Task Routing
routing:
presets:
code_generation: smart
summarization: cheap
classification: cheap
model = config.route("code_generation") # -> ModelConfig for "smart"
Configuration Reference
See docs/02_config-spec.md for the full YAML specification, and docs/06_examples.md for more usage examples.
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
If you find this project useful, please give it a star on GitHub — it motivates continued development and helps others find this project.
License
MIT
Metadata
Release files for pai-llm-config 0.1.5
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 |
|---|---|---|---|---|
| pai_llm_config-0.1.5.tar.gz | 44.7 kB | Without provenance | Details for pai_llm_config-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pai_llm_config-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for pai_llm_config-0.1.5-py3-none-any.whl |
Total release size: 68.7 kB
Release files / pai_llm_config-0.1.5.tar.gz
| Download URL | pai_llm_config-0.1.5.tar.gz |
|---|---|
| Size | 44.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
798fd84721db486d7ab542155e8eb8345b669a149bdd9645f3e70df07a74d7f2
|
|
BLAKE2b-256 checksum How to use checksums |
d2ce46fb7c128d7113d54c91a5521eacf99bd14d74f7f59c310de34e8ebc7ee8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / pai_llm_config-0.1.5-py3-none-any.whl
| Download URL | pai_llm_config-0.1.5-py3-none-any.whl |
|---|---|
| Size | 23.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3d92c686a4d70408c3149b3ed63f443e43f80aba9a1ed4c28fc109dc6115e04b
|
|
BLAKE2b-256 checksum How to use checksums |
34407c1e4f8c88b9fc6a816c92d8869563af50c1978d07e70390d8a1375ced00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for pai-llm-config 0.1.5
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.