Namespace for type definitions of different API operations.
This class organizes type definitions for create, read, update, delete, and search operations across different resources (threads, assistants, crons).
Start by denying all requests by default, then add handlers to allow access:
from langgraph_sdk import Auth
auth = Auth()
# Default deny: reject all requests without a specific handler
@auth.on
async def deny_all(ctx: Auth.types.AuthContext, value: Auth.on.value):
return False
# Allow thread creation, stamping the owner
@auth.on.threads.create
async def allow_thread_create(ctx: Auth.types.AuthContext, value: Auth.on.threads.create.value):
value.setdefault("metadata", {})["owner"] = ctx.user.identity
# Allow assistant search, scoped to user's resources
@auth.on.assistants.search
async def allow_assistant_search(ctx: Auth.types.AuthContext, value: Auth.on.assistants.search.value):
return {"owner": ctx.user.identity}on()