The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_keyless_key_managed_resource_owner
mateo-berriabbfdd548420
diff --cc litellm/llms/base_llm/managed_resources/isolation.pyindex 5cc2110ef95,e1b204214d7..6a71e8e9223--- a/litellm/llms/base_llm/managed_resources/isolation.py+++ b/litellm/llms/base_llm/managed_resources/isolation.py@@@ -3,14 -3,13 +3,14 @@@ Tenant-isolation helpers for managed fiReturns a Prisma filter and an ownership check that scope managed resourcesto the caller's identity: proxy admins see everything, user-keyed callers-see records they created, and service-account keys (no user_id) fall back-to the resource's owning team. Callers with no admin role and no-identifying ids are denied so an empty user_id can never select an-unscoped query.+see records they created, service-account keys (no user_id) fall back to+the resource's owning team, and keys with neither a user_id nor a team_id+fall back to their own hashed token so they can still reach the resources+they created. Callers with no admin role and no identifying ids at all+are denied so an empty user_id can never select an unscoped query."""- from typing import Any, Dict, List, Optional+ from typing import Any, Finalfrom litellm.proxy._types import (UserAPIKeyAuth,@@@ -18,33 -19,7 +20,33 @@@ from litellm.proxy._types import)+def resolve_resource_owner_id(+ user_api_key_dict: UserAPIKeyAuth,+) -> str | None:+ """Return the identity to stamp on (and match against) a managed+ resource's ``created_by``.++ A key with neither a user_id nor a team_id would otherwise stamp+ ``created_by=None`` and be locked out of its own resources, so it owns+ them under its hashed token instead, using the ``key:`` scope prefix+ already used by ``proxy/common_utils/resource_ownership.py``. ``None``+ means the caller has no usable identity of its own and must fall back+ to team scoping, or be denied.+ """+ if user_api_key_dict.user_id is not None:+ return user_api_key_dict.user_id++ if user_api_key_dict.team_id is not None:+ return None+- token = user_api_key_dict.token or user_api_key_dict.api_key++ token: Final = user_api_key_dict.token or user_api_key_dict.api_key+ if token:+ return f"key:{token}"++ return None++- def build_list_page(items: List[Any], has_more: bool = False) -> Dict[str, Any]:+ def build_list_page(items: list[Any], has_more: bool = False) -> dict[str, Any]:"""Build the OpenAI-style paginated list response shape used by managedfile/batch/vector-store listings. ``first_id`` and ``last_id`` aresourced from each item's ``.id`` attribute."""@@@ -91,10 -65,9 +93,10 @@@ def build_owner_filterif team_id is not None:return {"team_id": team_id}- owner_id = resolve_resource_owner_id(user_api_key_dict)++ owner_id: Final = resolve_resource_owner_id(user_api_key_dict)+ if owner_id is not None:+ return {"created_by": owner_id}+return None@@@ -113,11 -86,11 +115,11 @@@ def can_access_resourceif _user_has_admin_view(user_api_key_dict):return True- owner_id = resolve_resource_owner_id(user_api_key_dict)- user_id: Final = user_api_key_dict.user_id- if user_id is not None and created_by is not None and created_by == user_id:++ owner_id: Final = resolve_resource_owner_id(user_api_key_dict)+ if owner_id is not None and created_by is not None and created_by == owner_id:return True- team_id = user_api_key_dict.team_id+ team_id: Final = user_api_key_dict.team_idif team_id is not None and resource_team_id is not None and resource_team_id == team_id:return Truediff --cc litellm/proxy/_lazy_openapi_snapshot.jsonindex 96f6ee89d56,1963c7799a2..040d258f97a--- a/litellm/proxy/_lazy_openapi_snapshot.json+++ b/litellm/proxy/_lazy_openapi_snapshot.json@@@ -9378,6 -10238,6 +10238,18 @@@"description": "AWS Bedrock runtime endpoint URL","title": "Aws Bedrock Runtime Endpoint"},++ "aws_external_id": {++ "anyOf": [++ {++ "type": "string"++ },++ {++ "type": "null"++ }++ ],++ "description": "External ID required by the target role's trust policy on sts:AssumeRole",++ "title": "Aws External Id"++ },"aws_profile_name": {"anyOf": [{@@@ -18775,7 -25231,14 +25243,17 @@@},{"items": {- "$ref": "#/components/schemas/ChatCompletionTextObject"+ "anyOf": [+ {+ "$ref": "#/components/schemas/ChatCompletionTextObject"+ },+ {+ "$ref": "#/components/schemas/ChatCompletionImageObject"++ },++ {++ "$ref": "#/components/schemas/ChatCompletionToolReferenceObject"+ }+ ]},"type": "array"}@@@ -18854,6 -25324,6 +25339,26 @@@"title": "ChatCompletionToolParamFunctionChunk","type": "object"},++ "ChatCompletionToolReferenceObject": {++ "description": "Anthropic tool-search result block, carried through untouched so it survives a round trip.",++ "properties": {++ "tool_name": {++ "title": "Tool Name",++ "type": "string"++ },++ "type": {++ "const": "tool_reference",++ "title": "Type",++ "type": "string"++ }++ },++ "required": [++ "type",++ "tool_name"++ ],++ "title": "ChatCompletionToolReferenceObject",++ "type": "object"++ },"ChatCompletionUserMessage": {"properties": {"cache_control": {diff --cc litellm/proxy/pass_through_endpoints/managed_id_rewriter.pyindex 411ea8eea43,23cfef6576c..567d8375737--- a/litellm/proxy/pass_through_endpoints/managed_id_rewriter.py+++ b/litellm/proxy/pass_through_endpoints/managed_id_rewriter.py@@@ -41,9 -49,10 +49,11 @@@ from litellm._logging import verbose_prfrom litellm.llms.base_llm.managed_resources.isolation import (build_owner_filter,can_access_resource,+ resolve_resource_owner_id,)from litellm.proxy._types import UserAPIKeyAuth+ from litellm.proxy.batches_endpoints.common_utils import validate_batch_list_limit+ from litellm.proxy.common_utils.sse_keepalive import split_complete_sse_framesfrom litellm.repositories.table_repositories import (ManagedFileRepository,ManagedObjectRepository,diff --cc ui/litellm-dashboard/src/lib/http/schema.d.tsindex 541d7a17ae1,25fbd53018a..8945710cba2--- a/ui/litellm-dashboard/src/lib/http/schema.d.ts+++ b/ui/litellm-dashboard/src/lib/http/schema.d.ts@@@ -26825,6 -29466,6 +29466,11 @@@ export interface components* @description AWS Bedrock runtime endpoint URL*/aws_bedrock_runtime_endpoint?: string | null;++ /**++ * Aws External Id++ * @description External ID required by the target role's trust policy on sts:AssumeRole++ */++ aws_external_id?: string | null;/*** Aws Profile Name* @description AWS profile name for credential retrieval