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.5.0.tar.gz (36.3 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.5.0-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: uc_llm_provider-0.5.0.tar.gz
  • Upload date:
  • Size: 36.3 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.5.0.tar.gz
Algorithm Hash digest
SHA256 dcb26b8b329fc21c0df6055e4cb8dd91cc018dfc77569cbd8964dad471955273
MD5 11a457420e8d27699e8503918310f211
BLAKE2b-256 0ee303f9929590f6b0d14ddfcce1b3a8d2a1bef565b6d4c71c77279880279bf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uc_llm_provider-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36692485a23e9f1b8ba483490134da8eb5d844305f5e483fe2aba393b20c2343
MD5 60ecc6bcb06cd00240f808e5220a62c6
BLAKE2b-256 d78449fc4b084932efa35aa41052f4150cf654b6275a285180df3b63d145ab10

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