tokens
that users accrue when they pay for monthly subscriptions or make top-up purchases. These tokens are consumed whenever an agent is used. Orb’s prepaid credits feature manages this token-based billing model efficiently.
external_plan_id
of these plans to free
and premium
respectively. Similar to the external_customer_id
, this allows you to refer to these plans in your codebase without having to store Orb’s internal plan IDs.token
currency.
The billable metric tracks request tokens directly, so pricing uses a simple 1:1 unit price. Each request token consumed reduces the token balance by exactly one token
without any conversion factors.
customer.created
webhook from Stripe (see this guide for setting up webhooks in Stripe). When a customer has been created in Stripe, create the customer in Orb using Orb’s create customer API endpoint.
external_customer_id
to this Orb API endpoint, which will allow you to take all customer-related actions in Orb’s API directly based on this internal id rather than having to store Orb’s created customer ID.
payment_provider=stripe_charge
and your Stripe customer ID as payment_provider_id
to this Orb endpoint. This step associates the Orb customer with the Stripe customer, allowing Orb to later pull in payment method information and trigger charges on your behalf.
credit_balance_depleted
and credit_balance_recovered
alert using the alert creation API. Note that the currency of these alerts should be set to token, corresponding to your pricing setup. We’ll explain this below, in the section on customer spend controls.
SetupIntent
flowsSetupIntent
(required on the server-side before you confirm the setup process on the client), make sure to associate the intent with the Stripe customer. Set usage=off_session
.
setup
– you’re just collecting the user’s payment method, not collecting immediate payment through this flow. Pass setupFutureUsage: off_session
as an option to ensure that the appropriate payment methods are displayed to your user.
stripe.confirmSetup
on your client side, passing in the clientSecret
returned by creating the SetupIntent
.
SetupIntent
successfully sets the Stripe customer’s invoice_settings.default_payment_method
to the collected payment method. When triggering charges, Orb uses customer.invoice_settings.default_payment_method
or falls back to customer.default_source
. Do this by listening to the setup_intent.succeeded
webhook and ensuring that the customer’s newly attached payment method is set as the default payment method.
Once you’ve updated the Customer’s default payment method, Orb will sync that payment method as the preferred payment method for future charges.
Address synchronization: In addition to payment method information, Orb can automatically keep customer addresses synchronized with Stripe. When you link an Orb customer to a Stripe customer, Orb will automatically pull the customer’s billing and shipping addresses from Stripe and update the corresponding Orb customer record. Additionally, Orb can be configured to automatically sync any address changes via Stripe’s customer.updated
webhook, ensuring that billing and shipping information remains consistent between both platforms without manual intervention. This automatic synchronization helps maintain accurate customer information for tax calculations, invoice delivery, and compliance requirements. For more details on configuring address syncing, see the Stripe integration documentation.
token
.
entry_type
= increment
signifies an increment in tokens
amount
represents the additional tokens being bought. For our pricing model, ensure that this is a multiple of 100K.
per_unit_cost_basis
represents the cost of each token in your invoicing currency, USD. Because the purchase rate of tokens is $10 per 100K tokens, set this to $0.0001.
expiry_date
represents when the tokens will automatically be depleted. Set this to one year from the grant (current) date.
invoice_settings.auto_collection
to True, invoice_settings.require_successful_payment
to True, and invoice_settings.net_terms
to 0.
Orb-Cache-Control
header, passing Orb-Cache-Control: cache
as a directive. Asynchronously, you can rehydrate this data without the header and automatically refresh live usage data.
In the upcoming invoice response, filter to the line item that represents your token utilization price and use the line_items
serialization’s credits_applied
field to show the number of tokens used in the current billing cycle.
In addition, you should list the customer’s invoices by using the list invoices endpoint filtered to your customer’s external_customer_id
. With this response, you’ll be able to:
line_items[].credits_applied
field for invoices that correspond to recurring subscription charges. You can identify these invoices by the presence of invoice_source=subscription
.
invoice.status
field) as well as explicitly annotate invoices that were a result of credit purchases (invoice_source=one_off
).
invoice_settings.require_successful_payment
to True, invoice_settings.auto_collection
to True, and invoice_settings.net_terms
to 0.
external_plan_id=free
body parameter. Because the user has already paid for their credit allotment for the current month, pass change_option=end_of_subscription_term
. This will schedule the plan change so that future charges no longer apply.
Note that you should not reclaim or expire any existing credits; by default, credit allocations on Premium expire within a month and ad hoc credit purchases should remain until their original expiration date.
external_plan_id=premium
body parameter. Because the user expects an upgrade in service immediately, pass change_option=immediate
.
Furthermore, set the billing_cycle_alignment=plan_change_date
to ensure that the user is charged $50 on upgrade. This will transition the subscription to Premium, and automatically issue the $50 invoice for in-advance charges.
In order to show the previewed charges as the result of the upgrade (especially for more complicated cases that involve prorated charges), you can dry-run the plan change when first loading the checkout flow by passing the header Orb-Dry-Run: true
. In addition, pass Include-Changed-Resources: true
to fetch a preview of created invoices in the response.
description
field to explain the nature of the grant. In this event, you should create the grant with a cost basis of $0 to avoid any additional charges to the customer.
Similarly, you can grant credits directly through the Orb webapp by navigating to the customer’s page and clicking the “Adjust credits” button, being sure that you are adjusting credits in the token currency: