ZuploZuplo
LoginStart for Free
  • Documentation
  • API Reference
Getting Started
    Develop in the portal
      1 - Setup Your Gateway2 - Rate Limiting3 - API Key Auth4 - Deploy5 - Dynamic Rate LimitingDynamic MCP Server - Quickstart
    Develop locally with the CLI
      1 - Setup Your Gateway2 - Rate Limiting3 - API Key Auth4 - Deploy5 - Dynamic Rate LimitingDynamic MCP Server - Quickstart
Concepts
API Management
    Overview
    API Keys
    Rate Limiting
    Caching
    GraphQL
    Monetization
    Policies
      Overview
      Authentication
      Authorization
      Security & Validation
      Metrics, Billing & Quotas
        QuotaMoesif Analytics & BillingAmberflo Metering / BillingReadme MetricsOpenMeterMonetization
      Testing
      Request Modification
      Response Modification
      Upstream Authentication
      GraphQL
      Caching
      Other
      Guides
    Handlers
AI Gateway
MCP Gateway
MCP Server
Developer Portal
Development
Deploying & Source Control
Analytics
Observability
Networking & Infrastructure
Account Management
Programming API
Build with AI
Zuplo CLI
Migration Guides
Platform LimitsVersion Support PolicySecuritySupportTrust & ComplianceChangelog
powered by Zudoku
Metrics, Billing & Quotas

Moesif Analytics & Billing Policy

Moesif moesif.com is an API analytics and monetization platform. This policy allows you to measure (and meter) API calls flowing through your Zuplo gateway.

Add the policy to each route you want to meter. Note you can specify the Meter API Name and Meter Value (meter increment) at the policy level.

Configuration

The configuration shows how to configure the policy in the 'policies.json' document.

Code
{ "name": "my-moesif-inbound-policy", "policyType": "moesif-inbound", "handler": { "export": "MoesifInboundPolicy", "module": "$import(@zuplo/runtime)", "options": { "applicationId": "$env(MOESIF_APPLICATION_ID)", "logRequestBody": true, "logResponseBody": true } } }

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 moesif-inbound.
  • handler.export <string> - The name of the exported type. Value should be MoesifInboundPolicy.
  • handler.module <string> - The module containing the policy. Value should be $import(@zuplo/runtime).
  • handler.options <object> - The options for this policy. See Policy Options below.

Policy Options

The options for this policy are specified below. All properties are optional unless specifically marked as required.

  • applicationId (required) <string> - Your Moesif application ID.
  • logRequestBody <boolean> - Set to false to disable sending the request body to Moesif. Defaults to true.
  • logResponseBody <boolean> - Set to false to disable sending the response body to Moesif. Defaults to true.

Using the Policy

By default, Zuplo will read the request.user.sub property and assign this as the moesif user_id attribute when sending to Moesif. However, this and the following attributes can be overriden in a custom code policy.

  • api_version
  • company_id
  • session_token
  • user_id
  • metadata

Here is some example code that shows how to override two of these attributes

Code
// Add this import at the top of your doc import { setMoesifContext } from "@zuplo/runtime"; setMoesifContext(context, { userId: "user-1234", metadata: { some: "arbitrary", meta: "data", }, });

Execute on every route

If you want to execute this policy on every route, you can add a hook in your runtime extensions file zuplo.runtime.ts:

Code
import { RuntimeExtensions } from "@zuplo/runtime"; export function runtimeInit(runtime: RuntimeExtensions) { runtime.addRequestHook((request, context) => { return context.invokeInboundPolicy("moesif-inbound", request); }); }

Note you can add a guard clause around the context.invokeInboundPolicy if you want to exclude a few routes.

Read more about how policies work

Edit this page
Last modified on September 5, 2026
QuotaAmberflo Metering / Billing
On this page
  • Configuration
    • Policy Configuration
    • Policy Options
  • Using the Policy
  • Execute on every route
JSON
TypeScript
TypeScript