Skip to main content
Authenticate with an API key or a bearer token. Configure credentials directly or through environment variables.

API Key

Set PHALA_CLOUD_API_KEY in your environment and the SDK picks it up automatically:
This is the recommended approach for production deployments and CI/CD pipelines. It keeps credentials out of your source code.

Explicit API Key

Pass the key directly when creating the client:
The explicit api_key parameter takes precedence over the environment variable.

Bearer token and workspace

Set bearer_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.
A nonempty explicit value takes precedence over its environment variable. If both an API key and a bearer token are configured, the API key is used. Workspace names are stripped of surrounding whitespace.

Environment Variables

These variables are read at client creation time. Changing them after the client is created has no effect. 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

Call get_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-configured httpx client:
The SDK applies its configured authentication, workspace, and version headers to requests made with the provided client. Configure that client with a base URL for relative API paths. The SDK does not close it automatically. You are responsible for calling http.close() when done.