NewClient returns an error if neither is configured.
API Key via Option
The most explicit way to authenticate is passingWithAPIKey when creating the client.
API Key via Environment Variable
For production deployments, storing the key in an environment variable is the standard approach. The SDK readsPHALA_CLOUD_API_KEY automatically when no explicit key is provided.
If you pass
WithAPIKey explicitly, it always takes priority over the environment variable.Bearer token and workspace
UseWithBearerToken for bearer credentials, including an OIDC token, and WithWorkspace to select a workspace by slug. The SDK also reads PHALA_OIDC_TOKEN and PHALA_CLOUD_WORKSPACE. An API key takes precedence over a bearer token when both are configured. This also applies to credentials supplied with WithHeader: if the final request has an API key, the SDK removes its authorization header.
RevokeSelfToken
DELETE /tokens/self
client.RevokeSelfToken(ctx) revokes the API token used for the request. The token stops working immediately and cannot be restored.
Custom Base URL
You can override the API endpoint withWithBaseURL or the PHALA_CLOUD_API_PREFIX environment variable. The SDK defaults to https://cloud-api.phala.com/api/v1.
Custom Headers
UseWithHeader to attach additional headers to every request. This is useful for tracing, correlation IDs, or internal routing.
WithHeader adds one header. You can call it multiple times to set several headers.
API Versioning
The SDK sends an API version header with every request. The default is"2026-06-23". Override it if you need an older response shape.
Custom HTTP Client
For advanced scenarios like custom TLS configuration, proxies, or instrumented transports, pass your own*http.Client with WithHTTPClient.
User Agent
The SDK sends aUser-Agent header like phala-cloud-sdk-go/0.3.0 by default. Override it to identify your application in server logs.
Resolution Priority
The client resolves configuration in this order (first match wins):- Explicit option passed to
NewClient(e.g.,WithAPIKey,WithBaseURL) - Environment variable (
PHALA_CLOUD_API_KEY,PHALA_CLOUD_API_PREFIX) - Built-in default (base URL:
https://cloud-api.phala.com/api/v1)

