Skip to main content

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

uc_llm_provider-0.2.0.tar.gz (29.8 kB view details)

Uploaded Source

Built Distribution

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

uc_llm_provider-0.2.0-py3-none-any.whl (40.8 kB view details)

Uploaded Python 3

File details

Details for the file uc_llm_provider-0.2.0.tar.gz.

File metadata

  • Download URL: uc_llm_provider-0.2.0.tar.gz
  • Upload date:
  • Size: 29.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for uc_llm_provider-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ecfabdca88d291f191bc8ef7c4c75a90285f4ec6b0aeab092f7a635713c2e1c9
MD5 af6151271dc2336583e428b19b2aed49
BLAKE2b-256 8fce3904754feb082e3beafa25e94e640fc9b9faafa02373414f72671959e5ea

See more details on using hashes here.

File details

Details for the file uc_llm_provider-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for uc_llm_provider-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 132263d0ba1e7ceebb892d302b4c2e9df8ebfdeff1f19d99609e70c2759c2e01
MD5 146d9719f3683711815990bcd0c464c4
BLAKE2b-256 aa3b7b91d7fc48720811c77c61f3b5ea2dd5166f8f00df84cf66154fcb18c35a

See more details on using hashes here.

Supported by

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