Authentication
Learn how to securely authenticate with the ViewAI API using API keys, environment variables, and configuration options.
Overview
The ViewAI SDK uses API key authentication to secure access to the platform. API keys are unique identifiers that authenticate your applications and track usage.
Getting an API Key
Authentication Methods
Method 1: Direct API Key (Quick Testing)
Pass your API key directly when initializing the client:
from viewai_client import ViewAIClient
client = ViewAIClient(api_key="your-api-key-here")Use Case: Quick testing, interactive sessions, Jupyter notebooks
⚠️ Warning: Not recommended. API key is visible in code.
Method 2: Environment Variables (Recommended)
The most secure method for production applications:
Setting Environment Variables:
Use Case: Production applications, CI/CD pipelines, Docker containers
Method 3: Configuration File
Use a .env file with python-dotenv:
.env file:
Python code:
Use Case: Local development, team collaboration
Important: Add .env to your .gitignore!
Method 4: Configuration Object
For advanced configuration:
Use Case: Complex applications, custom configurations
Verifying Authentication
Always verify your authentication before performing operations:
Security Best Practices
Never expose your API keys in source code or logs. The examples below show bad and good practices for handling keys.
Never Hardcode API Keys
❌ Bad:
✅ Good:
Use Environment Variables
Store API keys in environment variables or secret management systems:
Rotate API Keys Regularly
Generate a new API key in the dashboard
Update your environment variables
Test with the new key
Revoke the old key
Use Different Keys for Different Environments
Restrict API Key Permissions
In your ViewAI dashboard:
Set IP whitelist restrictions
Limit workspace access
Set rate limits
Enable monitoring and alerts
Don't Log API Keys
❌ Bad:
✅ Good:
Platform-Specific Setup
Docker
Dockerfile:
docker-compose.yml:
Usage:
Kubernetes
Secret:
Deployment:
AWS
Using AWS Secrets Manager:
GitHub Actions
.github/workflows/deploy.yml:
Add secret in GitHub: Settings → Secrets → Actions → New repository secret
Configuration Options
Complete Configuration Example
Environment Variables Reference
VIEWAI_API_KEY
Your API key
Required
VIEWAI_BASE_URL
API endpoint
https://api.viewai.ca
VIEWAI_TIMEOUT
Request timeout (seconds)
30
VIEWAI_MAX_RETRIES
Maximum retry attempts
3
VIEWAI_LOG_LEVEL
Logging level
INFO
Error Handling
Handle authentication errors gracefully:
Testing Authentication
Create a test script:
Run the test:
Troubleshooting
Issue: Authentication Failed
Check:
Is your API key correct?
Has the key been revoked?
Are there IP restrictions?
Is the key expired?
Solution:
Issue: Connection Timeout
Solution:
Issue: Rate Limit Exceeded
Solution:
Next Steps
📘 Core Concepts - Understand workspaces and projects
🚀 Quick Start - Build your first model
🔐 Best Practices - Production security patterns
Additional Resources
https://app.viewai.ca/settings/api-keys
/advanced/best-practices.md#security
mailto:[email protected]
Security Question? Contact [email protected]
Last updated
Was this helpful?