Your API's ultimate wingman β handles rate limits so you donβt get ghosted by third-party services.
ProxyPapi is a robust proxy API service designed to transparently manage rate limits for third-party APIs. Acting as an intermediary, it handles API key authentication, enforces rate-limiting policies, forwards requests, and ensures response integrity. Developers can seamlessly integrate with ProxyPapi without worrying about request throttling or exceeding rate limits.
ProxyPapi also provides real-time monitoring and analytics through Prometheus and Grafana integration, enabling developers to track API usage, performance, and queue statistics effectively.
- Backend: Express.js, TypeScript
- Database: MongoDB (with Mongoose ODM)
- Auth: API Key-Based Authentication
- Rate Limiting: Custom Strategies (Token Bucket implemented; more strategies planned: Fixed Window, Sliding Log, Leaky Bucket)
- Monitoring: Prometheus Metrics + Grafana Dashboards
- API Key Generation: Secure API keys are issued upon user registration.
- API Key Validation: All requests require a valid
x-api-keyheader for authentication.
- Register third-party APIs (e.g., OpenAI, Gemini) to be proxied through ProxyPapi.
- Configure custom rate-limiting strategies per app.
- Forward all requests to the corresponding registered third-party API while maintaining headers and query parameters.
- Ensure full request/response integrity, including error handling.
- Token Bucket Strategy: Each app gets a "bucket" with limited tokens. Requests consume tokens, which refill at regular intervals.
- Configurable Parameters:
maxRequests: Number of tokens in the bucket.windowMs: Refill window duration in milliseconds.
When the rate limit is exceeded:
{
"error": "Rate limit exceeded",
"message": "Your request has been queued and will be processed shortly.",
"remainingTokens": 0
}- Supports different API key mechanisms dynamically:
- For OpenAI, the
Authorizationheader is used (Bearer <API_KEY>). - For Gemini, the API key is converted into a query parameter (
key=<API_KEY>).
- For OpenAI, the
# 1. Clone this repo
git clone https://github.com/yourusername/ProxyPapi.git
# 2. Move into the project folder
cd ProxyPapi
# 3. Install dependencies
npm install
# 4. Create a `.env` file and add the following:
# (Replace values as needed)
PORT=3000
MONGODB_URI=mongodb://localhost:27017/proxypapi
CORS_ORIGIN=http://localhost:51732
JWT_SECRET=yourSuperSecretKey
# 5. Run the app
npm run devRegister a user and receive an API key.
Body:
{
"email": "your@email.com"
}Response:
{
"apiKey": "abcd-1234-..."
}Register a third-party API to be proxied through ProxyPapi.
Headers:
x-api-key: YOUR_API_KEY
Body:
{
"name": "OpenAI",
"baseURL": "https://api.openai.com/v1",
"rateLimit": {
"strategy": "token_bucket",
"maxRequests": 60,
"windowMs": 60000
}
}Response:
{
"appId": "app_abc123"
}All requests forwarded to the corresponding registered third-party API.
Headers:
x-api-key: YOUR_API_KEY- Any other headers required by the third-party API
Example:
GET /apis/app_abc123/completionsProxyPapi will forward this to:
https://api.openai.com/v1/completions
For OpenAI, the Authorization header is passed as-is:
Authorization: Bearer YOUR_OPENAI_API_KEYFor Gemini, the API key is automatically converted into a query parameter:
?key=YOUR_GEMINI_API_KEYProxyPapi exposes metrics at the /metrics endpoint for Prometheus scraping. Metrics include:
- Request Count:
proxy_request_total - Remaining Tokens:
proxy_tokens_remaining - Request Durations:
proxy_request_duration_seconds
Visualize API usage, performance, and queue statistics using Grafana. Import the pre-built dashboard or create your own.
Use the provided Postman collection to test ProxyPapi endpoints:
π Postman Collection
- One API key per user for simplicity (can be extended to per-app keys).
- Rate limits are configured at the app level, not the user level.
- Token Bucket is the first implemented rate-limiting strategy.
To prevent GitHub push failures due to large file sizes (like 100MB+), weβve taken the following precautions:
-
.gitignore:
We've addeddata/*to.gitignoreto exclude bulky files (like API logs, request data dumps, etc.) from being tracked by Git. -
.gitattributes:
Weβve initialized Git LFS (Large File Storage) to manage any future large files efficiently without clogging the repo. This ensures the repo remains fast and pushable.
These steps help avoid the classic βFile exceeds GitHubβs 100MB limitβ error and keep the repo clean and developer-friendly. π₯
ProxyPapi/
βββ src/
β βββ controllers/ # Handles business logic
β βββ middlewares/ # Authentication, rate limiting, etc.
β βββ models/ # Database schemas
β βββ routes/ # API routes
β βββ services/ # Core services (e.g., rate limiting, queuing)
β βββ utils/ # Utility functions (e.g., metrics, helpers)
β βββ workers/ # Background workers (e.g., queue processing)
βββ types # TypeScript type definitions
βββ .env # Environment variables
βββ prometheus.yml # Prometheus configuration file
βββ tsconfig.json # TypeScript configuration
βββ package.json # Node.js dependencies
βββ README.md # This file- Multiple Rate-Limiting Strategies: Implement Fixed Window, Sliding Log, and Leaky Bucket strategies.
- Request Priority Levels: Allow users to prioritize certain requests over others.
- API Usage Dashboard: Provide a web-based dashboard for monitoring API usage and performance.
- Analytics + Error Logs: Detailed logs and analytics for debugging and optimization.
Pull up with a PR or suggest a feature β letβs make ProxyPapi the MVP of rate limiting. π