AI-Powered Mock Data Generation — Gemini & Faker.js

Seed your mock APIs with realistic, context-aware data. Choose between Gemini AI for intelligent generation or Faker.js for fast, deterministic output. Auto mode picks the best option based on record count and API key availability.

// Three Generation Modes

Auto (Default)Recommended

Uses AI for ≤100 records when Gemini is available, falls back to Faker otherwise.

mode: "auto"
AI (Gemini)Smart

Generates context-aware data using Gemini 2.0 Flash. Understands field relationships and business logic.

mode: "ai"
Faker.jsFast

Fast, deterministic generation using field name heuristics. Maps 'email' → faker.internet.email(), etc.

mode: "faker"

// AI-Powered Generation

Gemini analyzes your resource schema, field names, and optional context to produce data that makes sense together—not just random strings.

terminalbash
curl -X POST https://moqapi.dev/api/mock-apis/<mockApiId>/resources/<resourceId>/generate \
  -H "Content-Type: application/json" \
  -d '{
    "count": 25,
    "mode": "ai",
    "context": "A premium pet store in San Francisco specializing in exotic animals"
  }'
ai-response.jsonjson
{
  "message": "Generated 25 records",
  "count": 25,
  "mode": "ai",
  "data": [
    {
      "id": 1,
      "name": "Aurora",
      "species": "Blue Poison Dart Frog",
      "status": "available",
      "price": 189.99,
      "category": { "id": 3, "name": "Amphibians" }
    },
    {
      "id": 2,
      "name": "Kai",
      "species": "Veiled Chameleon",
      "status": "pending",
      "price": 349.00,
      "category": { "id": 2, "name": "Reptiles" }
    }
  ]
}

Context matters. The optional context field guides Gemini to generate thematically consistent data. Try "A Japanese restaurant in NYC" or "A B2B SaaS platform for HR".

// Faker.js Field Mapping

When using Faker mode (or as AI fallback), field names are matched to Faker methods:

faker-mapping.jsonjson
{
  "name":        "faker.person.fullName()",
  "email":       "faker.internet.email()",
  "phone":       "faker.phone.number()",
  "avatar":      "faker.image.avatar()",
  "price":       "faker.commerce.price()",
  "title":       "faker.commerce.productName()",
  "description": "faker.commerce.productDescription()",
  "address":     "faker.location.streetAddress()",
  "city":        "faker.location.city()",
  "country":     "faker.location.country()",
  "company":     "faker.company.name()",
  "url":         "faker.internet.url()",
  "image":       "faker.image.url()",
  "status":      "faker.helpers.arrayElement(['active','inactive','pending'])",
  "createdAt":   "faker.date.recent()",
  "boolean":     "faker.datatype.boolean()"
}

// Auto Mode Decision Tree

auto-mode.txttext
mode = "auto"
  │
  ├── Gemini API key configured?
  │   ├── YES → count ≤ 100?
  │   │   ├── YES → Use Gemini AI ✓
  │   │   └── NO  → Use Faker.js (too many records for AI)
  │   └── NO  → Use Faker.js
  │
  └── AI generation fails?
      └── Automatic fallback to Faker.js
          (response.mode = "faker-fallback")

Response Mode Values

"ai"
"faker"
"faker-fallback"

Check the mode field in the response to see which generator was used.

// Gemini Free Tier Limits

moqapi uses Gemini 2.0 Flash on the free tier. These are the rate limits:

15

Requests / min

1,500

Requests / day

1,000,000

Tokens / min

If you hit rate limits, the system automatically falls back to Faker.js. Configure your platform Gemini API key via the GEMINI_API_KEY environment variable.

// API Reference

POST/api/mock-apis/:id/resources/:resId/generate

Request Body

request-body.jsonjson
{
  "count": 25,          // Number of records (1-1000)
  "mode": "auto",       // "auto" | "ai" | "faker"
  "context": "optional" // Context hint for AI generation
}