Get Started →
DocsSDK & ExamplesAPI Reference
Getting Started / Frameworks

FastAPI Middleware Setup

Integrate RaksHex with FastAPI for async route discovery and request telemetry.

Add route security checks and telemetry auditing to your FastAPI backend using our official python client package.

Integration

from fastapi import FastAPI
from rakshex.integrations.fastapi import RakshexMiddleware

app = FastAPI()

# Add the middleware as the first layer
app.add_middleware(
    RaksHexMiddleware,
    api_key="ik_26f99572954998ec678ac9ecbf27031f",
    exclude_paths=["/healthz", "/metrics"]
)

@app.post("/generate")
async def generate_response(prompt: str):
    return {"message": "Success"}