LLM Connector
A clean, modular Python connector providing a unified interface for various Large Language Model (LLM) providers, including OpenRouter, OpenAI, Anthropic, Google (Gemini), Vertex AI, Groq, and local instances like llama.cpp and Ollama.
Features
- Multiple Providers: Connect natively to OpenRouter, Google, Vertex AI, OpenAI, Anthropic, Groq, local llama.cpp, and Ollama.
- YAML Configuration: Manage all URLs, timeouts, retry logic, logging structures, and default models strictly through transparent YAML files (
llm.yaml,security.yaml,logs.yaml). - Secure Overrides: Inject local offline IPs and enterprise pricing seamlessly via a
.gitignorerestrictedoverride.yamland keep API keys strictly in.env. - Resilient Connections: Features internal connection pooling, exponential backoff logic (for Rate Limits & 50x errors), and dynamically tracks OpenRouter internet pricing.
- Dynamic Client Loading: Adapters load their heavy SDKs exclusively on-demand.
Installation
Option A: Install from PyPI (recommended)
pip install llm-connector
Then scaffold your project workspace:
llm-connector init
This creates an llm-connector/ directory with conf/, logs/, .env.template, and override.yaml.template — everything you need to configure the connector.
CLI Reference
The llm-connector command-line tool helps you set up and manage your workspace.
llm-connector --help
llm-connector init
Scaffolds a new llm-connector/ workspace in the current directory with all necessary configuration files.
llm-connector init [--force]
| Flag | Description |
|---|---|
--force |
Overwrite an existing llm-connector/ directory |
Generated structure:
llm-connector/
├── .env.template # Copy to .env and add your API keys
├── conf/
│ ├── llm.yaml # Default provider, model, temperature, max_tokens
│ ├── security.yaml # Connection pooling, retry limits, backoff
│ ├── logs.yaml # Log rotation and formatting
│ └── override.yaml.template # Copy to override.yaml for local endpoints
└── logs/ # Runtime logs (auto-created)
After scaffolding:
cd llm-connector
cp .env.template .env # Add your API keys
cp conf/override.yaml.template conf/override.yaml # Add local endpoints (optional)
Option B: Clone as a submodule / standalone repo
git clone https://github.com/isbogdanov/llm_connector.git
cd llm_connector
pip install -e .
Configuration
-
API Keys (
.env): Copy the environment template and insert your secret keys.cp .env.template .env
API keys should exclusively live in
.envand never be committed. -
Local Environment Overrides (
conf/override.yaml): If you are running local inference servers (like Ollama or LLaMA.cpp), or if you want to hardcode specific contract prices, create an override file:cp conf/override.yaml.template conf/override.yaml
This file is safely untracked by Git, meaning your local IP addresses won't leak into the remote repository.
-
Base System Configuration (
conf/llm.yaml,conf/logs.yaml,conf/security.yaml): These files define the core tracked architecture. You can tune defaults likedefault_provider, log rotation limits, and API retry backoff-factors directly inside them.
Note: When installed via pip, all paths resolve relative to your scaffolded
llm-connector/directory. You can override this with theLLM_CONNECTOR_HOMEenvironment variable.
Usage
Import the chat_completion function from the connector.
from llm_connector import chat_completion
# Example messages
messages = [
{"role": "system", "content": "You are a highly capable AI assistant."},
{"role": "user", "content": "Explain the importance of context windows in LLMs."},
]
# 1. Using the default provider & model (defined in llm.yaml)
response, p_t, c_t, t_t, latency = chat_completion(messages)
print(f"Default Response: {response}")
# 2. Specifying a specific provider and native model
response_openrouter, _, _, _, _ = chat_completion(
messages,
provider=("openrouter", "anthropic/claude-3.5-sonnet"),
temperature=0.5,
)
# 3. Using Vertex AI
response_vertex, _, _, _, _ = chat_completion(
messages,
provider=("vertex", "gemini-2.5-flash"),
)
# 4. Hitting a local offline model
response_local, _, _, _, _ = chat_completion(
messages,
provider=("ollama", "llama3.1:8b"),
)
Creating Custom Adapters
This package is designed to be infinitely extensible. To add a brand-new API provider, follow these 3 steps:
-
Create the Adapter Class: Add a new file in
llm_connector/adapters/(e.g.,my_adapter.py). It must inherit fromAdapterBaseand strictly implement the corechat_completionsignature:from .adapter import AdapterBase class MyCustomAdapter(AdapterBase): def chat_completion(self, messages, model, temperature, max_tokens, top_p, **kwargs): # 1. Initialize your specific SDK client here # 2. Translate the generic 'messages' array into your provider's requested format # 3. Await the response # 4. Extract token usage and latency return response_text, prompt_tokens, completion_tokens, total_tokens, latency
-
Export the Adapter: Expose your new adapter class inside
llm_connector/adapters/__init__.py:from .my_adapter import MyCustomAdapter __all__ = [..., "MyCustomAdapter"]
-
Register it in the Router: Add your provider string internally into the
get_adapternetwork factory insidellm_connector/connector.py:elif provider_name == "my-custom-api": _adapters[provider_name] = MyCustomAdapter()
Testing
The testing suite natively utilizes pytest to rigidly guarantee the dynamic YAML hierarchy maps flawlessly to the internal routing logic without triggering infinite fallback loops.
To execute the entire engine diagnostic comprehensively, run:
pytest tests/
To include local model tests (requires a running llama.cpp or Ollama server):
pytest tests/ --run-local
The local suite actively asserts:
- Integration Verification: Dynamically attempts to route offline dummy prompts safely through OpenRouter, OpenAI, Anthropic, Google, Groq, and your local/Ollama networking blocks.
- Security Validation: Explicitly deconstructs the
requests.Session()engine upon boot and validates your exactsecurity.yamllimits (Connection Pools, HTTP Max Retries, and networkbackoff_factors) are clamped physically to the memory pipeline. - Adapter Isolation: Prevents SDK crosstalk by verifying requests generated for
"groq"cannot accidentally bleed over or trigger"local"internal logic modules.
Metadata
Release files for llm-connector 1.1.8
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 | |
|---|---|---|---|---|
| llm_connector-1.1.8.tar.gz | 29.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_connector-1.1.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 72.5 kB
Release files / llm_connector-1.1.8.tar.gz
| Download URL | llm_connector-1.1.8.tar.gz |
|---|---|
| Size | 29.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9551dadfcffeda90595a6b2fd6d7312c61c74a72822798f2e290f63e1559b02
|
|
BLAKE2b-256 checksum How to use checksums |
1c341c0ad800c31abab3e0d29c72e0a1b10dd69413476fcca467937fdd235059
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 5, 2026.
Transparency logRelease files / llm_connector-1.1.8-py3-none-any.whl
| Download URL | llm_connector-1.1.8-py3-none-any.whl |
|---|---|
| Size | 43.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
369bc1836bbabb19f161b68f37ee413442bdae2a936e9e625dba451cb3d63aee
|
|
BLAKE2b-256 checksum How to use checksums |
3d37685976d45e2737106fde21fabb4f5a2c3fdc17184e20593c5cebf8060c51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 5, 2026.
Transparency logSecurity for llm-connector 1.1.8
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for llm_connector-1.1.8.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 5, 2026.
Transparency logA 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.