Chatbot Configuration¶
The chatbot backend is configured via environment variables in the .env file located in the chatbot/ directory.
Environment Variables¶
OpenAI Configuration¶
Your OpenAI API key for accessing GPT models. Get one from OpenAI Platform.
Required: Yes
Pinecone Configuration¶
PINECONE_API_KEY: Your Pinecone API key from Pinecone Console
PINECONE_INDEX_NAME: The name of your Pinecone index containing document embeddings. Default: openlibx402-docs
Required: Yes
Solana Payment Configuration¶
| Variable | Description | Default |
|---|---|---|
X402_WALLET_ADDRESS |
Solana wallet address to receive payments | Required |
X402_WALLET_SECRET_KEY |
Secret key (as JSON array) for signing transactions | Required |
SOLANA_NETWORK |
Network: devnet or mainnet-beta |
devnet |
USDC_MINT_ADDRESS |
USDC token mint address | 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU (devnet) |
X402_PAYMENT_AMOUNT |
Default payment amount (deprecated, frontend uses slider) | 0.01 |
X402_PAYMENT_TOKEN |
Token symbol for payments | USDC |
Notes:
- Secret key must be in JSON array format: [byte1,byte2,...]
- For production, use mainnet USDC: EPjFWaYCh7QFMZWWB2BHXZPE6q8bZvWfNvwsKqVDTLST
- Never commit secret keys to version control
Rate Limiting Configuration¶
Number of free queries allowed per user per day. Default: 3
Server Configuration¶
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3000 |
ALLOWED_ORIGINS |
Comma-separated CORS origins | http://localhost:8000,http://localhost:3000 |
Environment Files¶
Development (.env)¶
Local development configuration. Never commit this to version control.
Production (.env.production)¶
Production configuration with mainnet settings.
Runtime Configuration¶
The chatbot loads configuration via the Config interface in src/utils/config.ts:
Payment Pricing¶
The pricing is hardcoded in the payment handler for all deployments:
- Minimum: 0.01 USDC = 10 queries
- Maximum: 1.00 USDC = 1000 queries
- Rate: 1000 queries per USDC
To change pricing, modify src/handlers/payment.ts line 100:
Solana Network Setup¶
Devnet (Development)¶
For local development on Solana devnet:
- Get devnet USDC tokens: https://spl-token-faucet.com/
- Use devnet wallet address
- Set
SOLANA_NETWORK=devnet
Mainnet (Production)¶
For production on Solana mainnet:
- Create mainnet wallet with SOL for transaction fees
- Ensure wallet has USDC tokens for testing
- Use mainnet USDC mint:
EPjFWaYCh7QFMZWWB2BHXZPE6q8bZvWfNvwsKqVDTLST - Set
SOLANA_NETWORK=mainnet-beta
Frontend Configuration¶
The frontend chatbot is configured via the HTML script tag:
Verifying Configuration¶
Start the server and check the logs:
You should see:
Troubleshooting¶
API Key Errors¶
Solution: Ensure OPENAI_API_KEY is set in .env file.
Pinecone Connection Errors¶
Solution:
- Verify PINECONE_API_KEY is correct
- Check PINECONE_INDEX_NAME exists in Pinecone console
- Ensure network connectivity to Pinecone
CORS Errors¶
Solution: Add your origin to ALLOWED_ORIGINS in .env:
Solana Network Errors¶
Solution: - Verify wallet address is valid - Check wallet has SOL for transaction fees - Ensure network matches (devnet vs mainnet) - Verify recipient wallet exists on the network
Security Best Practices¶
- Never commit
.envfiles to version control - Use environment variables for all secrets
- Rotate API keys regularly
- Monitor spending on OpenAI and Pinecone
- Use HTTPS in production
- Validate all inputs on the backend
- Rate limit payment endpoints to prevent abuse