33import logging
44from typing import Any
55
6+ from fastapi .params import Depends
67from llama_stack_client import APIConnectionError
78from fastapi import APIRouter , HTTPException , Request , status
89
910from client import AsyncLlamaStackClientHolder
1011from configuration import configuration
12+ from authorization .middleware import authorize
13+ from authorization .models import Action
1114from models .responses import ModelsResponse
1215from utils .endpoints import check_configuration_loaded
16+ from auth import get_auth_dependency
1317
1418logger = logging .getLogger (__name__ )
1519router = APIRouter (tags = ["models" ])
1620
1721
22+ auth_dependency = get_auth_dependency ()
23+
24+
1825models_responses : dict [int | str , dict [str , Any ]] = {
1926 200 : {
2027 "models" : [
4350
4451
4552@router .get ("/models" , responses = models_responses )
46- async def models_endpoint_handler (_request : Request ) -> ModelsResponse :
53+ @authorize (Action .GET_MODELS )
54+ async def models_endpoint_handler (_request : Request , auth : Any = Depends (get_auth_dependency ())) -> ModelsResponse :
4755 """
4856 Handle requests to the /models endpoint.
4957
@@ -57,6 +65,10 @@ async def models_endpoint_handler(_request: Request) -> ModelsResponse:
5765 Returns:
5866 ModelsResponse: An object containing the list of available models.
5967 """
68+
69+ # Used only by the middleware
70+ _ = auth
71+
6072 check_configuration_loaded (configuration )
6173
6274 llama_stack_configuration = configuration .llama_stack_configuration
0 commit comments