Skip to main content
The Python SDK authenticates requests using an API key sent via the X-API-Key header. You can provide the key directly or through an environment variable.

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.

Environment Variables

Both 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 X-API-Key header is not sent, and 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.

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:
When you provide your own http_client, the SDK does not close it automatically. You are responsible for calling http.close() when done.