Get your API key
- Sign in at alphacast.io.
- Click your user avatar in the left sidebar to open Account Settings.
- Find or generate your key under the API Key section.
Initialize the client
Pass the key to theAlphacast constructor. Every method called on the resulting client uses that key:
Recommended: read from an environment variable
Hardcoding API keys in your code makes it easy to leak them by accident. Read the key from an environment variable instead:Loading from a .env file
The SDK declares python-dotenv as a dependency, so you can keep your key in a local .env file:
Errors
If the API key is missing or invalid, the SDK raises anException whose message includes the HTTP status code returned by the server. The most common case is 401:
- 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).
How the SDK uses your key
Internally, every method in the SDK callsrequests.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.