Reference
Python SDK
Async operations for OAuth and managed-secret credentials. Provider credentials are never returned to application code.
The Python SDK ships as the alter-sdk package on PyPI. Python 3.11+.
pip install alter-sdkfrom alter_sdk import App, Agent, HttpMethod, ProviderTwo clients
Section titled “Two clients”The SDK exposes two top-level clients. They share the request surface but differ in principal and identity scoping.
Construct with an alter_rk_… key. Acts as the application — provisions agents, mints Connect sessions, manages grants, and proxies provider calls under stored grants.
Construct with an alter_ak_… key. Workload-scoped: can only reach credentials delegated or directly bound to the agent. The right entry point for AI agents and tool-calling workloads.
Both classes expose async network and lifecycle methods. Always close them (await app.close()) or use them as async context managers.
async with App(api_key="alter_rk_…") as app: page = await app.list_grants()Reference
Section titled “Reference”App and Agent constructors, lifecycle, with_constraints, get_agent, is_valid_key.
request(), proxy_request(), scopes.list(), and spans.emit().
provider_specs.* metadata, operation search, and request/response schemas.
Connect sessions, grant CRUD, delegation revoke, managed-secret grants, HITL approvals.
Agents & Keysapp.agents.* CRUD, Agent.me / trace / with_constraints, keys.derive / rotate / revoke.
Pydantic models returned across the SDK surface.
ErrorsTyped exception hierarchy.
FastAPIAlterFastAPI dependency for automatic JWT capture.
@alter_tool decorator and AlterMCPInterceptor.
AlterMCP, AlterAuthProvider, AlterContext for FastMCP servers.
Configuration
Section titled “Configuration”The constructor accepts an api_key argument; application code is responsible for sourcing it. The convention is to read it from the process environment:
| Variable | Used by | Description |
|---|---|---|
ALTER_API_KEY | application code (typical app workload) | Conventional name when the application owns one app-level key. |
AGENT_API_KEY | application code (agent workload) | Conventional name when the workload runs as a managed agent. |
For agent workloads, the convention is to read AGENT_API_KEY in application code:
import osfrom alter_sdk import Agent
agent = Agent(api_key=os.environ["AGENT_API_KEY"])Conventions
Section titled “Conventions”- Network and lifecycle methods are
async. Constructors, properties,with_constraints(),get_agent(),trace(), andis_valid_key()are synchronous. - Response and input models are Pydantic objects with
snake_casefields matching the wire format. Most are frozen;APICallAuditLog,UserSpan, andEmitSpansResultare mutable. - Methods that retrieve tokens never return the token plaintext. The SDK injects it into the outbound request.
- Public exceptions inherit from
AlterSDKError. See Errors.