Skip to main content

llm-infer

Python Coverage Typed Linting: Ruff CI PyPI License

llm-infer is a Python package for LLM inference: a production-grade multi-backend client library, plus a thin wrapper for serving local models behind an OpenAI-compatible endpoint.

Two components:

  1. llm_infer.client — a production-grade multi-backend client library. Speaks OpenAI, Anthropic, Google (AI Studio + Vertex OpenAI-compat), Vertex AI native REST, and any OpenAI-compatible server through one interface, with routing, cross-provider fallback, retries, rate limiting, structured callbacks, and embeddings. This is the main event.
  2. llm-infer serve — a thin devops wrapper around Ollama, vLLM, native torch, and PEFT that exposes them all behind one OpenAI-compatible HTTP endpoint. Useful when a team runs several models across mixed engines and wants a single operator contract. Not a replacement for real inference platforms (KServe, Ray Serve, NVIDIA Triton, vLLM's production stack) at GPU-farm scale.

The two are independent — the client works against any endpoint (cloud or self-hosted), and the server can be consumed by any OpenAI-compatible client.


llm_infer.client — Multi-Backend Client Library

Unified interface across cloud providers and self-hosted servers, with the primitives production agent code actually needs: fallback across providers, per-backend rate limits, exponential backoff, structured callbacks for cost and tracing, embeddings, and async everywhere.

Backends

Backend Notes
openai OpenAI API
openai_compatible Any OpenAI-compatible endpoint (vLLM, Ollama, llm-infer serve, ...)
anthropic Anthropic Claude
Google Gemini via AI Studio, Vertex OpenAI-compat, and native Vertex REST (generateContent + cachedContents)

Highlights

  • Multi-backend routingLLMRouter with pluggable RoutingStrategy and lazy model discovery.
  • Cross-provider fallbackFallbackClient with chained pairs and model@backend pinning; 429s exhaust their retry budget on the primary before failing over.
  • Structured callbacks — six lifecycle hooks split across retry-loop level (on_request, on_response, on_retry, on_error) and HTTP level (on_before_send, on_after_send) for cost tracking, tracing, and latency histograms.
  • EmbeddingsEmbeddingClient for OpenAI and Google (AI Studio + Vertex) with the same retry/callback contract.
  • Sync, async, streaming — every execution mode.
  • Auth — bearer tokens or GCP service accounts, resolved from the auth: block on any backend.
  • Extensible — register custom backends via Factory.register().

Quick example

from appinfra.log import Logger
from llm_infer.client import Factory, FallbackClient

lg = Logger("my-app")
factory = Factory(lg)

messages = [{"role": "user", "content": "Hello!"}]

# Single backend
with factory.openai(base_url="http://localhost:8000/v1") as client:
    response = client.chat(messages)

# Multi-backend router with cross-provider fallback
config = {
    "default": "primary",
    "backends": {
        "primary": {
            "type": "openai_compatible",
            "base_url": "http://localhost:8000/v1",
        },
        "fallback": {"type": "anthropic"},
    },
}  # see llm_infer/client/README.md for full schema
router = factory.from_config(config)
client = FallbackClient(lg, router, fallbacks={"gpt-4o": "claude-sonnet-4-20250514"})
response = client.chat(messages, model="gpt-4o")

Full API, configuration schema, routing and fallback semantics, embeddings, and observability hooks: see llm_infer/client/README.md.


llm-infer serve — Local Inference Wrapper

A single OpenAI-compatible HTTP server that dispatches to Ollama, vLLM, native torch, or PEFT — selected by one yaml key. This is a devops wrapper, not a serving platform: it unifies the operator surface (CLI, health, shutdown, model catalog, OpenAI API, think/adapter protocol extensions) across engines. Each engine keeps its own tuning knobs under a shared outer envelope. Serves one model per process.

Good fit

  • Several models with different settings — one models.yaml entry per model, one CLI flag to switch which model the server hosts.
  • Mixed engines behind one contract — Ollama for small models, vLLM for production serving (hot LoRA swap in-process, or pinned adapters as an HTTP subprocess), native for experimentation, PEFT for PROMPT_TUNING adapters that vLLM doesn't support.
  • Client code doesn't change when the backend changes — same OpenAI surface, same think/adapter extensions across engines.
  • Dev↔prod parity — the yaml (with -o key=value overrides) is the same shape everywhere.

Not a fit

  • One model, laptop, casual useollama run is simpler.
  • One model, single engine, productionvllm serve or ollama serve alone gives every knob directly, no abstraction cost.
  • Multi-model in one process, dynamic KV cache sharing, engine-crash auto-restart — this wrapper doesn't do those. Use a supervisor with one process per model, or a real inference platform (KServe, Ray Serve, NVIDIA Triton, vLLM's production stack) — see Scale ceiling below.

Scale ceiling

At GPU-farm scale — autoscaling, disaggregated prefill/decode, cross-replica batching, hot-swap under traffic — reach for a real inference platform: KServe, Ray Serve, NVIDIA Triton, or vLLM's production stack. Not raw engine CLIs. Because llm-infer serve preserves the OpenAI contract, downstream client code doesn't have to change when migrating; the model catalog does.

Production deployment assumes

  • A reverse proxy in front for auth, TLS, rate limiting, and per-model routing — the server has no built-in auth.
  • A supervisor (systemd, k8s) for restart and multi-model fan-out — the server won't auto-restart a crashed engine subprocess.
  • Scrape-side handling of /metrics, which returns structured JSON, not Prometheus text-exposition.

Quick start

Serve on Ollama (the simplest path — CPU or GPU, no local weights to manage):

# 1. Install the Ollama binary (once per machine)
curl -fsSL https://ollama.com/install.sh | sh

# 2. Pull the model
ollama pull qwen2.5:0.5b

# 3. Install llm-infer and serve — llm-infer manages the ollama daemon
pip install 'llm-infer[runtime]'
llm-infer serve --model qwen2.5:0.5b

# 4. Query from another terminal
llm-infer query "What is the capital of France?"

See docs/usage.md for per-engine walkthroughs and llm_infer/etc/README.md for the bundled configuration and override patterns.

Engines

Engine Description Install
ollama (default) Wraps the Ollama server ollama.com
vllm / vllm-server vLLM — in-process (LoRA hot-swap) or as HTTP subprocess (LoRA pinned at boot) pip install vllm
native From-scratch torch implementation (PagedAttention + FlashInfer) pip install llm-infer[runtime]
peft HuggingFace PEFT, incl. PROMPT_TUNING adapters pip install llm-infer[runtime]
llm-infer serve --model qwen2.5:7b                          # Ollama
llm-infer serve --engine vllm --model-path /path/to/model   # vLLM (in-process)
llm-infer serve --engine native --model-path /path/to/model # Native

Protocol extensions

The server extends OpenAI chat completions with think (reasoning content) and adapter (LoRA selection) request fields, mirrored back as thinking in the message and an adapter metadata block on the response. The client library passes these through as keyword arguments on client.chat().

API endpoints

Endpoint Description
POST /v1/chat/completions Chat completion (OpenAI-compatible)
POST /v1/completions Text completion (OpenAI-compatible)
POST /v1/embeddings Embeddings (OpenAI-compatible)
GET /v1/models List available models
GET /health Readiness gate — reports initializing until warmup completes
GET /metrics Structured JSON metrics (not Prometheus text-exposition)

Installation

pip install llm-infer              # Client library only
pip install llm-infer[anthropic]   # + Anthropic support
pip install llm-infer[saia]        # + llm-saia integration
pip install llm-infer[runtime]     # + native engine and serve (torch)

Supported Python versions

CI runs against Python 3.11, 3.12, 3.13, and 3.14 on Linux. Other platforms and Python versions are not tested and not claimed. requires-python = ">=3.11" is enforced at install time.

License

Apache License 2.0 - see LICENSE for details.

Maintained by LLM Works LLC and contributors.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_infer-0.7.1.tar.gz (508.8 kB view details)

Uploaded Source

Built Distribution

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

llm_infer-0.7.1-py3-none-any.whl (365.7 kB view details)

Uploaded Python 3

File details

Details for the file llm_infer-0.7.1.tar.gz.

File metadata

  • Download URL: llm_infer-0.7.1.tar.gz
  • Upload date:
  • Size: 508.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for llm_infer-0.7.1.tar.gz
Algorithm Hash digest
SHA256 08c664e7a2c983015e97ad604b2700c3c02d86ff52c04c0dd67d9c3c086a1232
MD5 53ee971b4d128963321952542b1a880c
BLAKE2b-256 8ca9c074f6dcc2205299e6dde25093a468d0daa5ac70843a9acc662a86a7a754

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_infer-0.7.1.tar.gz:

Publisher: release.yml on llm-works/llm-infer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llm_infer-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: llm_infer-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 365.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for llm_infer-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3ba3815a69ae1207400dac67f9753eef70fc9ec6d9e9711a0e2be562609fcc8e
MD5 880dac4d0f09dbe688c6577e4df7f5d2
BLAKE2b-256 ff78cd6fedfd43ab8e3cf1329c397ec0a81da36c414a51359b49864a0ba0750c

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_infer-0.7.1-py3-none-any.whl:

Publisher: release.yml on llm-works/llm-infer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.7.1 This release

2 files

0.7.0

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page