How the Alphacast Python SDK authenticates requests with your API key, plus best practices for storing the key safely.
The Alphacast Python SDK authenticates every request with your personal API key. Internally the SDK uses HTTP Basic Auth — your key is sent as the username with an empty password, exactly as documented for the REST API. You only need to provide the key once when you create the client.
Your API key grants full access to your Alphacast account. Do not commit it to source control, share it in chat or screenshots, or embed it in client-side code that ships to users.
If the API key is missing or invalid, the SDK raises an Exception whose message includes the HTTP status code returned by the server. The most common case is 401:
Exception: API failed with status code 401
Common causes:
The key was mistyped or copied with leading/trailing whitespace.
The key was revoked or regenerated from the Alphacast UI.
The key belongs to an account that no longer has access to the requested resource (in which case you may also see 403).
If you suspect your key has been exposed, regenerate it from your account settings. Regenerating immediately invalidates the old key.
Internally, every method in the SDK calls requests.get, requests.post, requests.put, or requests.delete with auth=HTTPBasicAuth(self.api_key, ""). The Search endpoint is the one exception — it sends the key as an apiKey query parameter because the search endpoint lives on the workspace host (alphacast.io) rather than on api.alphacast.io. Both transports are equivalent in terms of authority — both grant the same access — but Basic Auth is preferred for everything that supports it because the credential travels in the Authorization header rather than in the URL.