Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:LMCache LMCache API Registry

From Leeroopedia


Knowledge Sources
Domains API Server, Plugin Discovery
Last Updated 2026-02-09 00:00 GMT

Overview

Automatically discovers and registers FastAPI route modules by category for the LMCache internal API server.

Description

The APIRegistry class provides a convention-based auto-discovery mechanism for API route modules. It scans category subdirectories (common, vllm, controller) under the internal_api_server package, imports any module whose name ends with _api, and includes their APIRouter instances into a parent FastAPI application. This plugin-style architecture allows new API endpoints to be added simply by creating a new *_api.py file in the appropriate category directory. The registry supports selective category registration via the optional categories parameter.

Usage

Use APIRegistry at application startup to wire all API endpoints into the FastAPI app. Instantiate with the FastAPI app, then call register_all_apis with the desired category list. New API modules are automatically discovered without modifying the registry code.

Code Reference

Source Location

Signature

APICategory = Literal["common", "vllm", "controller"]

class APIRegistry:
    def __init__(self, app: FastAPI) -> None: ...
    def register_all_apis(self, categories: Optional[List[APICategory]] = None) -> None: ...

Import

from lmcache.v1.internal_api_server.api_registry import APIRegistry, APICategory

I/O Contract

Inputs

Name Type Required Description
app FastAPI Yes The FastAPI application instance to register routes on
categories Optional[List[APICategory]] No List of categories to register; defaults to all ("common", "vllm", "controller")

Outputs

Name Type Description
(side effect) None API routes from discovered modules are included into the FastAPI app

Usage Examples

from fastapi import FastAPI
from lmcache.v1.internal_api_server.api_registry import APIRegistry

app = FastAPI()
registry = APIRegistry(app)

# Register all API categories
registry.register_all_apis()

# Or register only specific categories
registry.register_all_apis(categories=["common", "vllm"])

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment