A powerful, scalable AI-powered API mocking tool that captures real API requests and generates realistic mock responses using AI. Each endpoint gets a unique ID for easy management and routing.
- π― Capture Real APIs: Record actual API responses for learning
- π’ Unique Endpoint IDs: Auto-generated 7-digit CAPS alphanumeric IDs for each endpoint
- π€ AI Sample Generation: Uses Anthropic Claude or OpenAI GPT to generate realistic samples per endpoint
- π Scalable Routes: Serve multiple endpoints simultaneously with
/api/<ID>/<path>
format - π Endpoint Management: List and manage captured endpoints with their unique IDs
- βοΈ Configurable: X (context requests), Y (sample count), and prompts are all configurable
- π Production Ready: Built with FastAPI, comprehensive error handling, and CORS support
# Clone the repository
git clone https://github.com/simplyrk/ai-mock-api-genie.git
cd ai-mock-api-genie
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# 1. Initialize the database
mock-api-genie init
# 2. Capture endpoints (each gets a unique ID)
mock-api-genie capture https://jsonplaceholder.typicode.com/users/1 --count 3
mock-api-genie capture https://jsonplaceholder.typicode.com/posts --count 5
# 3. List captured endpoints with their IDs
mock-api-genie list
# 4. Generate AI samples for specific endpoints
mock-api-genie generate --id ABC1234
mock-api-genie generate --id XYZ5678
# 5. Start the scalable mock server
mock-api-genie serve --port 8000
# 6. Access mock endpoints using their unique IDs
curl http://localhost:8000/api/ABC1234/users/1
curl http://localhost:8000/api/XYZ5678/posts
- Python 3.9+
- SQLite3 (usually comes pre-installed with Python)
- Anthropic API key or OpenAI API key
Create a .env
file in the project root:
# ============================================
# AI PROVIDER CONFIGURATION
# ============================================
# Get your Anthropic API key from: https://console.anthropic.com/
ANTHROPIC_API_KEY=your_anthropic_api_key_here
# Get your OpenAI API key from: https://platform.openai.com/api-keys
OPENAI_API_KEY=your_openai_api_key_here
# AI Provider (anthropic or openai)
AI_PROVIDER=anthropic
# AI Models
ANTHROPIC_MODEL=claude-3-5-sonnet-20241022
OPENAI_MODEL=gpt-4-turbo-preview
# ============================================
# DATABASE CONFIGURATION
# ============================================
DATABASE_URL=sqlite:///mock_api_genie.db
# ============================================
# MOCK SERVER CONFIGURATION
# ============================================
MOCK_SERVER_HOST=0.0.0.0
MOCK_SERVER_PORT=8000
# Enable CORS for mock server
ENABLE_CORS=true
# Mock server response delay (milliseconds)
MIN_RESPONSE_DELAY_MS=50
MAX_RESPONSE_DELAY_MS=500
# Logging
LOG_LEVEL=INFO
# ============================================
# AI SAMPLE GENERATION SETTINGS
# ============================================
# X - Number of recent captured requests to analyze as context
AI_CONTEXT_REQUESTS=10
# Y - Number of sample responses to generate each time
AI_SAMPLE_COUNT=5
# Maximum number of captures to store per endpoint
MAX_CAPTURES_PER_ENDPOINT=100
# ============================================
# AI PROMPT TEMPLATES (SIMPLIFIED)
# ============================================
# System prompt for AI sample generation
AI_SAMPLE_SYSTEM_PROMPT=You are an AI assistant that generates realistic sample API responses based on captured request patterns. Generate diverse, realistic responses that follow the patterns from the provided examples.
# User prompt template for sample generation (Variables: {requests}, {num_samples})
AI_SAMPLE_PROMPT=Based on these captured API requests and responses: {requests} Generate {num_samples} new realistic sample responses that follow similar patterns. Make the data varied and realistic while maintaining the same structure and data types. Return a JSON object with a samples key containing an array of sample response objects.
The scalable version supports unlimited endpoints with unique routing:
- Capture - Auto-assigns unique 7-digit CAPS IDs to endpoints
- Generate - Creates AI samples for specific endpoint IDs
- Serve - Routes requests to
/api/<ID>/<path>
format
ai-mock-api-genie/
βββ mock_api_genie/
β βββ cli.py # Simplified CLI interface
β βββ core/
β β βββ analyzer.py # Endpoint-specific AI generation
β β βββ generator.py # Sample serving
β β βββ capture.py # Auto-generates unique IDs
β β βββ config.py # Configuration management
β βββ server/
β β βββ app.py # Scalable FastAPI server
β βββ models/
β βββ database.py # Database models with unique_id fields
βββ requirements.txt # Clean dependencies
βββ setup.py # Production-ready setup
βββ .env.example # Configuration template
βββ README.md # This file
Command | Description | Example |
---|---|---|
init |
Initialize database | mock-api-genie init |
capture |
Capture endpoint (auto-assigns ID) | mock-api-genie capture https://api.com/users --count 5 |
list |
List captured endpoints with IDs | mock-api-genie list |
generate |
Generate samples for specific endpoint | mock-api-genie generate --id ABC1234 |
serve |
Start scalable mock server | mock-api-genie serve --port 8000 |
mock-api-genie list
Output:
π Captured Endpoints:
βββββββββββ¬βββββββββ¬ββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββ¬ββββββββββββ
β ID β Method β URL β Capturesβ Generated β
βββββββββββΌβββββββββΌββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββ€
β ABC1234 β GET β https://jsonplaceholder.typicode.com... β 3 β 5 β
β XYZ5678 β GET β https://api.github.com/users/octocat β 2 β 0 β
βββββββββββ΄βββββββββ΄ββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββ
mock-api-genie generate --id ABC1234
Output:
π€ Generating AI samples for endpoint ABC1234...
β
Generated 5 new samples for endpoint ABC1234
π Endpoint: GET https://jsonplaceholder.typicode.com/users/1
Endpoint | Method | Description |
---|---|---|
/ |
GET | Server info and active endpoints |
/health |
GET | Health check endpoint |
/admin/generate/{endpoint_id} |
POST | Generate samples via API |
Route Pattern | Description | Example |
---|---|---|
/api/{endpoint_id}/{path} |
Serves mock data for endpoint ID | /api/ABC1234/users/1 |
# 1. Set up environment
export ANTHROPIC_API_KEY="your_key_here"
# 2. Initialize database
mock-api-genie init
# 3. Capture multiple different endpoints
mock-api-genie capture https://jsonplaceholder.typicode.com/users/1 --count 3
mock-api-genie capture https://jsonplaceholder.typicode.com/posts --count 5
mock-api-genie capture https://api.github.com/users/octocat --count 2
# 4. List all captured endpoints with their unique IDs
mock-api-genie list
# Example output:
# βββββββββββ¬βββββββββ¬ββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββ¬ββββββββββββ
# β ID β Method β URL β Capturesβ Generated β
# βββββββββββΌβββββββββΌββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββ€
# β A7B9X2M β GET β https://jsonplaceholder.typicode.com... β 3 β 0 β
# β K3N8Y4P β GET β https://jsonplaceholder.typicode.com... β 5 β 0 β
# β R6T1Z9Q β GET β https://api.github.com/users/octocat β 2 β 0 β
# βββββββββββ΄βββββββββ΄ββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββ
# 5. Generate AI samples for each endpoint
mock-api-genie generate --id A7B9X2M
mock-api-genie generate --id K3N8Y4P
mock-api-genie generate --id R6T1Z9Q
# 6. Start the scalable server
mock-api-genie serve --port 8000
# 7. Access mock endpoints using their unique IDs
curl http://localhost:8000/api/A7B9X2M/users/1 # Returns realistic user data
curl http://localhost:8000/api/K3N8Y4P/posts # Returns realistic posts data
curl http://localhost:8000/api/R6T1Z9Q/users/octocat # Returns realistic GitHub user data
# 8. Check server status and available endpoints
curl http://localhost:8000/
For captured endpoint https://jsonplaceholder.typicode.com/users/1
with ID A7B9X2M
:
Original Request | Mock Route | Description |
---|---|---|
GET https://jsonplaceholder.typicode.com/users/1 |
GET /api/A7B9X2M/users/1 |
Exact path match |
GET https://jsonplaceholder.typicode.com/users/123 |
GET /api/A7B9X2M/users/123 |
Pattern match with different ID |
Variable | Description | Default |
---|---|---|
AI_CONTEXT_REQUESTS |
Number of recent requests to analyze (X) | 10 |
AI_SAMPLE_COUNT |
Number of samples to generate (Y) | 5 |
AI_SAMPLE_SYSTEM_PROMPT |
System prompt for AI | Configurable |
AI_SAMPLE_PROMPT |
User prompt template for AI | Configurable |
ANTHROPIC_API_KEY |
Anthropic API key | Required |
OPENAI_API_KEY |
OpenAI API key | Alternative to Anthropic |
AI_PROVIDER |
AI provider choice | anthropic |
DATABASE_URL |
Database connection | sqlite:///mock_api_genie.db |
MOCK_SERVER_PORT |
Server port | 8000 |
mock-api-genie serve --port 8000
python -c "
import uvicorn
from mock_api_genie.server.app import create_app
app = create_app()
uvicorn.run(app, host='0.0.0.0', port=8000)
"
uvicorn mock_api_genie.server.app:create_app --factory --host 0.0.0.0 --port 8000
- Unlimited Endpoints: Mock as many APIs as needed simultaneously
- Easy Management: Each endpoint has a memorable 7-digit ID
- AI-Powered: Generates realistic, contextually appropriate data
- Isolated Samples: AI generates samples specific to each endpoint
- Clear Routing:
/api/<ID>/<path>
format prevents conflicts - Production Ready: FastAPI backend with comprehensive error handling
- Flexible Deployment: Serve multiple mock APIs from one server
git clone https://github.com/simplyrk/ai-mock-api-genie.git
cd ai-mock-api-genie
python -m venv venv
source venv/bin/activate
pip install -e .
pytest tests/
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with:
- FastAPI - Modern, fast web framework
- SQLAlchemy - Database ORM
- Anthropic Claude - AI generation
- OpenAI - AI generation alternative
- Rich - Beautiful CLI formatting
- Typer - CLI framework
If you encounter any issues or have questions, please file an issue on the GitHub repository.
simplyrk - GitHub