openapi: 3.1.0 info: # Do not change the title, if the title changes, the import paths will be broken title: Api version: 0.1.0 description: API Rate Limiting SaaS Platform API specification servers: - url: /api description: Base API path tags: - name: health description: Health operations - name: auth description: Authentication operations - name: keys description: API key management - name: plans description: Plan management - name: logs description: Request logs - name: dashboard description: Dashboard stats paths: /healthz: get: operationId: healthCheck tags: [health] summary: Health check description: Returns server health status responses: "200": description: Healthy content: application/json: schema: $ref: "#/components/schemas/HealthStatus" /auth/login: post: operationId: login tags: [auth] summary: Login and get JWT requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/LoginInput" responses: "200": description: Login successful content: application/json: schema: $ref: "#/components/schemas/AuthToken" "401": description: Invalid credentials content: application/json: schema: $ref: "#/components/schemas/ApiError" /auth/me: get: operationId: getMe tags: [auth] summary: Get current user info responses: "200": description: Current user content: application/json: schema: $ref: "#/components/schemas/User" "401": description: Unauthorized content: application/json: schema: $ref: "#/components/schemas/ApiError" /plans: get: operationId: getPlans tags: [plans] summary: List all available plans responses: "200": description: List of plans content: application/json: schema: type: array items: $ref: "#/components/schemas/Plan" /keys: get: operationId: listApiKeys tags: [keys] summary: List all API keys for the authenticated user responses: "200": description: List of API keys content: application/json: schema: type: array items: $ref: "#/components/schemas/ApiKey" post: operationId: createApiKey tags: [keys] summary: Create a new API key requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ApiKeyInput" responses: "201": description: API key created content: application/json: schema: $ref: "#/components/schemas/ApiKeyWithSecret" "400": description: Validation error content: application/json: schema: $ref: "#/components/schemas/ApiError" /keys/{id}: get: operationId: getApiKey tags: [keys] summary: Get a specific API key parameters: - name: id in: path required: true schema: type: string responses: "200": description: API key detail content: application/json: schema: $ref: "#/components/schemas/ApiKey" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ApiError" patch: operationId: updateApiKey tags: [keys] summary: Update an API key (rename or change plan) parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ApiKeyUpdate" responses: "200": description: Updated API key content: application/json: schema: $ref: "#/components/schemas/ApiKey" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ApiError" delete: operationId: deleteApiKey tags: [keys] summary: Delete an API key parameters: - name: id in: path required: true schema: type: string responses: "204": description: Deleted "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ApiError" /keys/{id}/rotate: post: operationId: rotateApiKey tags: [keys] summary: Rotate (regenerate) an API key secret parameters: - name: id in: path required: true schema: type: string responses: "200": description: New key secret content: application/json: schema: $ref: "#/components/schemas/ApiKeyWithSecret" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ApiError" /keys/{id}/usage: get: operationId: getApiKeyUsage tags: [keys] summary: Get usage statistics for an API key parameters: - name: id in: path required: true schema: type: string responses: "200": description: Usage statistics content: application/json: schema: $ref: "#/components/schemas/KeyUsage" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ApiError" /keys/{id}/test: post: operationId: testApiKey tags: [keys] summary: Simulate a rate-limited request with this API key parameters: - name: id in: path required: true schema: type: string responses: "200": description: Request allowed content: application/json: schema: $ref: "#/components/schemas/RateLimitResult" "429": description: Rate limit exceeded content: application/json: schema: $ref: "#/components/schemas/RateLimitResult" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ApiError" /logs: get: operationId: getRequestLogs tags: [logs] summary: Get recent request logs across all API keys parameters: - name: keyId in: query required: false schema: type: string - name: limit in: query required: false schema: type: integer responses: "200": description: Request logs content: application/json: schema: type: array items: $ref: "#/components/schemas/RequestLog" /dashboard/summary: get: operationId: getDashboardSummary tags: [dashboard] summary: Get dashboard overview stats responses: "200": description: Dashboard summary content: application/json: schema: $ref: "#/components/schemas/DashboardSummary" /dashboard/activity: get: operationId: getDashboardActivity tags: [dashboard] summary: Get hourly request activity for the last 24 hours responses: "200": description: Hourly activity data content: application/json: schema: type: array items: $ref: "#/components/schemas/ActivityPoint" /dashboard/top-keys: get: operationId: getTopKeys tags: [dashboard] summary: Get top API keys by request volume responses: "200": description: Top keys content: application/json: schema: type: array items: $ref: "#/components/schemas/TopKey" components: schemas: HealthStatus: type: object properties: status: type: string required: - status ApiError: type: object properties: error: type: string required: - error LoginInput: type: object required: [username, password] properties: username: type: string password: type: string AuthToken: type: object required: [token, user] properties: token: type: string user: $ref: "#/components/schemas/User" User: type: object required: [id, username, email] properties: id: type: string username: type: string email: type: string Plan: type: object required: [id, name, requestsPerMinute, description, price] properties: id: type: string enum: [FREE, PRO, ENTERPRISE] name: type: string requestsPerMinute: type: ["integer", "null"] description: type: string price: type: number ApiKey: type: object required: [id, name, plan, maskedKey, status, createdAt, totalRequests, requestsThisMinute, requestsThisHour, requestsToday] properties: id: type: string name: type: string plan: type: string enum: [FREE, PRO, ENTERPRISE] maskedKey: type: string status: type: string enum: [active, revoked] createdAt: type: string totalRequests: type: integer requestsThisMinute: type: integer requestsThisHour: type: integer requestsToday: type: integer lastUsedAt: type: ["string", "null"] ApiKeyWithSecret: type: object required: [id, name, plan, key, maskedKey, status, createdAt, totalRequests, requestsThisMinute, requestsThisHour, requestsToday] properties: id: type: string name: type: string plan: type: string enum: [FREE, PRO, ENTERPRISE] key: type: string maskedKey: type: string status: type: string enum: [active, revoked] createdAt: type: string totalRequests: type: integer requestsThisMinute: type: integer requestsThisHour: type: integer requestsToday: type: integer lastUsedAt: type: ["string", "null"] ApiKeyInput: type: object required: [name, plan] properties: name: type: string minLength: 1 plan: type: string enum: [FREE, PRO, ENTERPRISE] ApiKeyUpdate: type: object properties: name: type: string minLength: 1 plan: type: string enum: [FREE, PRO, ENTERPRISE] KeyUsage: type: object required: [keyId, plan, requestsPerMinuteLimit, requestsThisMinute, requestsThisHour, requestsToday, totalRequests, hourlyBreakdown] properties: keyId: type: string plan: type: string requestsPerMinuteLimit: type: ["integer", "null"] requestsThisMinute: type: integer requestsThisHour: type: integer requestsToday: type: integer totalRequests: type: integer hourlyBreakdown: type: array items: $ref: "#/components/schemas/ActivityPoint" RateLimitResult: type: object required: [allowed, plan, requestsThisMinute, limitPerMinute, retryAfterSeconds] properties: allowed: type: boolean plan: type: string requestsThisMinute: type: integer limitPerMinute: type: ["integer", "null"] retryAfterSeconds: type: ["integer", "null"] message: type: string RequestLog: type: object required: [id, keyId, keyName, endpoint, method, timestamp, allowed, plan] properties: id: type: string keyId: type: string keyName: type: string endpoint: type: string method: type: string timestamp: type: string allowed: type: boolean plan: type: string responseStatus: type: integer DashboardSummary: type: object required: [totalKeys, activeKeys, totalRequestsToday, blockedRequestsToday, planBreakdown, redisStatus] properties: totalKeys: type: integer activeKeys: type: integer totalRequestsToday: type: integer blockedRequestsToday: type: integer planBreakdown: type: object properties: FREE: type: integer PRO: type: integer ENTERPRISE: type: integer required: [FREE, PRO, ENTERPRISE] redisStatus: type: string enum: [connected, disconnected] ActivityPoint: type: object required: [hour, requests, blocked] properties: hour: type: string requests: type: integer blocked: type: integer TopKey: type: object required: [id, name, plan, requestsToday, percentOfLimit] properties: id: type: string name: type: string plan: type: string requestsToday: type: integer percentOfLimit: type: number