Accéder directement au contenu
Créez un compte
ou
connecter-vous
Logo de la documentation Stripe
/
Demander à l'assistant IA
Créez un compte
Connectez-vous
Démarrer
Paiements
Revenus
Plateformes et places de marché
Gestion de fonds
Ressources pour les développeurs
Aperçu
Billing
PrésentationÀ propos des API Billing
Abonnements
Invoicing
Facturation à la consommation
    Présentation
    Fonctionnement de la facturation à l'usage
    Cas d'usage
    Enregistrer la consommation en vue de la facturation
      Créer et configurer un compteur
      Enregistrer l'utilisation avec l'API
      Enregistrer l'utilisation dans le Dashboard
      Enregistrer l'utilisation avec S3
      Configurer le délai de grâce
    Proposer des crédits de facturation
    Surveiller l'utilisation
    Gérer votre configuration de facturation à l'usage
    Facturation à l'utilisation avancée
    Facturation des tokens LLM
Devis
Gestion des clients
Facturation avec d'autres produits
Recouvrement de revenus
Automatisations
Tester votre intégration
Tax
Présentation
Utiliser Stripe Tax
Gérer la conformité
Rapports
Présentation
Sélectionner un rapport
Configurer des rapports
API de rapport
Rapports sur plusieurs comptes
Comptabilisation des revenus
Données
Présentation
Différents cas d'usage des données métier et produit
SchémaActualisation des données
Sigma
Data Pipeline
Importer des données externes
AccueilRevenusUsage-based billingRecord usage for billing

Remarque

Cette page n'est pas encore disponible dans cette langue. Nous faisons tout notre possible pour proposer notre documentation dans davantage de langues et nous vous fournirons la version traduite dès qu'elle sera disponible.

Create and configure a meter

Create and configure a meter for usage-based billing.

Before you can record customer usage, you must create a meter, then configure it. After you configure the meter, you can’t make any changes aside from the display name.

Create a meter

Meters specify how to aggregate meter events over a billing period. Meter events represent all actions that customers take in your system (for example, API requests). Meters attach to prices and form the basis of what’s billed.

For the Alpaca AI example, meter events are the number of tokens a customer uses in a query. The meter is the sum of tokens over a month.

You can use the Stripe Dashboard or API to configure a meter. To use the API with the Stripe CLI to create a meter, get started with the Stripe CLI.

  1. On the Meters page, click Create meter.
  2. On the Create meter page, do the following:
    • For Meter name, enter the name of the meter to display and for organization purposes. For the Alpaca AI example, enter “Alpaca AI tokens.”
    • For Event name, enter the name to display in meter events when reporting usage to Stripe. For the Alpaca AI example, enter “alpaca_ai_tokens.”
    • Set the Aggregation method in the dropdown:
      • For the Alpaca AI example, select Sum. This will sum the values reported (in this example, number of tokens a customer uses) to determine the usage to bill for.
      • Choose Count to bill based on the number of events reported.
      • Choose Last to bill based on the last value reported.
      • Use the preview pane to set example usage events and verify the aggregation method.
    • Click Create meter.
    • (Optional) Under Advanced settings, specify the Dimensions that you want to tag your usage data with. To generate granular segment specific alerts, or to granularly price usage based on a combination of attributes, submit your usage data with dimensions that are populated for analytics and reporting. Some example dimensions are LLM model, token type, region, and event type.

Meter configuration attributes

Meter attributeDescription
Event nameThe name of the meter event that you want to record usage for with the meter. When you send usage to Stripe, specify this event name in the event_name field for the Meter Event. This allows the correct meter to record and aggregate the usage. You can only use an event name with a single meter.

Event ingestion

Specify how to send events to Stripe:

  • Raw: Handle all meter events as standalone events. Multiple events sent for the same timestamp don’t overwrite each other. The aggregation includes the multiple events. This is the default option if you don’t specify anything.
  • Pre-aggregated: If you send events for a specific time interval (hourly or daily), Stripe only uses the most recently received meter event in that time interval. A newer event sent within the same hourly or daily window overwrites the previous one. The meter event timestamp in UTC dictates the hour and day boundaries.

Aggregation formula

Specify how to aggregate usage over the billing period:

  • Sum: Bill customers based on the sum of all usage values for the billing period.
  • Count: Bill customers based on the count of all usage for the billing period.
  • Last: Bill customers based on the most recent usage event’s value for the billing period.

Payload key overrides

Specify which keys in the event payload refer to the customer and numerical usage values:

  • value_settings: Use this parameter to define the key in the event payload that refers to the numerical usage value. The default key is value, but you can specify a different key, such as tokens.
  • customer_mapping: Use this parameter to define the key in the event payload that refers to the Customer ID. The default key is stripe_customer_id, but you can specify a different key, such as customer_id.

Fix incorrect usage data

If you identify incorrectly recorded events in the current billing period, you can create a Meter Event Adjustment to cancel those events. You must specify the identifier for the meter event.

You can only cancel events sent to Stripe within the last 24 hours. If you cancel usage that’s included on a finalized invoice, we won’t update the invoice or issue a corrected invoice for the canceled usage. We don’t support billing adjustments for canceled usage on a finalized invoice sent to a customer.

You can also fix incorrectly recorded usage data by recording negative quantities. If the overall cycle usage is negative, Stripe reports the invoice line item usage quantity as 0.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/billing/meter_event_adjustments \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d type=cancel \ -d event_name=alpaca_ai_tokens \ -d "cancel[identifier]"={{METER_EVENT_IDENTIFIER}}
Cette page vous a-t-elle été utile ?
OuiNon
  • Besoin d'aide ? Contactez le service Support.
  • Rejoignez notre programme d'accès anticipé.
  • Consultez notre log des modifications.
  • Des questions ? Contactez l'équipe commerciale.
  • LLM ? Lire llms.txt.
  • Propulsé par Markdoc
Guides connexes
Usage-based pricing models