API Keys Configuration
PolyOracle AI requires several API keys to function properly. This guide explains how to obtain and configure each required service.
Required API Keys
1. OpenAI API Key ⚡ Required
What it's for: Powers the AI analysis and decision-making
How to get it:
- Visit OpenAI Platform
- Create an account or sign in
- Navigate to API Keys section
- Click "Create new secret key"
- Copy the key (starts with
sk-
)
Usage: Add to .env
file:
OPENAI_API_KEY=sk-your-openai-key-here
Cost: Pay-per-use, typically $0.002-0.06 per 1K tokens
2. Exa API Key ⚡ Required
What it's for: Powers the deep research capabilities
How to get it:
- Visit Exa.ai
- Sign up for an account
- Go to your dashboard
- Find your API key in the settings
Usage: Add to .env
file:
EXA_API_KEY=your-exa-api-key
Cost: Free tier available, then usage-based pricing
3. Polymarket API Keys ⚡ Required
What it's for: Trading and market data access
How to get it:
- Visit Polymarket
- Connect your wallet and create an account
- Navigate to API section in your account settings
- Generate API key and secret
- Note: You'll also need to create a proxy contract (see Polymarket Setup)
Usage: Add to .env
file:
POLYMARKET_API_KEY=your-polymarket-api-key
POLYMARKET_API_SECRET=your-polymarket-secret
4. Polygon Wallet Private Key ⚡ Required
What it's for: Executing trades on Polygon blockchain
How to get it:
- Create a dedicated trading wallet (recommended)
- Export private key from MetaMask or similar wallet
- ⚠️ Security Warning: Use a separate wallet for trading, never your main wallet
Usage: Add to .env
file:
POLYGON_WALLET_PRIVATE_KEY=0xYourPrivateKeyHere
Security Note: Keep this key secure and never share it
Optional API Keys
Anthropic API Key (Optional)
What it's for: Alternative LLM for analysis (fallback option)
How to get it:
- Visit Anthropic Console
- Create account and generate API key
ANTHROPIC_API_KEY=your-anthropic-key
LangChain API Key (Optional)
What it's for: Tracing and monitoring agent execution
How to get it:
- Visit LangSmith
- Create account and generate API key
LANGCHAIN_API_KEY=your-langchain-key
LANGCHAIN_TRACING_V2=true
LANGSMITH_PROJECT=polyoracle
Tavily API Key (Optional)
What it's for: Additional search capabilities (backup to Exa)
How to get it:
- Visit Tavily
- Sign up and get API key
TAVILY_API_KEY=your-tavily-key
Web3 Configuration (Frontend)
Privy Authentication
What it's for: Web3 wallet authentication in frontend
How to get it:
- Visit Privy
- Create an app and get your App ID
NEXT_PUBLIC_PRIVY_APP_ID=your-privy-app-id
PRIVY_SECRET=your-privy-secret
Configuration Checklist
Essential Setup ✅
- OpenAI API Key configured
- Exa API Key configured
- Polymarket API Key and Secret configured
- Polygon Wallet Private Key configured
- Privy App ID configured (for frontend)
Optional Enhancements ⚪
- Anthropic API Key (for model diversity)
- LangChain API Key (for tracing)
- Tavily API Key (for backup search)
Security Best Practices
API Key Security
- Use Environment Variables: Never hardcode keys in source code
- Separate Environments: Use different keys for dev/staging/production
- Regular Rotation: Rotate keys periodically
- Access Monitoring: Monitor API usage for suspicious activity
Wallet Security
- Dedicated Trading Wallet: Use a separate wallet just for trading
- Limited Funds: Only keep necessary trading funds in the wallet
- Private Key Storage: Store private keys securely (consider hardware wallets)
- Regular Monitoring: Monitor wallet transactions
Environment File Security
# Make sure .env files are in .gitignore
echo ".env" >> .gitignore
echo ".env.local" >> .gitignore
# Set appropriate permissions
chmod 600 .env
chmod 600 frontend/.env.local
Testing Your Configuration
Backend API Test
cd backend
python -c "
import os
from dotenv import load_dotenv
load_dotenv()
print('OpenAI:', '✅' if os.getenv('OPENAI_API_KEY') else '❌')
print('Exa:', '✅' if os.getenv('EXA_API_KEY') else '❌')
print('Polymarket:', '✅' if os.getenv('POLYMARKET_API_KEY') else '❌')
"
Frontend Config Test
cd frontend
pnpm dev
# Check browser console for any missing environment variable warnings
Cost Management
OpenAI Costs
- Set usage limits in OpenAI dashboard
- Monitor token usage regularly
- Use GPT-4o-mini for cost optimization where possible
Exa Costs
- Start with free tier
- Monitor search volume
- Optimize research depth vs cost
Trading Costs
- Polymarket has trading fees
- Consider gas costs for Polygon transactions
- Start with small position sizes for testing
Troubleshooting
"Invalid API key" errors
- Double-check key format and characters
- Ensure no extra spaces or newlines
- Verify key is active in provider dashboard
"Insufficient permissions" errors
- Check API key permissions in provider settings
- Some keys need specific scopes enabled
Environment variables not loading
- Verify
.env
file location - Check file permissions
- Restart development servers after changes
Next Steps
Once your API keys are configured:
- Polymarket Setup - Configure Polymarket-specific settings
- Quick Start - Test your configuration
- Usage Guide - Start using the agent
Need help? Check the Troubleshooting Guide for common API configuration issues.