Generic LLM provider abstraction — Anthropic, OpenAI, Google, Ollama and any OpenAI-compatible local model
Project description
uc-llm-provider
Generic LLM provider abstraction for Python.
Anthropic, OpenAI, Google — and any OpenAI-compatible local model (Ollama, LM Studio, vLLM, llama.cpp).
Three usage modes: Library · Server · CLI
Install
pip install uc-llm-provider # core only
pip install "uc-llm-provider[anthropic]" # + Anthropic SDK
pip install "uc-llm-provider[openai]" # + OpenAI SDK
pip install "uc-llm-provider[server,cli]" # + Server + CLI
pip install "uc-llm-provider[all]" # everything
Library
from uc_llm_provider import get_provider, ChatRequest, ChatMessage
# Cloud
provider = get_provider({
"name": "anthropic",
"provider_type": "anthropic",
"api_key": "sk-ant-...",
"default_model": "claude-sonnet-4-20250514",
})
# Local (Ollama)
provider = get_provider({
"name": "ollama",
"provider_type": "ollama",
"api_base": "http://localhost:11434",
"default_model": "llama3.2",
})
# Any OpenAI-compatible endpoint
provider = get_provider({
"name": "lm-studio",
"provider_type": "openai_compatible",
"api_base": "http://localhost:1234/v1",
"default_model": "local-model",
})
# Chat
response = await provider.chat(ChatRequest(
messages=[ChatMessage(role="user", content="Hello")],
max_tokens=256,
))
print(response.content)
Streaming
async for chunk in provider.chat_stream(request):
if chunk.type == "content_delta":
print(chunk.content, end="", flush=True)
Custom provider
from uc_llm_provider import register_provider
from uc_llm_provider.providers.template import TemplateProvider
class MyProvider(TemplateProvider):
def _get_endpoint(self, path=""):
return "https://api.myprovider.com/v1/chat"
register_provider("myprovider", MyProvider)
Server
uc-llm-server --port 12290 --provider anthropic --model claude-sonnet-4-20250514
uc-llm-server --port 12290 --provider ollama --api-base http://localhost:11434 --model llama3.2
uc-llm-server --port 12290 --config server.yaml
Endpoints:
| Method | Path | Description |
|---|---|---|
| GET | /v1/health |
Provider status |
| GET | /v1/capabilities |
Supported tiers and features |
| GET | /v1/models |
Model list |
| GET | /v1/models/{id} |
Model detail |
| POST | /v1/chat |
Chat completion |
| POST | /v1/chat/stream |
Streaming chat (SSE) |
| POST | /v1/tokens/count |
Token count |
Config YAML:
provider: anthropic
model: claude-sonnet-4-20250514
api_key: "" # or set UC_LLM_API_KEY
log_mode: jsonl # jsonl | none
log_dir: ./logs
host: 0.0.0.0
cors_origins: ["*"]
CLI
uc-llm chat "Explain Playwright in one sentence"
uc-llm chat --interactive
uc-llm stream "Explain Playwright"
uc-llm models --provider ollama
uc-llm tokens "How many tokens is this?"
uc-llm health --provider anthropic
uc-llm config
Global options:
| Option | Env | Description |
|---|---|---|
--provider |
UC_LLM_PROVIDER |
Provider type |
--model |
UC_LLM_MODEL |
Model |
--api-key |
UC_LLM_API_KEY |
API key |
--api-base |
UC_LLM_API_BASE |
API base URL |
--log-mode |
UC_LLM_LOG_MODE |
jsonl or none |
Provider types
provider_type |
Provider |
|---|---|
anthropic |
Anthropic Claude |
openai |
OpenAI |
google |
Google Gemini |
ollama |
Ollama (local) |
openai_compatible |
Any OpenAI-compatible API |
lm_studio / lmstudio |
LM Studio |
vllm |
vLLM |
llamacpp |
llama.cpp server |
localai |
LocalAI |
Ollama extras
from uc_llm_provider import get_provider
ollama = get_provider({"provider_type": "ollama", "api_base": "http://localhost:11434"})
models = await ollama.list_local_models()
async for status in ollama.pull_model("mistral"):
print(status)
running = await ollama.is_running()
License
MIT · cuber IT service
Project details
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 uc_llm_provider-0.3.0.tar.gz.
File metadata
- Download URL: uc_llm_provider-0.3.0.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06d606639c11e38ba845722b1e630a189a5ce4863bac3b6b35a3bba1147a773c
|
|
| MD5 |
ade9f369097c3f03dd5794ddf1b4182f
|
|
| BLAKE2b-256 |
63b4b4ed0139f9b7042a1a9d7fbbba53c5f7d3baa6f7c96b46deeba2fc0dba1e
|
File details
Details for the file uc_llm_provider-0.3.0-py3-none-any.whl.
File metadata
- Download URL: uc_llm_provider-0.3.0-py3-none-any.whl
- Upload date:
- Size: 43.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fcf49c4c2d811637346868387055fcdefbc6749540a8ff9d5b90391470f6f84
|
|
| MD5 |
1e84f85bebbab2ba4092a6d513fc66fb
|
|
| BLAKE2b-256 |
ee84fb5bf52766eea4518c3e4dfb49f347e313d1c1c8c9d9c9bf469cc9608857
|