MCPcopy Create free account
hub / github.com/OpenDCAI/Paper2Any / verify_api_key

Function verify_api_key

fastapi_app/middleware/api_key.py:431–456  ·  view source on GitHub ↗

Verify the API key in request header (for use as Depends). Raises: HTTPException 401 if key is missing or invalid

(
    x_api_key: str = Header(None, alias="X-API-Key"),
)

Source from the content-addressed store, hash-verified

429
430
431async def verify_api_key(
432 x_api_key: str = Header(None, alias="X-API-Key"),
433) -> None:
434 """
435 Verify the API key in request header (for use as Depends).
436
437 Raises:
438 HTTPException 401 if key is missing or invalid
439 """
440 if not x_api_key:
441 raise HTTPException(
442 status_code=status.HTTP_401_UNAUTHORIZED,
443 detail="API key required",
444 )
445
446 if not API_KEY:
447 raise HTTPException(
448 status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
449 detail="BACKEND_API_KEY is not configured",
450 )
451
452 if x_api_key != API_KEY:
453 raise HTTPException(
454 status_code=status.HTTP_401_UNAUTHORIZED,
455 detail="Invalid API key",
456 )

Callers

nothing calls this directly

Calls 1

HeaderFunction · 0.85

Tested by

no test coverage detected