Multi-backend LLM completion protocol (OpenRouter, Claude, Codex, OpenCode), endpoint and model registry, dispatch and execution, front-door API, graph viewer, CLI, and deployment-mode runtime with bootstrap provisioning guards
This library provides one shared protocol with four backend transports -- OpenRouter HTTP, Claude CLI, Codex CLI, and OpenCode CLI -- plus the layers that resolve a named endpoint and model, pace the call, and execute it with halt-and-resume semantics. The contract sits at the seam between what a caller asks for and what a transport does; every transport below that seam is a concrete integration. Deployment provenance is explicit: source, legacy, and package modes each route shared contracts differently, and an ambiguous environment raises rather than guesses. Batch pipeline orchestration lives one level down with its own page.
Where to start
Open packages/katsoft-llm-kit/src/llm_kit/adapters/backends.py to see how the OpenRouter and Claude transports build a request, track dropped parameters, and classify failures into the shared halt taxonomy. The completion package's type definitions define the response shape every transport returns.
Routes
- Build an OpenRouter client and complete
- packages/katsoft-llm-kit/src/llm_kit/adapters/client.py -- resolve the endpoint, build the OpenAI client
- packages/katsoft-llm-kit/src/llm_kit/adapters/backends.py -- OpenRouterBackend.complete issues the call and normalizes the result
- Compose and run a Codex exec call
- packages/katsoft-llm-kit/src/llm_kit/adapters/codex_command.py -- build the sanctioned argv with absolute paths and sandbox flags
- packages/katsoft-llm-kit/src/llm_kit/adapters/codex_backend.py -- CodexCliBackend.complete drives the subprocess and reads the result file
- Terminate a swapper-managed model
- packages/katsoft-llm-kit/src/llm_kit/adapters/swapper.py -- locate and verify the model PID against the swapper process
- packages/katsoft-llm-kit/src/llm_kit/adapters/_swapper_process.py -- re-check create_time, send SIGTERM, escalate to SIGKILL if needed
Protocol and types
- packages/katsoft-llm-kit/src/llm_kit/completion -- response types, halt classification, capability records, contract validation, and skill-context composition; the contract every backend must fulfill
Backend transports
- packages/katsoft-llm-kit/src/llm_kit/adapters -- OpenRouter, Claude CLI, Codex CLI, and OpenCode CLI backends; capability tables, CLI runners, auth probes, executable resolution, endpoint profiles, and the llama-swap swapper lifecycle with its process-safety rules
Endpoint and model registry
- packages/katsoft-llm-kit/src/llm_kit/registry -- named endpoint entries, model alias resolution, effort plans, cost accounting, and layered API-key lookup from environment variables and .env files
Dispatch and execution
- packages/katsoft-llm-kit/src/llm_kit/dispatch -- backend selection, pacing policy, and reachability probes
- packages/katsoft-llm-kit/src/llm_kit/execution -- running completions with halt-and-resume semantics and retry logic
Front door and CLI
- packages/katsoft-llm-kit/src/llm_kit/frontdoor -- the single caller-facing API composing registry, dispatch, and execution into one interface
- packages/katsoft-llm-kit/src/llm_kit/cli -- command-line entry point for account management, endpoint probing, and one-shot completion
Graph viewer
- packages/katsoft-llm-kit/src/llm_kit/graph -- graph data model, commands, operations, and the browser-based viewer with its static assets (6 JS files, 1 CSS, 1 HTML)
Runtime and deployment
- packages/katsoft-llm-kit/src/llm_kit/_runtime.py -- deployment provenance (source, legacy, package), contract routing through the shared contracts distribution, and the fleet detection gate
- packages/katsoft-llm-kit/src/llm_kit/bootstrap_guard.py -- vendored guard that detects bootstrap provisioning, resolves the plugin venv interpreter, and re-execs the process under it; stdlib-only by constraint
- packages/katsoft-llm-kit/src/llm_kit/_deployment.py -- the mode marker file that build hooks replace with release identity in installed wheels
Support
- packages/katsoft-llm-kit/src/llm_kit/jobs -- job schema and persistence for batch work units
- packages/katsoft-llm-kit/src/llm_kit/scaffold -- project scaffolding for new consumers of the kit
- packages/katsoft-llm-kit/src/llm_kit/schema -- schema definitions shared across the library
- packages/katsoft-llm-kit/src/llm_kit/storage -- the storage layer underlying the job and graph subsystems