API Keys are NOT stored in code files - this is the correct approach!
Current status:
- ✅ API key is not in configuration files
- ✅ API key is not hardcoded in source code
- ✅ API key is only stored in environment variables
Security Rules:
- ❌ Do not commit API keys to Git repository
- ❌ Do not hardcode API keys in configuration files
- ✅ Use environment variables or
.envfiles - ✅ Ensure
.envis in.gitignore - ✅ Do not share API keys publicly
Run in terminal:
export OPENROUTER_API_KEY="sk-or-v1-[...]"Add to ~/.bashrc or ~/.zshrc:
# Add to end of file
echo 'export OPENROUTER_API_KEY="sk-or-v1-[...]"' >> ~/.zshrc
# Reload configuration
source ~/.zshrc- Create
.envfile in project root:
cd /path/to/symphony
cat > .env << 'EOF'
OPENROUTER_API_KEY=sk-or-v1-[...]
EOF- Ensure
.envis in.gitignore(to prevent committing to Git):
# Check .gitignore
if ! grep -q "^\.env$" .gitignore; then
echo ".env" >> .gitignore
echo "✅ Added .env to .gitignore"
fi- Code will automatically read environment variables; no need to load .env file separately (see below).
Verify in terminal:
# Check environment variable
echo $OPENROUTER_API_KEY
# Or verify in Python
python3 -c "import os; print('✅ API Key set' if os.getenv('OPENROUTER_API_KEY') else '❌ API Key not set')"In agents/agent.py, API key is read as follows:
api_key = os.getenv('OPENROUTER_API_KEY', os.getenv('OPENAI_API_KEY', 'EMPTY'))This means:
- Prefers
OPENROUTER_API_KEYenvironment variable - Falls back to
OPENAI_API_KEYif not available - Uses
'EMPTY'if neither is available (will cause API calls to fail)
Note: Symphony 2.0 code already uses os.getenv(), so if you set the environment variable, code will read it automatically. If using .env file, you may need to install python-dotenv package and call load_dotenv() in code, but for most cases, directly setting environment variables is sufficient.
✅ Recommended structure: organize files by model/agent name:
runtime/configs/openrouter/<agent-name>/config_agent_openrouter_<id>.yaml
Create runtime/configs/openrouter/<agent-name>/config_agent_openrouter_1.yaml:
# Agent 1: Gemini 2.5 Flash-Lite
debug: false
role: "agent"
node_id: "agent-openrouter-001"
base_model: "openrouter:google/gemini-2.5-flash-lite"
sys_prompt: "You are a helpful AI assistant specialized in fast responses."
capabilities:
- math
- reasoning
- general
max_tokens: 512
temperature: 0.2
top_p: 0.9
gpu_id: 0Create runtime/configs/openrouter/config_agent_openrouter_2.yaml:
# Agent 2: GPT-5 Nano
debug: false
role: "agent"
node_id: "agent-openrouter-002"
base_model: "openrouter:openai/gpt-5-nano"
sys_prompt: "You are a helpful AI assistant."
capabilities:
- math
- code
- reasoning
max_tokens: 512
temperature: 0.2
top_p: 0.9
gpu_id: 0Create runtime/configs/openrouter/config_agent_openrouter_3.yaml:
# Agent 3: GPT-4o Mini
debug: false
role: "agent"
node_id: "agent-openrouter-003"
base_model: "openrouter:openai/gpt-4o-mini"
sys_prompt: "You are a helpful AI assistant."
capabilities:
- math
- code
- reasoning
max_tokens: 512
temperature: 0.2
top_p: 0.9
gpu_id: 0| Display Name | OpenRouter Format | Full Config Value |
|---|---|---|
| Gemini 2.5 Flash-Lite | google/gemini-2.5-flash-lite |
openrouter:google/gemini-2.5-flash-lite |
| GPT-5 Nano | openai/gpt-5-nano |
openrouter:openai/gpt-5-nano |
| GPT-4o Mini | openai/gpt-4o-mini |
openrouter:openai/gpt-4o-mini |
| GPT-5.1 Codex Mini | openai/gpt-5.1-codex-mini |
openrouter:openai/gpt-5.1-codex-mini |
| Qwen2.5-7B-Instruct | qwen/qwen-2.5-7b-instruct |
openrouter:qwen/qwen-2.5-7b-instruct |
| Qwen3-8B | qwen/qwen-3-8b |
openrouter:qwen/qwen-3-8b |
Follow the API Key Setup section instructions to set environment variables.
from agents.agent import Agent
import yaml
# Load configuration
with open('runtime/configs/openrouter/config_agent_openrouter_1.yaml', 'r') as f:
config = yaml.safe_load(f)
# Create Agent
agent = Agent(config=config)# Verify agent is correctly initialized
print(f"Agent ID: {agent.agent_id}")
print(f"Base Model: {config['base_model']}")
print(f"Capabilities: {agent.capabilities}")- Check if environment variable is set:
echo $OPENROUTER_API_KEY - Confirm API key format is correct (starts with
sk-or-v1-) - Check if API key has expired or been revoked
- Verify API key is working:
python3 -c "import os; print('✅ API Key set' if os.getenv('OPENROUTER_API_KEY') else '❌ API Key not set')"
- Confirm model name is correct (refer to OpenRouter documentation)
- Check if model is available (some models may require special permissions)
- Try using another available model
- Refer to Model Name Mapping table above for correct format
- Check network connection
- Check firewall settings
- Try using VPN (if in restricted regions)
- Check OpenRouter service status
- API key not working: Ensure environment variable is set in terminal running the code, or restart terminal/IDE
- Configuration file format error: Check YAML syntax, ensure indentation is correct
- Cost control: Be aware of API call costs, recommend setting budget limits in OpenRouter console
API key should be stored in:
- ✅ Environment variables (
export OPENROUTER_API_KEY="...") - Recommended for production - ✅
.envfile (in project root) - Recommended for development - ✅
~/.bashrcor~/.zshrc(persistent) - Recommended for personal development
API key should NOT be in:
- ❌ Configuration files (
runtime/config_*.yaml) - ❌ Source code files (
*.py) - ❌ Git repository (should be ignored)