from definable.agent import Agent
from definable.agent.auth import APIKeyAuth, AllowlistAuth, CompositeAuth
from definable.model.openai import OpenAIChat
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
)
# Composite auth: API keys for HTTP + allowlist for Telegram
agent.auth = CompositeAuth(
APIKeyAuth(keys={"sk-my-api-key"}),
AllowlistAuth(
user_ids={"telegram-user-123", "telegram-user-456"},
platforms={"telegram"},
),
)
# Public webhook (no auth)
@agent.on(Webhook("/public-hook", auth=False))
async def public_endpoint(event):
return "Public response"
# Auth context in hooks
@agent.before_request
async def log_auth(context):
if hasattr(context, "auth") and context.auth:
print(f"Authenticated: {context.auth.user_id}")
agent.serve(port=8000)