Complete guide to configuring LLM providers for QWED.
- Copy
.env.exampleto.env - Choose your LLM provider
- Add your API key
- Run QWED backend
cp .env.example .env
# Edit .env and add your API key
export ACTIVE_PROVIDER=anthropic
python -m qwed_apiBest for: Simple setup, standard OpenAI models
Get API Key: https://platform.openai.com/api-keys
Configuration:
ACTIVE_PROVIDER=openai
OPENAI_API_KEY=sk-proj-...
OPENAI_MODEL=gpt-4 # or gpt-3.5-turbo, gpt-4-turboPython Code:
# In your backend code
from qwed_new.config import settings
print(settings.OPENAI_API_KEY) # Verify it's loadedBest for: Latest Claude models, simple API
Get API Key: https://console.anthropic.com
Configuration:
ACTIVE_PROVIDER=anthropic
ANTHROPIC_API_KEY=sk-ant-api03-...
ANTHROPIC_MODEL=claude-3-5-sonnet-20241022 # or claude-3-opus-20240229Available Models:
claude-3-5-sonnet-20241022(Recommended)claude-3-opus-20240229claude-3-haiku-20240307
Best for: Enterprise deployments, compliance requirements
Get Credentials: https://portal.azure.com → Azure OpenAI Service
Configuration:
ACTIVE_PROVIDER=azure_openai
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_API_KEY=abc123...
AZURE_OPENAI_DEPLOYMENT=gpt-4 # Your deployment name in Azure
AZURE_OPENAI_API_VERSION=2024-02-01How to Get:
- Go to Azure Portal
- Navigate to your Azure OpenAI resource
- Click "Keys and Endpoint"
- Copy
KEY 1andEndpoint
Best for: AWS infrastructure, unified billing
Setup AWS Credentials:
Option A: AWS CLI
aws configure
# Enter: Access Key ID, Secret Access Key, RegionOption B: Environment Variables
AWS_ACCESS_KEY_ID=AKIA...
AWS_SECRET_ACCESS_KEY=...
AWS_REGION=us-east-1
AWS_BEDROCK_MODEL=anthropic.claude-3-5-sonnet-20241022-v2:0Prerequisites:
- AWS account with Bedrock access
- Request model access in AWS Console
- Install boto3:
pip install boto3
Best for: Google Cloud integration, Gemini models
Get API Key: https://makersuite.google.com/app/apikey
Configuration:
ACTIVE_PROVIDER=gemini
GOOGLE_API_KEY=AIzaSy...
GEMINI_MODEL=gemini-1.5-pro # or gemini-1.5-flashAvailable Models:
gemini-1.5-pro(Best quality)gemini-1.5-flash(Fastest)gemini-1.0-pro(Legacy)
# Load .env and check
python -c "from qwed_new.config import settings; print(f'Provider: {settings.ACTIVE_PROVIDER}')"python -m qwed_api
# Should see:
# INFO: Started server process
# INFO: Uvicorn running on http://0.0.0.0:8000from qwed import QWEDClient
client = QWEDClient(
api_key="qwed_local", # Local auth key
base_url="http://localhost:8000"
)
result = client.verify("Is 2+2 equal to 4?")
print(result.verified) # Should be TrueProblem:
Error: OPENAI_API_KEY environment variable not set
Solution:
# Check .env file exists
ls -la .env
# Verify it's loaded
python -c "from dotenv import load_dotenv; load_dotenv(); import os; print(os.getenv('OPENAI_API_KEY'))"Problem:
Error: Invalid provider: opnai
Solution:
Check spelling in ACTIVE_PROVIDER:
- ✅
openai(correct) - ❌
opnai(typo) - ❌
OpenAI(case-sensitive)
Problem:
Error: The API version is not supported
Solution:
Update AZURE_OPENAI_API_VERSION:
AZURE_OPENAI_API_VERSION=2024-02-01 # Latest stable-
Use .env files
# .env file (gitignored) ANTHROPIC_API_KEY=sk-ant-... -
Add .env to .gitignore
echo ".env" >> .gitignore
-
Rotate keys regularly
- Generate new keys every 90 days
- Revoke old keys immediately
-
Use different keys per environment
# Development OPENAI_API_KEY=sk-dev-... # Production OPENAI_API_KEY=sk-prod-...
-
Hardcode keys in code
# ❌ NEVER DO THIS! api_key = "sk-proj-abc123..."
-
Commit .env to Git
git add .env # ❌ WRONG! -
Share keys via email/Slack Use secure secret managers instead
-
Use same key across all environments Production keys should be separate
| Provider | Pros | Cons | Best For |
|---|---|---|---|
| OpenAI | ✅ Simple, Latest GPT | ❌ Rate limits | Quick start |
| Anthropic | ✅ Long context, Safe | ❌ Newer | Production |
| Azure OpenAI | ✅ Enterprise SLAs | ❌ Complex setup | Enterprise |
| AWS Bedrock | ✅ Unified billing | ❌ Requires AWS | AWS users |
| Google Gemini | ✅ Fast, Free tier | ❌ Limited models | Testing |
You can configure multiple providers and switch between them:
Setup:
# Configure all providers in .env
OPEN AI_API_KEY=sk-proj-...
ANTHROPIC_API_KEY=sk-ant-...
AZURE_OPENAI_ENDPOINT=https://...Switch dynamically:
import os
# Switch to Anthropic for this request
os.environ['ACTIVE_PROVIDER'] = 'anthropic'
result = client.verify("complex query")
# Switch to OpenAI for speed
os.environ['ACTIVE_PROVIDER'] = 'openai'
result = client.verify("simple query")Provider-specific issues:
- OpenAI: https://platform.openai.com/docs
- Anthropic: https://docs.anthropic.com
- Azure: https://learn.microsoft.com/azure/ai-services/openai/
- AWS: https://docs.aws.amazon.com/bedrock/
- Gemini: https://ai.google.dev/docs
QWED issues:
- GitHub: https://github.com/QWED-AI/qwed-verification/issues
- Discussions: https://github.com/QWED-AI/qwed-verification/discussions