If you’ve developed an API especially one that’s compute-intensive, such as for code execution, inference, or data processing - it’s time to consider how you’ll monetize it. But not just any monetization model will do. Traditional options like subscriptions, postpaid billing, or prepaid credits often fall short for APIs with unpredictable usage patterns, variable costs, and strict performance requirements. This guide introduces a pay-as-you-go model powered by real-time payments, designed for modern API services. With this setup, your users pay exactly for what they consume, and payments are processed instantly. There’s no need to manage user balances manually, chase down unpaid invoices, or limit usage through rate limiting. Throughout this guide, we’ll use a code execution API as our example — think of a service inspired by the popular open-source platform Judge0, where users can submit code in various programming languages (Python, JavaScript, Rust, etc.) and receive execution results. We’ll charge users a fixed fee per code submission.

Merchant Onboarding & Product Setup

1

Create a Paygentic account

Go to platform.paygentic.io and sign up. Choose Merchant during registration.
2

Create a Product

Open your merchant dashboard and create a new product:
Mercant Dashboard
Create product
3

Define Billable Metrics

This is what you’ll charge for — e.g., number of code submissions or execution time
Create billable metric
For different API tiers, you can create separate metrics:
  • Basic Submissions: Simple languages like Python, JavaScript
  • Premium Submissions: Complex languages like Rust, Haskell
  • Execution Time: Actual processing time in seconds
4

Create Plan and Price

  • Create a usage plan
  • Set a price for your metric (e.g., $0.001 per submission)
Create a plan
Create and link price
5

Generate Authorization Links

Next you need to create checkout/authorization links using which a user can subscribe to your plan and become a customer.Go to Product -> Choose the plan -> Generate authorization link
Create checkout links
How to use authorization links:
  • Send the link directly to your user via email
  • Use the API to generate links dynamically and embed them in button actions within your app
  • Add subscribe buttons on your landing page that redirect to these links
Always generate a unique authorization link for each individual user.

Tracking Usage

Now that your product is set up and customers can subscribe, it’s time to track the usage. This involves creating entitlements to pre-authorize payments(optional) and reporting usage events in real-time.
1

Create an Entitlement (Optional)

Before processing expensive operations like code execution, create an entitlement to reserve funds and guarantee payment. For high-volume APIs, use Paygentic’s edge endpoints to reduce latency by 30-70%.
Find Your IDs: You’ll need your API Key from Settings → API Keys, Merchant ID from Settings → Organization, and Billable Metric ID from your product’s billable metrics section.
// Create entitlement using edge API for optimal performance
const entitlement = await fetch('https://edge-api.paygentic.com/v0/entitlements', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.PAYGENTIC_API_KEY}`, // From Settings → API Keys
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    merchantId: process.env.PAYGENTIC_MERCHANT_ID, // From Settings → Organization  
    customerId: customerId,
    entitlementData: [
      {
        billableMetricId: process.env.PAYGENTIC_BILLABLE_METRIC_ID, // From your product's metrics
        quantity: 10 // Reserve for 10 code executions
      }
    ]
  })
});

const entitlementData = await entitlement.json();
// Save this entitlement ID - you'll need it for usage reporting!
const entitlementId = entitlementData.id; // e.g., "com_abc123def456"
Important: Store the entitlementId from the response! You’ll need this ID when reporting usage to consume from the pre-authorized amount.
Regional Edge Optimization: If you know your user’s location, use regional edge endpoints for even better performance:
// For users in Asia
const response = await fetch('https://asia-south1-edge-api.paygentic.com/v0/entitlements', {
  // ... same body
});

// Or use headers with main API
const response = await fetch('https://api.paygentic.com/v0/entitlements', {
  headers: {
    'X-Paygentic-Region': 'asia-south1',
    'Authorization': `Bearer ${process.env.PAYGENTIC_API_KEY}`,
    'Content-Type': 'application/json'
  },
  // ... same body
});
2

Report Usage Events

When a customer uses your API, report the usage immediately to trigger real-time billing:
// Report usage after successful code execution
const usageEvent = await fetch('https://edge-api.paygentic.com/v0/usage', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.PAYGENTIC_API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    idempotencyKey: `${submissionId}_${timestamp}`, // Unique key to prevent double billing
    entitlementId: entitlementId, // Optional: Connect to the pre-authorized entitlement
    customerId: customerId,
    merchantId: process.env.PAYGENTIC_MERCHANT_ID,
    timestamp: new Date().toISOString(),
    properties: [
      {
        billableMetricId: process.env.PAYGENTIC_BILLABLE_METRIC_ID,
        quantity: 1 // One code execution
      }
    ],
    metadata: {
      submissionId: submissionId,
      language: 'python',
      executionTime: '1.2s'
    }
  })
});

if (usageEvent.id) {
  console.log('✅ Usage reported and customer charged');
} else {
  console.error('❌ Failed to report usage:', await usageEvent.text());
}
While the entitlementId is optional when reporting usage, it is considered best practice to include it. Creating and consuming from a pre-authorized entitlement helps guarantee that you will be paid for the reported usage in full.
3

Check Merchant Dashboard

Head over to your merchant dashboard and enjoy being paid in real time.
Merchant Dashboard

Conclusion

🎉 You’ve successfully monetized your API service with real-time payments! You now benefit from:
  • Instant Revenue: Get paid immediately when customers use your API
  • Zero Risk: No unpaid usage or bad debt from customers
  • Transparent Pricing: Customers see exactly what they pay for each request
  • Scalable Architecture: Handles high-volume APIs with edge infrastructure