Skip to main content

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:

  1. Visit OpenAI Platform
  2. Create an account or sign in
  3. Navigate to API Keys section
  4. Click "Create new secret key"
  5. 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:

  1. Visit Exa.ai
  2. Sign up for an account
  3. Go to your dashboard
  4. 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:

  1. Visit Polymarket
  2. Connect your wallet and create an account
  3. Navigate to API section in your account settings
  4. Generate API key and secret
  5. 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:

  1. Create a dedicated trading wallet (recommended)
  2. Export private key from MetaMask or similar wallet
  3. ⚠️ 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:

  1. Visit Anthropic Console
  2. 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:

  1. Visit LangSmith
  2. 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:

  1. Visit Tavily
  2. 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:

  1. Visit Privy
  2. 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

  1. Use Environment Variables: Never hardcode keys in source code
  2. Separate Environments: Use different keys for dev/staging/production
  3. Regular Rotation: Rotate keys periodically
  4. Access Monitoring: Monitor API usage for suspicious activity

Wallet Security

  1. Dedicated Trading Wallet: Use a separate wallet just for trading
  2. Limited Funds: Only keep necessary trading funds in the wallet
  3. Private Key Storage: Store private keys securely (consider hardware wallets)
  4. 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:

  1. Polymarket Setup - Configure Polymarket-specific settings
  2. Quick Start - Test your configuration
  3. Usage Guide - Start using the agent

Need help? Check the Troubleshooting Guide for common API configuration issues.