Required variables
OPENAI_API_KEY
Purpose: Authentication for OpenAI API (embeddings and LLM) Used by:OpenAIEmbeddingsfor document and query embeddingsChatOpenAIfor answer generation
- Create an account at platform.openai.com
- Navigate to API keys section
- Create a new secret key
- Copy the key (it will only be shown once)
The system uses
text-embedding-3-small for embeddings and gpt-4.1 for generation. Ensure your API key has access to these models.UNSTRUCTURED_API_KEY
Purpose: Authentication for Unstructured.io API (document parsing) Used by:- Document ingestion pipeline (
src/rag/ingest.py) - Markdown file parsing and chunking
- Sign up at unstructured.io
- Navigate to API settings
- Generate an API key
The Unstructured API is only needed for document ingestion. If you’re only querying the RAG system (not adding new documents), this key is optional.
Configuration file
Create a.env file in the project root:
.env
Loading environment variables
The system automatically loads variables from.env using python-dotenv:
src/config.py
Setting variables by environment
- Development (local)
- Docker
- Production
- CI/CD
Create a The application will automatically load these values.
.env file in the project root:Optional configuration
While not currently configurable via environment variables, these settings can be modified in the source code:LLM configuration
Located insrc/rag/retriever.py:
Vector store configuration
Located inSimpleRetrievalAgent.__init__:
API server configuration
Located inmain.py:
Verification
Verify your environment variables are loaded correctly:Troubleshooting
KeyError: 'OPENAI_API_KEY'
KeyError: 'OPENAI_API_KEY'
Cause: Environment variable not set or
.env file not foundSolutions:- Check
.envfile exists in project root - Verify variable name spelling (case-sensitive)
- Ensure
python-dotenvis installed:uv sync - Try loading manually:
export OPENAI_API_KEY=your_key
OpenAI AuthenticationError
OpenAI AuthenticationError
Error:
openai.AuthenticationError: Invalid API keyCauses:- Invalid or expired API key
- Whitespace in the key value
- Key not activated in OpenAI dashboard
- Regenerate API key in OpenAI dashboard
- Copy key without extra spaces
- Update
.envfile - Restart the application
Rate limit errors
Rate limit errors
Error:
RateLimitError: Rate limit exceededCause: Too many API requests in a short periodSolutions:- Check OpenAI dashboard for current limits
- Upgrade to a paid tier for higher limits
- Implement request throttling
- Use caching for repeated queries
Environment variables not loading in Docker
Environment variables not loading in Docker
Cause: Verify:
.env file not mounted or env_file not configuredSolution:docker-compose.yml
Security checklist
Use separate keys per environment
- Development: Test API key with rate limits
- Staging: Separate key for integration testing
- Production: Dedicated key with monitoring
Rotate keys regularly
- Generate new keys every 90 days
- Update all deployment environments
- Revoke old keys immediately
Next steps
Docker deployment
Deploy using Docker and Docker Compose
Production deployment
Production best practices and scaling
Installation
Complete installation guide
Quickstart
Get started in 5 minutes