ZuploZuplo
LoginSign Up
  • Documentation
  • API Reference
Introduction
Getting Started
    Develop using the Portal
      1 - Setup Your Gateway2 - Rate Limiting3 - API Key Auth4 - Deploy5 - Dynamic Rate LimitingMCP - Quick start
    Develop Locally
      1 - Setup Your Gateway2 - Rate Limiting3 - API Key Auth
Concepts
Development
Policies
    Policy Catalog
    Authentication
    Authorization
    Security & Validation
    Metrics, Billing & Quotas
    Testing
      A/B Test Inbound PolicyMock API Response PolicySleep / Delay Policy
    Request Modification
    Response Modification
    Upstream Authentication
    Archival
    GraphQL
    Other
    Guides
Handlers
API Keys
MCP Server
MCP Gateway
AI Gateway
Developer Portal
Monetization
Deploying & Source Control
Observability
Networking & Infrastructure
Account Management
Programming API
Build with AI
Zuplo CLI
Migration Guides
Platform LimitsSecuritySupportTrust & ComplianceChangelog
powered by Zudoku
Testing

A/B Test Inbound Policy

Custom Policy Example

Zuplo is extensible, so we don't have a built-in policy for A/B Test Inbound, instead we've a template here that shows you how you can use your superpower (code) to achieve your goals. To learn more about custom policies see the documentation.

This example shows how to perform an action on incoming requests based on the result of a randomly generated number. A/B tests could also be performed on properties such as the request.user.

A/B tests can also be combined with other policies by passing data to downstream policies. For example, you could save a value in ContextData based on the results of the A/B test and use that value in a later policy to modify the request.

modules/my-policy.ts
import { ZuploContext, ZuploRequest } from "@zuplo/runtime"; export default async function (request: ZuploRequest, context: ZuploContext) { // Generate a random number to segment the test groups const score = Math.random(); if (score < 0.5) { // Do something for half the requests } else { // Do something else for the other half } return request; }

Configuration

The example below shows how to configure a custom code policy in the 'policies.json' document that utilizes the above example policy code.

config/policies.json
{ "name": "ab-test-inbound", "policyType": "custom-code-inbound", "handler": { "export": "default", "module": "$import(./modules/ab-test-inbound)" } }

Policy Configuration

  • name <string> - The name of your policy instance. This is used as a reference in your routes.
  • policyType <string> - The identifier of the policy. This is used by the Zuplo UI. Value should be ab-test-inbound.
  • handler.export <string> - The name of the exported type. Value should be default.
  • handler.module <string> - The module containing the policy. Value should be $import(./modules/YOUR_MODULE).

Using the Policy

Read more about how policies work

Edit this page
Last modified on May 29, 2026
OpenMeter PolicyMock API Response Policy
On this page
  • Configuration
    • Policy Configuration
  • Using the Policy
TypeScript
JSON