API Simulation & Automation
Learn how MockAPI persists REST state, simulates rate limits and latency, applies scenario overrides, validates OpenAPI drift, and exposes a Management API for automation.
What this guide covers
MockAPI can run in stateless mode, where every response is freshly generated from your models, or in stateful mode, where GET, POST, PUT, PATCH, and DELETE operations persist data across requests. Independently, you can enable simulated rate limiting, latency profiles, named scenario presets, structured error bodies, OpenAPI drift detection, and CI/CD automation via the Management API.
All features described below are production-ready and available on your mock host at https://api.mockapi.com/{your-path}. Configuration is managed through the dashboard under Project Settings.
Stateful REST (persistent CRUD)
When Stateful mode is enabled on a project, your mock endpoints behave like a real REST API: records are created, read, updated, and deleted persistently. Each endpoint's behavior is determined by the model attached to its response configuration.
Plan requirements and limits
Stateful mode requires the Developer plan or higher (not available on the Free plan). Each plan has a maximum record limit that is enforced on both seeding and individual POST requests: Developer (100 records), Team (1,000), Business (5,000), Enterprise (10,000). Attempting to exceed this limit returns an error.
Enabling and configuring
Turn on stateful mode in Project Settings → Advanced. You can configure:
- Stateful seed count: number of synthetic records to generate when a model is seeded (capped by your plan limit).
- TTL (days): how long stored records are kept before the store resets and reseeds (1 to 30 days, default 1).
- Pagination: when enabled, list responses include pagination metadata (current page, total pages, total records, etc.) alongside the data array.
Each REST method on an endpoint should reference a response with a model. Endpoints that share the same model share the same pool of stored records.
Record identity and timestamps
Every record is assigned a server-generated UUID as its id. The API returns this id alongside your model's fields and two automatic timestamps: createdAt (when the record was created) and updatedAt (when it was last modified).
If your model schema defines an id field, it is ignored on creation. The server always assigns the authoritative UUID to prevent conflicts.
When data is seeded
On the first GET request to a collection path (e.g., /users with no trailing ID) where no records exist yet, MockAPI automatically seeds the model with synthetic data based on your seed count and model schema.
You can also seed data manually from the dashboard: navigate to the endpoint detail page and use the Clear and re-seed button, which deletes all existing records for that model and regenerates fresh data.
Seeding is per model, not per endpoint. Two endpoints that share the same model share the same backing data store.
Seed data validation
Before generating seed data, MockAPI validates that the records produced by your model schema are within acceptable size limits. If they are not, seeding is aborted with an explanatory error message so you can adjust your model.
HTTP method behavior
When stateful mode is active, each HTTP method behaves as follows:
| Method | Behavior |
|---|---|
| GET (collection) | Returns persisted records with pagination, sorting, and query-string filtering. Auto-seeds on first request when empty. |
| GET /{id} | Returns a single record by ID. Returns 404 if the record does not exist. |
| POST (collection) | Creates a new record using your request body, filling in any missing fields from the model schema, and assigns a new ID and timestamps. Enforces plan record limits. |
| PUT /{id} | Fully replaces an existing record. Fields not in your request body are regenerated from the model schema. |
| PATCH /{id} | Partial update. Only fields present in your request body are updated; all other fields remain unchanged. |
| DELETE /{id} | Permanently deletes the record with the specified ID. |
Collection GET query parameters
The following query parameters are supported on collection GET requests. Reserved parameters are never treated as field filters:
| Parameter | Description |
|---|---|
| page / _page | Page number, 1-based (default: 1). |
| limit / _limit | Number of records per page (default: 25, max: 100). |
| sortBy / _sort | Field name to sort by. Use createdAt to sort by creation time. |
| sortOrder / _order | Sort direction: asc or desc (default: asc). |
| cursor | Reserved for future use. Not applied as a filter. |
| Any other key | Treated as a case-insensitive substring filter on the matching field. Multiple filters are combined with AND logic. |
When Enable pagination is set on the project, the list response wraps results with your configured pagination labels (current page, next/previous page, page size, total pages, total records) alongside the data array.
Path templates vs. collection URLs
Single-record operations are identified when the final path segment is a UUID. For template paths like /actors/{id}, use /actors/<uuid> for GET, PUT, PATCH, and DELETE. Use the collection URL /actors for listing and creating records.
The dashboard automatically normalizes template paths to the collection URL when re-seeding data.
Re-seeding from the dashboard
Users with Endpoint edit permission can clear all records for an endpoint’s model and immediately re-generate seed data. This is useful after schema changes or when you need a clean slate.
Triggered via the Clear and re-seed button on the endpoint detail page, or programmatically via POST /api/endpoint/{projectId}/{endpointId}/stateful-reseed.
Record limit enforcement
Plan-based record limits are enforced on both auto-seeding and individual POST requests. When you attempt to create a record that would exceed your plan’s maximum, the request is rejected with HTTP 403.
| Plan | Max records per model |
|---|---|
| Developer | 100 |
| Team | 1,000 |
| Business | 5,000 |
| Enterprise | 10,000 |
When the limit is reached, POST requests return the following error body:
{
"error": "Record limit reached (100 for your plan). Delete existing records or upgrade your plan.",
"code": "RECORD_LIMIT_EXCEEDED"
}Simulated rate limiting
When rate limiting is enabled on a project, every mock REST request is counted against a rolling one-minute window. The rate limit check runs before scenario and stateful processing, so all requests count toward the limit, including those matched by scenarios.
Every response includes rate-limit headers so your client can react to throttling in the same way it would with a production API. When the configured requests-per-minute threshold is exceeded, MockAPI returns HTTP 429 with a structured error body.
Configuring rate limits
Enable and configure rate limiting under Project Settings → Advanced. Set the Requests per minute threshold (default: 60). Changes take effect immediately for all endpoints in the project.
Response headers
X-RateLimit-Limit: The configured maximum requests per minute.X-RateLimit-Remaining: Remaining requests in the current one-minute window.X-RateLimit-Reset: Unix timestamp (seconds) when the current window resets.Retry-After: Seconds until the current rate-limit window resets. Included on every response when rate limiting is enabled.
429 response
When the request count exceeds the threshold, the API returns HTTP 429 with rate-limit headers still attached. Clients should back off until the Retry-After period elapses or use exponential backoff.
{
"error": "Too Many Requests",
"code": "RATE_LIMITED"
}Latency profiles
Latency profiles let you simulate realistic network delays on your mock endpoints, so your application can be tested under different network conditions. Each project supports one of four modes:
| Mode | Behavior |
|---|---|
| Fixed | Adds a constant delay to every response. Configure the delay in milliseconds. |
| Random | Adds a random delay between a minimum and maximum value you set. |
| Spike | Uses the random range for most requests, but a share of requests (the spike probability) take the spike duration instead, to simulate intermittent slowdowns. Configure the spike probability and spike duration. |
| Slow 3G | Simulates a slow 3G mobile network connection with realistic pacing. |
Configuring latency
Configure your project's latency profile under Project Settings → Advanced. Select the mode and fill in the fields that appear (minimum delay, maximum delay, spike probability, and spike duration, as applicable). Changes apply immediately to all endpoints.
Scenario presets may include a latency override that temporarily replaces the project-level profile for requests matched by that scenario.
Scenario presets
Scenarios let you define named response presets that can be activated per-request using the X-MockAPI-Scenario header. When the header is present, MockAPI loads the matching scenario for the project. If no match is found, the default scenario (if set) is used.
X-MockAPI-Scenario: your-scenario-nameScenarios are evaluated before stateful processing. If a scenario defines an endpoint override matching the current request path (and optionally HTTP method), MockAPI returns the override's configured status code, response body, and optional delay immediately, without executing the normal mock logic. Rate-limit headers are still included in the response.
What you can override per scenario
- Endpoint path with case-insensitive matching, plus an optional HTTP method filter.
- HTTP status code and an optional custom response body (JSON).
- Artificial delay in milliseconds per endpoint override.
- A latency profile override that applies to requests not matched by any endpoint-specific rule.
Managing scenarios
Scenarios are managed from the dashboard under Settings → Scenarios. You can:
- Create a new scenario with a name, description, endpoint overrides, and an optional latency override.
- Edit an existing scenario to update its overrides or configuration.
- Delete a scenario you no longer need.
- Set a default scenario that is applied automatically when no X-MockAPI-Scenario header is sent.
Each scenario is stored per project and scoped to the project’s endpoints. Only project members can create or modify scenarios.
Request processing order
The complete order of operations for each mock request: Authenticate → Plan access check → Rate limiting → Resolve scenario (may return early with override) → Apply scenario latency (if applicable) → Stateful CRUD or stateless generation → Attach rate-limit headers to the response.
Structured error bodies
In stateless mode, if the selected response has a custom Response Body Template and a status code of 400 or higher, MockAPI returns the template content instead of generated model data. This lets you define consistent error JSON for failure simulations.
OpenAPI drift detection
MockAPI can compare your current mock API configuration against an OpenAPI specification to detect contract drift. The analysis categorizes differences as breaking or non-breaking and identifies endpoints or fields that are missing on either side.
To run drift detection, navigate to Settings → Drift Detection in the dashboard, paste your OpenAPI spec (YAML or JSON), and review the results interactively.
Programmatically, authenticated users can call POST /api/OpenApiDrift/detect/{projectId} with { "openApiSpec": "..." } in the request body. Access requires project membership.
Management API
The Management API provides programmatic access to MockAPI resources for CI/CD pipelines and automation workflows. It is secured by management API keys with scoped permissions, separate from the MCP keys used by AI integrations.
The base URL is your dashboard host followed by /api/v1 (for example, https://app.mockapi.com/api/v1). This is the same API the dashboard uses internally, not the api.mockapi.com mock host.
Key scopes
Management keys are issued with specific scopes that control access:
mgmt:read: List and read projects, models, and endpoints.mgmt:write: Create and delete models and endpoints, run OpenAPI imports.
Access is scoped to projects owned by the key’s user. Include your management key in the Authorization header as a Bearer token.
Available routes
All paths below are relative to /api/v1. Write operations require mgmt:write scope; read operations require at least mgmt:read.
| Route | Description |
|---|---|
| GET /projects | List all projects owned by the key’s user. |
| GET /projects/{projectId} | Retrieve a single project. |
| GET /projects/{projectId}/models | List models with pagination. |
| GET /projects/{projectId}/models/{modelId} | Retrieve a single model. |
| POST /projects/{projectId}/models | Create a new model (requires write scope). |
| DELETE /projects/{projectId}/models/{modelId} | Delete a model (requires write scope). |
| GET /projects/{projectId}/endpoints | List endpoints with pagination. |
| POST /projects/{projectId}/endpoints | Create a new endpoint (requires write scope). |
| DELETE /projects/{projectId}/endpoints/{endpointId} | Delete an endpoint (requires write scope). |
| POST /projects/{projectId}/import/openapi | Import an OpenAPI schema (requires write scope). Body: { "schema": "...", "overwriteExisting": true }. |
Management keys vs. MCP keys
Use management keys in CI/CD pipelines to provision and configure projects. Use MCP keys in AI integrations (Cursor, Claude, etc.). They are intentionally separate so you can rotate automation credentials without affecting AI tooling, and vice versa.
OpenAPI import
MockAPI can import Swagger 2 and OpenAPI 3 specifications to automatically generate models and endpoints. This is available through the Management API, the MCP integration, and the dashboard UI.
See Import & Export for step-by-step instructions on importing from the dashboard.
Related documentation
- REST API: endpoint configuration, path templates, HTTP methods, and consuming your mock host.
- Settings: API keys, project configuration, scenarios, and drift detection.
- MCP (AI integration): AI-facing tools, MCP key scopes, and integration setup.