theauth package is the Python client for the theAuth REST API. It is built on httpx and ships a sync client and an async client with the same surface. Python 3.9 or newer.
Installation
Create a client
Resources
MCP servers
Plugin routes
Call routes declared withdefineEndpoint through request(). It returns the parsed JSON body.
ValidationError with the server issues. A 403 CSRF_REJECTED raises PermissionError, and a 429 raises RateLimitError with retry_after.
DPoP
DPoPAuth signs each request with an ES256 key pair, as described in RFC 9449.
- The
Authorizationheader becomesDPoP <token>and the proof carries anathclaim. htudrops the query and fragment.- The server
DPoP-Nonceis cached per origin and ause_dpop_nonceresponse is retried once.
DPoPAuth is a plain httpx.Auth, so you can also pass it to your own httpx.Client or httpx.AsyncClient. The cryptography package is imported lazily and a clear error is raised if it is missing.Devices
client.devices is the registry and needs a user or admin token. client.device is what a device calls as itself: enroll, authorize, fetch an offline policy bundle.
DeviceAssertionSigner signs the device-assertion+jwt the server verifies. It makes a new assertion for every call because the server accepts each jti once. It needs the cryptography extra, like DPoP.
Step-up
A 401 witherror="insufficient_user_authentication" (RFC 9470) raises StepUpRequiredError, a subclass of AuthenticationError. error.challenge.authorize_params() gives the acr_values and max_age for the new authorization request.
acr_satisfies and auth_is_fresh check a token’s acr and auth_time before you call.
Bound tokens and input provenance
Passcnf=dpop_confirmation(prover) to CreateAgentInput to bind an agent token to a DPoP key (RFC 7800). client.agents.rotate(id) keeps the binding, rotate(id, cnf=None) removes it. AuthorizeRequest(inputs=[ProvenanceInput("user_message", content=text)]) records what the model had in context; the server hashes the content and does not store it.
Errors
All exceptions inherit fromTheAuthError and carry code, message and status_code.
Related
Client SDK
The TypeScript fetch client this package mirrors.
Expo
React Native and Expo integration.