Implementation:LMCache LMCache API Registry
| 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
- Repository: LMCache
- File: lmcache/v1/internal_api_server/api_registry.py
- Lines: 1-59
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"])