Workflow Examples
Connection & Authentication
Setup workflows for connecting to managed Reflexio Enterprise and a self-hosted open-source server.
Connection & Authentication
Setup workflows for the two supported deployment modes: Managed Reflexio Enterprise (hosted at https://www.reflexio.ai) and self-hosted open source (the FastAPI server you run yourself). For initialization details, see the Client Initialization Reference.
Managed Enterprise Authentication
Enterprise
API key authentication and the hosted endpoint at https://www.reflexio.ai require a Reflexio Enterprise account.
Environment Variable (Recommended)
import reflexio
# export REFLEXIO_API_KEY="your-api-key"
client = reflexio.ReflexioClient()
response = client.get_config()
print("Client connected to Enterprise")Direct API Key
import reflexio
client = reflexio.ReflexioClient(api_key="your-api-key")Local / Self-Hosted
Direct URL
import reflexio
client = reflexio.ReflexioClient(url_endpoint="http://localhost:8081")
response = client.get_config()
print("Client connected to local server")Environment Variable
import reflexio
# export REFLEXIO_API_URL="http://localhost:8081"
client = reflexio.ReflexioClient()
response = client.get_config()
print("Client connected via environment variable")Advanced Authentication Patterns
Enterprise
API key persistence and validation are only relevant for managed Reflexio Enterprise — self-hosted open-source servers do not require API keys by default.
API Key Persistence and Validation
import json
import os
from pathlib import Path
import reflexio
class ReflexioAuthManager:
"""Manages authentication with API key persistence."""
def __init__(self, token_file: str = ".reflexio_token"):
self.token_file = Path(token_file)
self.client = None
def authenticate(self, api_key: str = None, save_key: bool = True):
"""
Authenticate with API key, optionally loading from file.
Args:
api_key: API key to use. If None, tries to load from file or environment.
save_key: Whether to save the API key to file for reuse.
"""
# Try to load existing key if none provided
if api_key is None:
api_key = self._load_key()
if api_key is None:
raise ValueError("No API key provided and none found in file or environment")
self.client = reflexio.ReflexioClient(api_key=api_key)
# Validate the key works
if not self._validate_key():
raise ValueError("API key validation failed")
# Save key for future use
if save_key:
self._save_key(api_key)
print("Authentication successful")
return True
def _save_key(self, api_key: str):
"""Save API key to file."""
with open(self.token_file, 'w') as f:
json.dump({"api_key": api_key}, f)
# Set restrictive permissions
os.chmod(self.token_file, 0o600)
def _load_key(self) -> str:
"""Load API key from file."""
if self.token_file.exists():
with open(self.token_file, 'r') as f:
token_data = json.load(f)
return token_data.get("api_key")
return None
def _validate_key(self) -> bool:
"""Validate that the current API key works."""
try:
self.client.get_config()
return True
except Exception:
return False
# Usage
auth_manager = ReflexioAuthManager()
auth_manager.authenticate(api_key="your-api-key")
# Client is now ready to use
client = auth_manager.client