# Set your API keyexport CEREVOX_API_KEY="your-api-key-here"
Copy
from cerevox import Lexa# Client automatically reads from CEREVOX_API_KEYclient = Lexa()# Test it worksdocuments = client.parse(b"Test authentication")print("✅ Authenticated successfully!")
Most secure method - keeps keys out of your code
Best for: Production applications and general use
Copy
# Set your API keyexport CEREVOX_API_KEY="your-api-key-here"
Copy
from cerevox import Lexa# Client automatically reads from CEREVOX_API_KEYclient = Lexa()# Test it worksdocuments = client.parse(b"Test authentication")print("✅ Authenticated successfully!")
Most secure method - keeps keys out of your code
Best for: Quick testing and prototyping
Copy
from cerevox import Lexa# Pass API key directlyclient = Lexa(api_key="your-api-key-here")# For async operationsfrom cerevox import AsyncLexaasync def main(): async with AsyncLexa(api_key="your-api-key-here") as client: documents = await client.parse(["document.pdf"])
Don’t hardcode keys in production - use environment variables instead
Best for: Local development
.env
Copy
# Create .env file in your project rootCEREVOX_API_KEY=your-api-key-here
from cerevox import Lexa, LexaErrordef test_auth(): try: client = Lexa() # Test with sample content documents = client.parse(b"Authentication test content") if documents: print("✅ Authentication successful!") print(f"📄 Parsed: {documents[0].content}") return True except LexaError as e: print(f"❌ API Error: {e.message}") if "authentication" in e.message.lower(): print("💡 Check your API key at cerevox.ai/lexa") return False except Exception as e: print(f"❌ Error: {e}") return False# Run the testtest_auth()
# Check for extra spaces/quotesimport osapi_key = os.getenv('CEREVOX_API_KEY', '').strip()print(f"Key length: {len(api_key)}")print(f"First 8 chars: {api_key[:8]}")# Get a fresh key from cerevox.ai/lexa if neededclient = Lexa(api_key=api_key)
Error:No API key provided
Quick fixes:
Copy
# Check if it's setecho $CEREVOX_API_KEY# Set it (Linux/Mac)export CEREVOX_API_KEY="your-key"# Set it (Windows)set CEREVOX_API_KEY=your-key# Verify in Pythonimport os; print(os.getenv('CEREVOX_API_KEY'))
Error:Connection timeout or network errors
Quick fixes:
Copy
# Increase timeoutclient = Lexa(timeout=180.0)# Check proxy settings if neededimport osos.environ['HTTPS_PROXY'] = 'http://your-proxy:port'# Test with smaller content firstclient.parse(b"small test")
FROM python:3.9-slimWORKDIR /appCOPY requirements.txt .RUN pip install -r requirements.txtCOPY . .# API key provided at runtime, not in imageCMD ["python", "app.py"]
Copy
# Run with API keydocker run -e CEREVOX_API_KEY="your-key" my-lexa-app
Copy
FROM python:3.9-slimWORKDIR /appCOPY requirements.txt .RUN pip install -r requirements.txtCOPY . .# API key provided at runtime, not in imageCMD ["python", "app.py"]
Copy
# Run with API keydocker run -e CEREVOX_API_KEY="your-key" my-lexa-app