Introduction
The Monkeytype API provides programmatic access to user data, test results, leaderboards, and configuration. Built with TypeScript and using the ts-rest library for type-safe contracts, the API offers a modern, REST-compliant interface.Base URL
The API is accessible at:The default port is 5005, but can be configured via the
PORT environment variable.API Architecture
ts-rest Contract System
Monkeytype uses @ts-rest/core to define type-safe API contracts. This approach ensures:- Type Safety: Shared types between frontend and backend
- Contract-First Design: API schema defined before implementation
- Automatic Validation: Request/response validation using Zod schemas
- OpenAPI Generation: Swagger documentation auto-generated from contracts
packages/contracts/src/ and define:
- Request/response schemas
- Path parameters and query strings
- Authentication requirements
- Rate limiting rules
Request/Response Format
All API responses follow a consistent format:Error Responses
Errors return appropriate HTTP status codes with details:200- Success400- Bad Request401- Unauthorized403- Forbidden404- Not Found422- Validation Error429- Rate Limit Exceeded500- Internal Server Error503- Service Unavailable
API Versioning
The API version is returned in the root endpoint:Rate Limiting
Rate limits protect the API from abuse and ensure fair usage:Standard Rate Limits
- Root Limit: 1,000 requests per hour per IP
- Bad Authentication: 30 failed attempts per hour per IP
- Endpoint-Specific: Varies by endpoint (see individual endpoint docs)
ApeKey Rate Limits
ApeKeys have separate, typically higher rate limits:- Different limits apply when using ApeKey authentication
- Specified per endpoint in contracts
Rate Limit Headers
Rate limit information is included in response headers:Exceeding Rate Limits
When rate limited:429 Too Many Requests
Authentication Methods
Monkeytype supports three authentication methods:- Bearer Token (Firebase JWT) - Primary method for user authentication
- ApeKey - API keys for programmatic access
- Public Endpoints - No authentication required
CORS and Security
The API implements:- CORS: Cross-origin requests enabled with exposed headers
- Helmet: Security headers automatically applied
- Trust Proxy: IP forwarding support for accurate rate limiting
- ETag: Weak ETag generation for caching
Maintenance Mode
When the server is under maintenance:503 Service Unavailable
Available Endpoints
The API provides the following resource groups:- Users (
/users) - User account management and profiles - Results (
/results) - Test results and statistics - Leaderboards (
/leaderboards) - Global and daily leaderboards - Configs (
/configs) - User configuration management - Presets (
/presets) - Test preset management - Quotes (
/quotes) - Quote submissions and ratings - ApeKeys (
/ape-keys) - API key management - PSAs (
/psas) - Public service announcements - Admin (
/admin) - Administrative functions
Getting Started
- Authentication: Choose your authentication method
- Test Connection: Verify API accessibility
- Explore Endpoints: Review available operations
- Handle Errors: Implement proper error handling
- Respect Rate Limits: Monitor usage and implement backoff
SDK and Client Libraries
The frontend uses a TypeScript client generated from ts-rest contracts:OpenAPI/Swagger Documentation
Interactive API documentation is available at:Swagger documentation is auto-generated from ts-rest contracts and includes request/response examples.
Support
For API issues or questions:- Check existing documentation
- Review contract definitions in
packages/contracts/src/ - Submit issues on GitHub
- Join the Discord community