Skip to main content

The operating model

You may want to grant usage credits to customers even before they make a purchase. This is handy for:
  • Free trial credits - Give new signups free credits to try your service
  • Promotional campaigns - Grant credits as part of marketing initiatives
  • Testing and demos - Provide credits for product demonstrations
This guide walks you through granting credits to customers who don’t yet have an active subscription or purchase.

System flow

To grant credits before a purchase, you need to:
  1. Create a customer in Ruba (if they don’t exist)
  2. Create a meter with Sum aggregation to track usage
  3. Ingest an event with a negative value to grant credits
Why negative values?When you ingest an event with a negative value (e.g., -10) into a meter using Sum aggregation, it grants the customer credits. A negative balance means available credits, which get reduced as they use your service.

Step 1: Create a Meter

First, create a meter to track your customers’ usage.
1

Navigate to Meters

Open Products → Meters in the dashboard.
2

Create a new meter

Click Create Meter and configure:
  • Name: Give your meter a descriptive name (e.g., “API Calls” or “Storage Usage”)
  • Filter: Add filters to match your usage events (e.g., name equals “api_usage”)
  • Aggregation: Select Sum and enter the property to sum (e.g., units)
The meter must use Sum aggregation for this approach to work.
3

Save the meter

Save your meter and note the meter name, you’ll need this when ingesting events.
Learn more about creating meters.

Step 2: Create a Customer

If your customer doesn’t already exist in Ruba, create them first.

Option A: Create via Dashboard

1

Navigate to Customers

Open Customers in the dashboard.
2

Add new customer

Click Add Customer and fill in:
  • Email: Customer’s email address (required)
  • Name: Customer’s full name (optional)
  • External ID: Your internal user ID for easy reference (optional but recommended)
3

Save customer

Click Save and note the Customer ID.

Option B: Create via API

Use the Ruba SDK or API to create a customer programmatically:
create-customer.ts
Use the externalId field to link Ruba customers with your internal user system. This lets you reference customers without storing Ruba’s internal ID.

Using External ID

If you set an externalId when creating the customer, you can use it in event ingestion in place of the Ruba customer ID:
Learn more about customer management.

Step 3: Grant Credits by Ingesting a Negative Event

Now that you have a customer and a meter, grant credits by ingesting an event with a negative value.

Using the Ruba SDK

grant-credits.ts

Using External Customer ID

If you’re using externalId for customer management:
grant-credits-external.ts

Step 4: Verify Credits Were Granted

Confirm that the credits were successfully granted to the customer.

Using Customer Meters API

Example Usage Flow