Skip to main content
Production deployments need secure credential management, environment-specific configurations, and proper secret handling. This guide covers advanced authentication patterns.
For basic SDK setup, see the Quickstart. This page covers production-ready authentication patterns.

Using .env Files for Local Development

For local development, use environment variable management tools to load secrets from a .env file: 1. Create a .env file with your api key:
.env
BREAD_API_KEY=your_api_key_here
2. Load in your application:
Install python-dotenv:
pip install python-dotenv
Or using uv:
uv pip install python-dotenv
Then load in your application:
import os
from dotenv import load_dotenv
from aibread import Bread

load_dotenv()  # Loads .env file

client = Bread(api_key=os.environ.get("BREAD_API_KEY"))
Note: If BREAD_API_KEY is already set as an environment variable (e.g., in production), you don’t need python-dotenv. The SDK will automatically read from the environment variable if you instantiate without passing api_key:
from aibread import Bread

# SDK automatically reads BREAD_API_KEY from environment
client = Bread()
Add .env to your .gitignore to prevent committing secrets to version control:
echo ".env" >> .gitignore

Supported Environment Variables

The SDK reads these environment variables:
VariableDescriptionDefault
BREAD_API_KEYAPI authentication keyRequired
BREAD_LOGLogging level (info or debug)None

Best Practices

Store API keys in environment variables, not in source code. This makes it easy to rotate keys and use different keys per environment.
Add .env and any files containing secrets to .gitignore. Use secret management systems in production.
Track API key usage to detect unauthorized access or anomalous behavior.

Secret Management in Production

For production deployments, use secure secret management:
import boto3
from aibread import Bread

def get_secret():
    client = boto3.client('secretsmanager', region_name='us-east-1')
    response = client.get_secret_value(SecretId='bread/api_key')
    return response['SecretString']

bread_client = Bread(api_key=get_secret())

Next Steps