Skip to main content

Quick Start

Minimal Configuration

The simplest way to use the Mocker plugin is with no configuration - it will create a default catch-all rule:

Custom Response

Responses Request Example

The mocker plugin automatically handles both chat completion and responses requests with the same configuration:

Installation

Add the plugin to your project:
Import in your code:

Basic Usage

Creating the Plugin

Adding to Bifrost

Disabling the Plugin

Supported Request Types

The Mocker plugin supports the following Bifrost request types:
  • Chat Completion Requests (ChatCompletionRequest) - Standard chat-based interactions
  • Responses Requests (ResponsesRequest) - OpenAI-compatible responses API format
  • Skip Context Key - Use "skip-mocker" context key to bypass mocking per request

Skip Mocker for Specific Requests

You can skip the mocker plugin for specific requests by adding a context key:

Key Features

Template Variables

Create dynamic responses using templates:
Available Variables:
  • {{provider}} - Provider name (e.g., “openai”, “anthropic”)
  • {{model}} - Model name (e.g., “gpt-4”, “claude-3”)
  • {{faker.*}} - Fake data generation (see Configuration Reference)

Weighted Response Selection

Configure multiple responses with different probabilities:

Latency Simulation

Add realistic delays to responses:

Advanced Matching

Regex Message Matching

Request Size Filtering

Faker Data Generation

Create realistic test data using faker variables:

Statistics and Monitoring

Get runtime statistics for monitoring:

Configuration Reference

MockerConfig

MockRule

Conditions

Response

SuccessResponse

ErrorResponse

Latency

Important: Use Go’s time.Duration constants:
  • ✅ Correct: 100 * time.Millisecond
  • ❌ Wrong: 100 (nanoseconds, barely noticeable)

Faker Variables

Personal Information

  • {{faker.name}} - Full name
  • {{faker.first_name}} - First name only
  • {{faker.last_name}} - Last name only
  • {{faker.email}} - Email address
  • {{faker.phone}} - Phone number

Location

  • {{faker.address}} - Street address
  • {{faker.city}} - City name
  • {{faker.state}} - State/province
  • {{faker.zip_code}} - Postal code

Business

  • {{faker.company}} - Company name
  • {{faker.job_title}} - Job title

Text and Data

  • {{faker.lorem_ipsum}} - Lorem ipsum text
  • {{faker.lorem_ipsum:10}} - Lorem ipsum with 10 words
  • {{faker.uuid}} - UUID v4
  • {{faker.hex_color}} - Hex color code

Numbers and Dates

  • {{faker.integer}} - Random integer (1-100)
  • {{faker.integer:10,50}} - Random integer between 10-50
  • {{faker.float}} - Random float (0-100, 2 decimals)
  • {{faker.float:1,10}} - Random float between 1-10
  • {{faker.boolean}} - Random boolean
  • {{faker.date}} - Date (YYYY-MM-DD format)
  • {{faker.datetime}} - Datetime (YYYY-MM-DD HH:MM:SS format)

Best Practices

Rule Organization

Development vs Production

Performance Considerations

  • Place specific conditions before general ones (higher priority)
  • Use simple string matching over complex regex when possible
  • Keep response templates reasonably sized
  • Consider disabling debug logging in production

Testing Your Configuration

Common Issues

Plugin Not Triggering

  1. Check if plugin is enabled: Enabled: true
  2. Verify rule is enabled: rule.Enabled: true
  3. Check probability: Probability: 1.0 for testing
  4. Verify conditions match your request

Latency Not Working

Use time.Duration constants, not raw integers:

Regex Not Matching

Test your regex pattern and ensure proper escaping:

Controlling Fallbacks

Skip Mocker Not Working

Ensure you’re using the correct context key format:

Responses Request Issues

If responses requests aren’t being mocked:
  1. Verify the plugin supports ResponsesRequest (version 1.2.13+)
  2. Check that your regex patterns match the message content
  3. Ensure the request type is schemas.ResponsesRequest

Debug Mode

Enable debug logging to troubleshoot: