Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ad9aa43
chore(proxy): scope skills and container resources
stuxf May 1, 2026
95c8406
chore(proxy): stabilize openapi snapshot ids
stuxf May 1, 2026
d2a3220
fix(proxy): preserve container ownership compatibility
stuxf May 1, 2026
0745b18
test(proxy): cover container endpoint forwarding
stuxf May 1, 2026
e4741fb
fix(proxy): add legacy skill ownership opt-out
stuxf May 1, 2026
9376b30
fix(proxy): reset filtered container pagination
stuxf May 1, 2026
6aac455
fix(proxy): forward decoded container ids
stuxf May 1, 2026
f3cff93
fix(proxy): harden resource ownership fallbacks
stuxf May 1, 2026
7b1e3f2
test(proxy): cover container endpoint post processing
stuxf May 1, 2026
20eb9c9
fix(proxy): avoid mutating container responses
stuxf May 1, 2026
3a566c3
fix(proxy): stabilize ownership fallback and openapi ids
stuxf May 1, 2026
a02aacf
fix(proxy): type openapi snapshot operation ids
stuxf May 1, 2026
2ecc79b
test(proxy): cover skill ownership propagation
stuxf May 1, 2026
f18ee03
fix(proxy): isolate ownership persistence paths
stuxf May 1, 2026
e9fb89b
fix(proxy): avoid misleading multi-method operation ids
stuxf May 1, 2026
8ced8d2
Merge remote-tracking branch 'origin/litellm_internal_staging' into HEAD
stuxf May 1, 2026
d812a53
fix managed container routing after staging merge
stuxf May 1, 2026
6c37e9d
fix(proxy): handle ownership-recording failures after upstream create
stuxf May 2, 2026
22ced8d
Merge upstream/litellm_internal_staging into HEAD
stuxf May 2, 2026
6194028
perf(proxy): cache container/skill ownership reads on the hot path
stuxf May 2, 2026
c01f209
fix(proxy): forward decoded container ids after ownership checks
stuxf May 2, 2026
4fa5778
fix(container): keep ownership-filter exceptions out of the LLM-error…
stuxf May 4, 2026
ec9b84d
chore(container,skills): LRU eviction for owner caches; widen file_pu…
stuxf May 4, 2026
de682c8
chore(container,skills): drop legacy-access opt-out env vars
stuxf May 4, 2026
758b488
fix(ownership): reject identity-less callers instead of sharing a sen…
stuxf May 4, 2026
777862a
Merge remote-tracking branch 'upstream/litellm_internal_staging' into…
stuxf May 4, 2026
b5a14f2
Merge remote-tracking branch 'upstream/litellm_internal_staging' into…
stuxf May 4, 2026
12fe945
fix: keep skills handler FastAPI-free; fold gcs deny list into the bo…
stuxf May 4, 2026
6ce84ef
chore: simplify ownership tracking — drop thin stores, in-memory fall…
stuxf May 5, 2026
2adfa96
fix(container): cache list-allow-set, track admin-created containers
stuxf May 5, 2026
4699b3d
chore(container): use delete_cache, json-encode scope key, clean test
stuxf May 5, 2026
3dcb6bd
Merge remote-tracking branch 'upstream/litellm_internal_staging' into…
stuxf May 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 85 additions & 10 deletions litellm/llms/litellm_proxy/skills/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,44 @@
Used by the transformation layer and skills injection hook.
"""

import os
import uuid
from typing import Any, Dict, List, Optional

from litellm._logging import verbose_logger
from litellm.proxy._types import LiteLLM_SkillsTable, NewSkillRequest
from litellm.proxy._types import LiteLLM_SkillsTable, NewSkillRequest, UserAPIKeyAuth
from litellm.proxy.common_utils.resource_ownership import (
get_primary_resource_owner_scope,
get_resource_owner_scopes,
is_proxy_admin,
user_can_access_resource_owner,
)

ALLOW_UNOWNED_SKILL_ACCESS_ENV = "LITELLM_ALLOW_UNOWNED_SKILL_ACCESS"


def _allow_unowned_skill_access() -> bool:
return os.getenv(ALLOW_UNOWNED_SKILL_ACCESS_ENV, "").lower() in {
"1",
"true",
"yes",
}


def _user_can_access_skill_owner(
owner: Optional[str],
user_api_key_dict: Optional[UserAPIKeyAuth],
) -> bool:
if owner is None and user_api_key_dict is not None:
if is_proxy_admin(user_api_key_dict):
return True
if _allow_unowned_skill_access():
verbose_logger.warning(
"Allowing unowned skill access because %s is enabled",
ALLOW_UNOWNED_SKILL_ACCESS_ENV,
)
return True
return user_can_access_resource_owner(owner, user_api_key_dict)


def _prisma_skill_to_litellm(prisma_skill) -> LiteLLM_SkillsTable:
Expand Down Expand Up @@ -58,6 +91,7 @@ async def _get_prisma_client():
async def create_skill(
data: NewSkillRequest,
user_id: Optional[str] = None,
user_api_key_dict: Optional[UserAPIKeyAuth] = None,
) -> LiteLLM_SkillsTable:
"""
Create a new skill in the LiteLLM database.
Expand All @@ -72,15 +106,16 @@ async def create_skill(
prisma_client = await LiteLLMSkillsHandler._get_prisma_client()

skill_id = f"litellm_skill_{uuid.uuid4()}"
owner = get_primary_resource_owner_scope(user_api_key_dict) or user_id

skill_data: Dict[str, Any] = {
"skill_id": skill_id,
"display_title": data.display_title,
"description": data.description,
"instructions": data.instructions,
"source": "custom",
"created_by": user_id,
"updated_by": user_id,
"created_by": owner,
"updated_by": owner,
}

# Handle metadata
Expand Down Expand Up @@ -111,6 +146,7 @@ async def create_skill(
async def list_skills(
limit: int = 20,
offset: int = 0,
user_api_key_dict: Optional[UserAPIKeyAuth] = None,
) -> List[LiteLLM_SkillsTable]:
"""
List skills from the LiteLLM database.
Expand All @@ -128,16 +164,36 @@ async def list_skills(
f"LiteLLMSkillsHandler: Listing skills with limit={limit}, offset={offset}"
)

find_many_kwargs: Dict[str, Any] = {
"take": limit,
"skip": offset,
"order": {"created_at": "desc"},
}
if user_api_key_dict is not None and not is_proxy_admin(user_api_key_dict):
owner_scopes = get_resource_owner_scopes(user_api_key_dict)
if not owner_scopes:
return []
if _allow_unowned_skill_access():
find_many_kwargs["where"] = {
"OR": [
{"created_by": {"in": owner_scopes}},
{"created_by": None},
]
}
else:
find_many_kwargs["where"] = {"created_by": {"in": owner_scopes}}

skills = await prisma_client.db.litellm_skillstable.find_many(
take=limit,
skip=offset,
order={"created_at": "desc"},
**find_many_kwargs
)
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

return [_prisma_skill_to_litellm(s) for s in skills]

@staticmethod
async def get_skill(skill_id: str) -> LiteLLM_SkillsTable:
async def get_skill(
skill_id: str,
user_api_key_dict: Optional[UserAPIKeyAuth] = None,
) -> LiteLLM_SkillsTable:
"""
Get a skill by ID from the LiteLLM database.

Expand All @@ -161,10 +217,18 @@ async def get_skill(skill_id: str) -> LiteLLM_SkillsTable:
if skill is None:
raise ValueError(f"Skill not found: {skill_id}")

if not _user_can_access_skill_owner(
getattr(skill, "created_by", None), user_api_key_dict
):
raise ValueError(f"Skill not found: {skill_id}")
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

return _prisma_skill_to_litellm(skill)

@staticmethod
async def delete_skill(skill_id: str) -> Dict[str, str]:
async def delete_skill(
skill_id: str,
user_api_key_dict: Optional[UserAPIKeyAuth] = None,
) -> Dict[str, str]:
"""
Delete a skill by ID from the LiteLLM database.

Expand All @@ -189,13 +253,21 @@ async def delete_skill(skill_id: str) -> Dict[str, str]:
if skill is None:
raise ValueError(f"Skill not found: {skill_id}")

if not _user_can_access_skill_owner(
getattr(skill, "created_by", None), user_api_key_dict
):
raise ValueError(f"Skill not found: {skill_id}")

# Delete the skill
await prisma_client.db.litellm_skillstable.delete(where={"skill_id": skill_id})

return {"id": skill_id, "type": "skill_deleted"}

@staticmethod
async def fetch_skill_from_db(skill_id: str) -> Optional[LiteLLM_SkillsTable]:
async def fetch_skill_from_db(
skill_id: str,
user_api_key_dict: Optional[UserAPIKeyAuth] = None,
) -> Optional[LiteLLM_SkillsTable]:
"""
Fetch a skill from the database (used by skills injection hook).

Expand All @@ -209,7 +281,10 @@ async def fetch_skill_from_db(skill_id: str) -> Optional[LiteLLM_SkillsTable]:
LiteLLM_SkillsTable or None if not found
"""
try:
return await LiteLLMSkillsHandler.get_skill(skill_id)
return await LiteLLMSkillsHandler.get_skill(
skill_id,
user_api_key_dict=user_api_key_dict,
)
except ValueError:
return None
except Exception as e:
Expand Down
65 changes: 55 additions & 10 deletions litellm/llms/litellm_proxy/skills/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

if TYPE_CHECKING:
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
from litellm.proxy._types import UserAPIKeyAuth


class LiteLLMSkillsTransformationHandler:
Expand All @@ -44,6 +45,7 @@ def create_skill_handler(
file_type: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
user_id: Optional[str] = None,
user_api_key_dict: Optional["UserAPIKeyAuth"] = None,
_is_async: bool = False,
logging_obj: Optional["LiteLLMLoggingObj"] = None,
litellm_call_id: Optional[str] = None,
Expand Down Expand Up @@ -99,6 +101,7 @@ def create_skill_handler(
file_type=file_type,
metadata=metadata,
user_id=user_id,
user_api_key_dict=user_api_key_dict,
)

import asyncio
Expand All @@ -113,6 +116,7 @@ def create_skill_handler(
file_type=file_type,
metadata=metadata,
user_id=user_id,
user_api_key_dict=user_api_key_dict,
)
)

Expand All @@ -126,6 +130,7 @@ async def _async_create_skill(
file_type: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
user_id: Optional[str] = None,
user_api_key_dict: Optional["UserAPIKeyAuth"] = None,
) -> Skill:
"""Async implementation of create_skill."""
# Lazy import to avoid SDK dependency on proxy
Expand All @@ -145,6 +150,7 @@ async def _async_create_skill(
db_skill = await LiteLLMSkillsHandler.create_skill(
data=skill_request,
user_id=user_id,
user_api_key_dict=user_api_key_dict,
)

return self._db_skill_to_response(db_skill)
Expand All @@ -156,6 +162,7 @@ def list_skills_handler(
_is_async: bool = False,
logging_obj: Optional["LiteLLMLoggingObj"] = None,
litellm_call_id: Optional[str] = None,
user_api_key_dict: Optional["UserAPIKeyAuth"] = None,
**kwargs,
) -> Union[ListSkillsResponse, Coroutine[Any, Any, ListSkillsResponse]]:
"""
Expand All @@ -182,18 +189,27 @@ def list_skills_handler(
)

if _is_async:
return self._async_list_skills(limit=limit, offset=offset)
return self._async_list_skills(
limit=limit,
offset=offset,
user_api_key_dict=user_api_key_dict,
)

import asyncio

return asyncio.get_event_loop().run_until_complete(
self._async_list_skills(limit=limit, offset=offset)
self._async_list_skills(
limit=limit,
offset=offset,
user_api_key_dict=user_api_key_dict,
)
)

async def _async_list_skills(
self,
limit: int = 20,
offset: int = 0,
user_api_key_dict: Optional["UserAPIKeyAuth"] = None,
) -> ListSkillsResponse:
"""Async implementation of list_skills."""
# Lazy import to avoid SDK dependency on proxy
Expand All @@ -202,6 +218,7 @@ async def _async_list_skills(
db_skills = await LiteLLMSkillsHandler.list_skills(
limit=limit,
offset=offset,
user_api_key_dict=user_api_key_dict,
)

skills = [self._db_skill_to_response(s) for s in db_skills]
Expand All @@ -217,6 +234,7 @@ def get_skill_handler(
_is_async: bool = False,
logging_obj: Optional["LiteLLMLoggingObj"] = None,
litellm_call_id: Optional[str] = None,
user_api_key_dict: Optional["UserAPIKeyAuth"] = None,
**kwargs,
) -> Union[Skill, Coroutine[Any, Any, Skill]]:
"""
Expand All @@ -242,20 +260,33 @@ def get_skill_handler(
)

if _is_async:
return self._async_get_skill(skill_id=skill_id)
return self._async_get_skill(
skill_id=skill_id,
user_api_key_dict=user_api_key_dict,
)

import asyncio

return asyncio.get_event_loop().run_until_complete(
self._async_get_skill(skill_id=skill_id)
self._async_get_skill(
skill_id=skill_id,
user_api_key_dict=user_api_key_dict,
)
)

async def _async_get_skill(self, skill_id: str) -> Skill:
async def _async_get_skill(
self,
skill_id: str,
user_api_key_dict: Optional["UserAPIKeyAuth"] = None,
) -> Skill:
"""Async implementation of get_skill."""
# Lazy import to avoid SDK dependency on proxy
from litellm.llms.litellm_proxy.skills.handler import LiteLLMSkillsHandler

db_skill = await LiteLLMSkillsHandler.get_skill(skill_id=skill_id)
db_skill = await LiteLLMSkillsHandler.get_skill(
skill_id=skill_id,
user_api_key_dict=user_api_key_dict,
)
return self._db_skill_to_response(db_skill)

def delete_skill_handler(
Expand All @@ -264,6 +295,7 @@ def delete_skill_handler(
_is_async: bool = False,
logging_obj: Optional["LiteLLMLoggingObj"] = None,
litellm_call_id: Optional[str] = None,
user_api_key_dict: Optional["UserAPIKeyAuth"] = None,
**kwargs,
) -> Union[DeleteSkillResponse, Coroutine[Any, Any, DeleteSkillResponse]]:
"""
Expand All @@ -289,20 +321,33 @@ def delete_skill_handler(
)

if _is_async:
return self._async_delete_skill(skill_id=skill_id)
return self._async_delete_skill(
skill_id=skill_id,
user_api_key_dict=user_api_key_dict,
)

import asyncio

return asyncio.get_event_loop().run_until_complete(
self._async_delete_skill(skill_id=skill_id)
self._async_delete_skill(
skill_id=skill_id,
user_api_key_dict=user_api_key_dict,
)
)

async def _async_delete_skill(self, skill_id: str) -> DeleteSkillResponse:
async def _async_delete_skill(
self,
skill_id: str,
user_api_key_dict: Optional["UserAPIKeyAuth"] = None,
) -> DeleteSkillResponse:
"""Async implementation of delete_skill."""
# Lazy import to avoid SDK dependency on proxy
from litellm.llms.litellm_proxy.skills.handler import LiteLLMSkillsHandler

result = await LiteLLMSkillsHandler.delete_skill(skill_id=skill_id)
result = await LiteLLMSkillsHandler.delete_skill(
skill_id=skill_id,
user_api_key_dict=user_api_key_dict,
)
return DeleteSkillResponse(
id=result["id"],
type=result.get("type", "skill_deleted"),
Expand Down
Loading
Loading