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: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:{{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
| Field | Type | Default | Description |
|---|---|---|---|
Enabled | bool | false | Enable/disable the entire plugin |
DefaultBehavior | string | "passthrough" | Action when no rules match: "passthrough", "success", "error" |
GlobalLatency | *Latency | nil | Global latency applied to all rules |
Rules | []MockRule | [] | List of mock rules evaluated in priority order |
MockRule
| Field | Type | Default | Description |
|---|---|---|---|
Name | string | - | Unique rule name for identification |
Enabled | bool | true | Enable/disable this specific rule |
Priority | int | 0 | Higher numbers = higher priority |
Probability | float64 | 1.0 | Activation probability (0.0=never, 1.0=always) |
Conditions | Conditions | {} | Matching conditions (empty = match all) |
Responses | []Response | - | Possible responses (weighted random selection) |
Latency | *Latency | nil | Rule-specific latency override |
Conditions
| Field | Type | Description |
|---|---|---|
Providers | []string | Match specific providers: ["openai", "anthropic"] |
Models | []string | Match specific models: ["gpt-4", "claude-3"] |
MessageRegex | *string | Regex pattern to match message content |
RequestSize | *SizeRange | Request size constraints in bytes |
Response
| Field | Type | Description |
|---|---|---|
Type | string | Response type: "success" or "error" |
Weight | float64 | Weight for random selection (default: 1.0) |
Content | *SuccessResponse | Required if Type="success" |
Error | *ErrorResponse | Required if Type="error" |
AllowFallbacks | *bool | Control fallback behavior (nil=allow, false=block) |
SuccessResponse
| Field | Type | Description |
|---|---|---|
Message | string | Static response message |
MessageTemplate | *string | Template with variables: {{provider}}, {{model}}, {{faker.*}} |
Model | *string | Override model name in response |
Usage | *Usage | Token usage information |
FinishReason | *string | Completion reason (default: "stop") |
CustomFields | map[string]interface{} | Additional metadata fields |
ErrorResponse
| Field | Type | Description |
|---|---|---|
Message | string | Error message to return |
Type | *string | Error type (e.g., "rate_limit", "auth_error") |
Code | *string | Error code (e.g., "429", "401") |
StatusCode | *int | HTTP status code |
Latency
| Field | Type | Description |
|---|---|---|
Type | string | Latency type: "fixed" or "uniform" |
Min | time.Duration | Minimum/exact latency (use time.Millisecond) |
Max | time.Duration | Maximum latency (required for "uniform") |
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
- Check if plugin is enabled:
Enabled: true - Verify rule is enabled:
rule.Enabled: true - Check probability:
Probability: 1.0for testing - Verify conditions match your request
Latency Not Working
Usetime.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:- Verify the plugin supports
ResponsesRequest(version 1.2.13+) - Check that your regex patterns match the message content
- Ensure the request type is
schemas.ResponsesRequest

