Skip to content

Usage-based subscription flow does not materialize charges/invoice lines, blocking customer credit consumption #4313

@pratham-ez

Description

@pratham-ez

Preflight Checklist

  • I have searched the issue tracker for an issue that matches the one I want to file, without success.
  • I am not looking for support or already pursued the available support channels without success.

OpenMeter Version

latest

Expected Behavior

Use case

I am integrating OpenMeter for usage-based billing with prepaid customer credits.

My target flow is:

  1. Create a customer
  2. Create metered features (token/call based usage)
  3. Create a plan with usage-based (non-flat) prices
  4. Subscribe the customer to that plan
  5. Ingest usage events
  6. Grant customer-level billing credits
  7. Let billing/subscription sync generate billable artifacts
  8. Consume credits as usage is billed

Goal: use customer credit balance as the source of truth for ongoing spend control and potential usage blocking logic.


Problem

In this flow, usage is ingested and meter queries show usage, but billing artifacts for that customer are not materialized:

  • customer charges endpoint stays empty
  • invoice creation fails with invoice_create_no_lines
  • customer credits remain unchanged (funded only, no consumed)

This prevents validating the expected “usage -> charge/invoice -> credit deduction” lifecycle for non-flat pricing.


Environment

  • OpenMeter quickstart Docker setup
  • API base: http://localhost:48888
  • Credits config in running container:
    • credits.enabled: true
    • enable_credit_then_invoice: true

Actual Behavior

  • GET /customers/{id}/charges returns empty (total: 0)
  • POST /api/v1/billing/invoices/invoice returns 400:
    • invoice_create_no_lines
  • Credits are not consumed:
    • balance unchanged
    • transactions contain funded, but no consumed

Steps To Reproduce

  1. Create customer (with usage attribution subject key)
  2. Create meter + feature
  3. Create plan with non-flat usage-based rate card
  4. Publish plan
  5. Create subscription for customer + plan
  6. Ingest event(s) for that customer subject
  7. Create customer-level credit grant (/api/v3/openmeter/customers/{id}/credits/grants)
  8. Trigger subscription sync / collect jobs
  9. Check:
    • GET /api/v3/openmeter/customers/{id}/charges
    • POST /api/v1/billing/invoices/invoice with customerId
    • GET /api/v3/openmeter/customers/{id}/credits/balance
    • GET /api/v3/openmeter/customers/{id}/credits/transactions

Additional Information

Expected behavior

For a customer with active subscription, non-flat usage-based pricing, ingested usage, and available credits:

  1. billable artifacts should be generated from usage (charges and/or invoice lines)
  2. invoice should be creatable/advancable with non-zero billable lines
  3. customer-level credits should be consumed according to settlement mode/config

Code-level hint / suspicion

This validation indicates non-flat invoice items require featureKey:

openmeter/billing/gatheringinvoice.go

if i.Price.Type() != productcatalog.FlatPriceType && i.FeatureKey == "" {
    errs = append(errs, errors.New("feature key is required for non-flat prices"))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions