API Key
Environment Variable (Recommended)
SetPHALA_CLOUD_API_KEY in your environment and the SDK picks it up automatically:
Explicit API Key
Pass the key directly when creating the client:api_key parameter takes precedence over the environment variable.
Bearer token and workspace
Setbearer_token to authenticate with a bearer token, including an OIDC token. Set workspace to select a workspace by slug. The SDK also reads PHALA_OIDC_TOKEN and PHALA_CLOUD_WORKSPACE.
Environment Variables
These variables are read at client creation time. Changing them after the client is created has no effect.
Cookie-Based Auth
For browser-like environments, the SDK supports cookie-based authentication instead of API keys. When enabled, the SDK does not add an API key or bearer authorization header. Authentication relies on cookies managed by the HTTP client.Cookie-based auth is primarily for internal use. Most users should stick with API key authentication.
revoke_current_api_token
DELETE /tokens/self
Call client.revoke_current_api_token() to revoke the API token used for the request. It returns None. The token stops working immediately and cannot be restored. The async client supports await client.revoke_current_api_token(); a safe_revoke_current_api_token variant is also available.
Custom Headers
You can add extra headers to every request. This is useful for tracing, debugging, or passing custom metadata.Verifying Authentication
Callget_current_user() to verify your credentials are valid:
Bring Your Own HTTP Client
If you need full control over transport settings (proxies, certificates, connection pooling), pass a pre-configuredhttpx client:
Related
- SDK Overview — installation and quick start
- Error Handling — handling
AuthError

