Get your API key
Log in to Avala
Navigate to app.avala.ai
Set environment variable (recommended)
The simplest and most secure method is to set theAVALA_API_KEY environment variable:
Pass the key explicitly
Alternatively, pass the API key directly when creating the client:Use a .env file
For local development, use a .env file to manage secrets:
Configure async client
The async client uses the same authentication methods:Handle authentication errors
The SDK raisesAuthenticationError when the API key is invalid or missing:
If you don’t provide an API key and
AVALA_API_KEY is not set, the client will raise a ValueError during initialization—before making any API requests.Production deployment
Environment variables
For production deployments, use your platform’s secret management:AWS Secrets Manager
Google Cloud Secret Manager
Security best practices
Never commit API keys
Never commit API keys
Always use environment variables or secret management systems. Add
.env to .gitignore and audit your repository for accidentally committed secrets.Rotate keys regularly
Rotate keys regularly
Generate new API keys periodically and revoke old ones. This limits the impact of a potential key compromise.
Use separate keys per environment
Use separate keys per environment
Create different API keys for development, staging, and production. This allows you to revoke a compromised key without affecting other environments.
Restrict key permissions
Restrict key permissions
Use the principle of least privilege. If Avala supports scoped API keys in the future, grant only the minimum permissions needed.
Monitor key usage
Monitor key usage
Regularly review API key usage in your Avala dashboard to detect unauthorized access.
Custom base URL
By default, the SDK connects tohttps://api.avala.ai/api/v1. For testing or on-premises deployments, override the base URL:
AVALA_BASE_URL environment variable:
Local development
Troubleshooting
ValueError: No API key provided
ValueError: No API key provided
The SDK couldn’t find your API key. Ensure
AVALA_API_KEY is set or pass api_key= explicitly:AuthenticationError: Invalid API key
AuthenticationError: Invalid API key
Your API key is incorrect or has been revoked. Generate a new key from the Avala dashboard and update your configuration.
AuthenticationError: API key expired
AuthenticationError: API key expired
Some API keys may have expiration dates. Check your dashboard and generate a new key if needed.
ValueError: Invalid base_url
ValueError: Invalid base_url
The
base_url must be a valid URL with a scheme (http/https) and host. Check your AVALA_BASE_URL environment variable or base_url parameter.Next steps
Quickstart
Make your first API calls with the authenticated client
Error Handling
Handle authentication errors gracefully