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 routing — LLMRouter with pluggable RoutingStrategy and lazy model discovery.
  • Cross-provider fallback — FallbackClient 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.
  • Embeddings — EmbeddingClient 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 use — ollama run is simpler.
  • One model, single engine, production — vllm 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.

Metadata

Release files for llm-infer 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-infer 0.9.0
File Size Uploaded Provenance Actions
llm_infer-0.9.0.tar.gz 565.6 kB With provenance Details for llm_infer-0.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llm-infer 0.9.0
File Interpreter ABI Platform Actions
llm_infer-0.9.0-py3-none-any.whl Python 3 none any Details for llm_infer-0.9.0-py3-none-any.whl

Total release size: 963.4 kB

Release files / llm_infer-0.9.0.tar.gz

Download URL llm_infer-0.9.0.tar.gz
Size 565.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1fc2348ef4733aba8bbf278fca1677966f21e0633e86b47ecd0dd1bb5884a56d
BLAKE2b-256 checksum
How to use checksums
cbfa88c4c2fc814bb897095f8aa01600e618020e2fa0ef3a2611af834df36e5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 12, 2026.

Transparency log

Release files / llm_infer-0.9.0-py3-none-any.whl

Download URL llm_infer-0.9.0-py3-none-any.whl
Size 397.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65d0b008ca94fac51a794620c5185b2c3575a19674e8b2e9b80fdb1830e6a444
BLAKE2b-256 checksum
How to use checksums
107a46d75427dbfc6285b911501c9c767b75bcfcce64f1d49376ea2c5eff2913
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 12, 2026.

Transparency log

Security for llm-infer 0.9.0

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for llm_infer-0.9.0.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 Nov 12, 2026.

Transparency log

A 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.

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