Documentation Index
Fetch the complete documentation index at: https://mintlify.com/MatthewSabia1/SubPirate-Pro/llms.txt
Use this file to discover all available pages before exploring further.
Overview
SubPirate uses OpenRouter to analyze subreddits for marketing potential. OpenRouter provides unified access to multiple LLM providers, and SubPirate uses Google’s Gemini 3 Flash model for fast, cost-effective analysis.Why OpenRouter?
OpenRouter offers several advantages:- Unified API: Access multiple LLM providers through a single API
- Automatic failover: If one provider is down, OpenRouter routes to alternatives
- Cost tracking: Built-in usage monitoring and spend limits
- Model flexibility: Easy to switch models without code changes
Getting Started
Create OpenRouter Account
Sign up at https://openrouter.ai
Add Credits
Add credits to your OpenRouter account. Start with $5-10 for testing.Typical costs:
- Analysis per subreddit: ~$0.01-0.05 depending on data volume
- 100 analyses: ~$2-5
Model Configuration
SubPirate uses Google Gemini 3 Flash Preview as the default model:api/_lib/openrouter.js:7.
Why Gemini 3 Flash?
- Fast: Low latency responses (typically 2-5 seconds)
- Cost-effective: ~$0.01 per analysis
- JSON output: Native support for structured JSON responses
- Context window: 1M+ tokens for analyzing large subreddit data
Switching Models
To use a different model, update the constant inapi/_lib/openrouter.js:
API Implementation
The OpenRouter integration is implemented inapi/_lib/openrouter.js:
Request Configuration
- temperature: 0.6 - Balanced creativity/consistency
- max_tokens: 35000 - Allows comprehensive analysis output
- response_format: json_object - Ensures structured JSON responses
Analysis Prompt
The system prompt guides the AI analysis:api/_lib/analyze.js (imported as buildAnalysisPrompt).
Quota Management
SubPirate enforces analysis quotas per subscription tier to control OpenRouter costs:Quota Check
Before each analysis, the system verifies the user hasn’t exceeded their limit:api/_lib/subscriptionGate.js:4.
Usage Tracking
After successful analysis, usage is incremented (non-admin users only):subscription_usage table via a database function.
Rate Limits
OpenRouter Rate Limits
OpenRouter applies rate limits based on your account tier:- Free tier: ~10 requests/minute
- Paid tier: ~60 requests/minute
- Enterprise: Custom limits
SubPirate Batch Analysis
When analyzing multiple subreddits, SubPirate:- Uses Web Workers for parallel processing (
analysisWorker.ts) - Queues requests to avoid overwhelming OpenRouter
- Caches results in IndexedDB to prevent duplicate analyses
Error Handling
The OpenRouter client handles various error scenarios:| Status | Cause | Solution |
|---|---|---|
| 401 | Invalid API key | Check OPENROUTER_API_KEY in .env |
| 402 | Insufficient credits | Add credits to OpenRouter account |
| 429 | Rate limit exceeded | Reduce concurrent requests or upgrade OpenRouter tier |
| 500 | OpenRouter internal error | Retry request, check OpenRouter status page |
Cost Optimization
1. Enable Result Caching
SubPirate caches analysis results in:- Client: IndexedDB (
analysisIdb.ts) - Server:
subreddit_analysestable
2. Set OpenRouter Spend Limits
In OpenRouter settings, configure:- Daily spend limit: e.g., $10/day
- Monthly budget: e.g., $100/month
- Low balance alerts: Email when credits drop below threshold
3. Monitor Usage
Track costs in OpenRouter dashboard:- Usage by model: Identify expensive models
- Usage by endpoint: See which features consume most credits
- Anomaly detection: Spot unexpected spikes
Security Considerations
Testing
Test OpenRouter Connection
Create a test endpoint to verify your API key:Monitor Test Costs
Small test requests typically cost less than $0.001. Check OpenRouter dashboard after testing.Environment Variables Reference
.env
Next Steps
- Reddit OAuth Integration - Connect Reddit accounts
- Stripe Billing - Configure subscription tiers and analysis quotas