Documentation Index
Fetch the complete documentation index at: https://docs.alterauth.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Thealter-sdk[fastapi] extra provides AlterFastAPI, a FastAPI dependency that automatically captures Bearer tokens from incoming requests and makes them available to the SDK for identity resolution. No manual ContextVar or header extraction needed.
Quick Start
Depends(alter) does two things per request:
- Extracts the
Authorization: Bearer <token>header (returns 403 if missing) - Returns the configured
AlterVaultinstance with the token available for identity resolution
How It Works
Under the hood,AlterFastAPI uses a task-scoped ContextVar to isolate tokens across concurrent requests. Each call to Depends(alter) captures the Bearer token for that specific request, so the SDK resolves the correct user identity when calling vault.request(provider=...).
This replaces the manual pattern that previously required writing a ContextVar, a Bearer extraction helper, and wiring them together:
Combined FastAPI + MCP Server
When building a server that exposes both REST endpoints and MCP tools, usealter.auth_provider() to create an MCP auth provider that shares the same identity context:
AlterVault instance and identity resolution — the REST path captures tokens via Depends(alter), and the MCP path captures them via auth.verify_token().
API Reference
AlterFastAPI(api_key, *, caller=None, **kwargs)
Creates a FastAPI-integrated vault wrapper.
| Parameter | Type | Description |
|---|---|---|
api_key | str | Alter Vault API key |
caller | str | None | Caller identifier for audit logs |
**kwargs | Additional arguments passed to AlterVault (except user_token_getter) |
alter.vault
The underlying AlterVault instance. Use this when a function needs the vault directly (e.g., @alter_tool(alter.vault, provider=...)).
alter.set_user_token(token)
Manually set the user token for the current request context. Use in custom auth flows or middleware that captures tokens outside the standard Depends(alter) path.
alter.auth_provider(*, base_url="", providers=None)
Create an MCP auth provider (full OAuth 2.0 Authorization Server) that auto-captures verified tokens for identity resolution.
| Parameter | Type | Description |
|---|---|---|
base_url | str | URL where the MCP server is mounted, used as the OAuth issuer (e.g., "http://localhost:8000/mcp") |
providers | dict[str, list[str]] | None | Map of provider_id to required scopes for Alter Connect |