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

1

Create an Account

  • Visit https://app.viewai.ca

  • Sign up for a free account

  • Verify your email address

2

Generate API Key

  • Log in to your ViewAI dashboard

  • Navigate to SettingsAPI Keys

  • Click Generate New API Key

  • Copy your API key (you won't be able to see it again!)

  • Store it securely

Warning: Never commit API keys to version control or share them publicly.

Authentication Methods

Method 1: Direct API Key (Quick Testing)

Pass your API key directly when initializing the client:

example.py
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.

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 Hardcode API Keys

❌ Bad:

✅ Good:

Use Environment Variables

Store API keys in environment variables or secret management systems:

Rotate API Keys Regularly

1

Generate a new API key in the dashboard

2

Update your environment variables

3

Test with the new key

4

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: SettingsSecretsActionsNew repository secret

Configuration Options

Complete Configuration Example

Environment Variables Reference

Variable
Description
Default

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

Security Question? Contact [email protected]

Last updated

Was this helpful?