diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index 096bbc029b..babe3122fe 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -775,6 +775,7 @@ class KeyRequestBase(GenerateRequestBase): tags: Optional[List[str]] = None enforced_params: Optional[List[str]] = None allowed_routes: Optional[list] = [] + allowed_passthrough_routes: Optional[list] = [] rpm_limit_type: Optional[ Literal["guaranteed_throughput", "best_effort_throughput"] ] = None # raise an error if 'guaranteed_throughput' is set and we're overallocating rpm @@ -1442,7 +1443,7 @@ class LiteLLM_ObjectPermissionTable(LiteLLMPydanticObjectBase): "1234567890": ["tool_name_1", "tool_name_2"] } """ - + vector_stores: Optional[List[str]] = [] @@ -3105,6 +3106,7 @@ LiteLLM_ManagementEndpoint_MetadataFields = [ "enforced_params", "temp_budget_increase", "temp_budget_expiry", + "allowed_passthrough_routes", ] LiteLLM_ManagementEndpoint_MetadataFields_Premium = [ diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index 3226ea0179..772cb42d3e 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -47,9 +47,9 @@ from litellm.proxy.management_endpoints.model_management_endpoints import ( _add_model_to_db, ) from litellm.proxy.management_helpers.object_permission_utils import ( + _set_object_permission, attach_object_permission_to_dict, handle_update_object_permission_common, - _set_object_permission, ) from litellm.proxy.management_helpers.team_member_permission_checks import ( TeamMemberPermissionChecks, @@ -563,6 +563,7 @@ async def _common_key_generation_helper( # noqa: PLR0915 data_json = data.model_dump(exclude_unset=True, exclude_none=True) # type: ignore data_json = handle_key_type(data, data_json) + # if we get max_budget passed to /key/generate, then use it as key_max_budget. Since generate_key_helper_fn is used to make new users if "max_budget" in data_json: data_json["key_max_budget"] = data_json.pop("max_budget", None) @@ -838,6 +839,7 @@ async def generate_key_fn( - enforced_params: Optional[List[str]] - List of enforced params for the key (Enterprise only). [Docs](https://docs.litellm.ai/docs/proxy/enterprise#enforce-required-params-for-llm-requests) - prompts: Optional[List[str]] - List of prompts that the key is allowed to use. - allowed_routes: Optional[list] - List of allowed routes for the key. Store the actual route or store a wildcard pattern for a set of routes. Example - ["/chat/completions", "/embeddings", "/keys/*"] + - allowed_passthrough_routes: Optional[list] - List of allowed pass through endpoints for the key. Store the actual endpoint or store a wildcard pattern for a set of endpoints. Example - ["/my-custom-endpoint"]. Use this instead of allowed_routes, if you just want to specify which pass through endpoints the key can access, without specifying the routes. If allowed_routes is specified, allowed_pass_through_endpoints is ignored. - object_permission: Optional[LiteLLM_ObjectPermissionBase] - key-specific object permission. Example - {"vector_stores": ["vector_store_1", "vector_store_2"], "mcp_tool_permissions": {"server_id_1": ["tool1", "tool2"]}}. IF null or {} then no object permission. - key_type: Optional[str] - Type of key that determines default allowed routes. Options: "llm_api" (can call LLM API routes), "management" (can call management routes), "read_only" (can only call info/read routes), "default" (uses default allowed routes). Defaults to "default". - prompts: Optional[List[str]] - List of allowed prompts for the key. If specified, the key will only be able to use these specific prompts. @@ -1114,8 +1116,6 @@ def prepare_metadata_fields( return non_default_values - - async def prepare_key_update_data( data: Union[UpdateKeyRequest, RegenerateKeyRequest], existing_key_row: LiteLLM_VerificationToken, @@ -2819,6 +2819,7 @@ async def list_keys( code=status.HTTP_500_INTERNAL_SERVER_ERROR, ) + @router.get( "/key/aliases", tags=["key management"],