AgentSkillsCN

tl-openmeter-api

与 OpenMeter REST API 配合,实现用量计量、计费与权限管理。涵盖 CloudEvents 数据摄入、计量器、功能、套餐、客户、订阅、权限、通知、计费档案、发票、应用、插件、授权,以及 Stripe 市场。适用于集成 OpenMeter、调试计量功能、构建目录同步脚本,或当用户提及 OpenMeter API 时使用。

SKILL.md
--- frontmatter
name: tl-openmeter-api
description: Works with the OpenMeter REST API for usage metering, billing, and entitlements. Covers CloudEvents ingestion, meters, features, plans, customers, subscriptions, entitlements, notifications, billing profiles, invoices, apps, addons, grants, and the Stripe marketplace. Use when integrating OpenMeter, debugging metering, building catalog sync scripts, or when the user mentions OpenMeter API.
license: MIT
compatibility: Requires HTTP client. OpenMeter OSS or Cloud instance.
metadata:
  author: tl-agent-skills
  version: "2.1"
  suite: tl-openmeter
  related: tl-openmeter-local-dev tl-openmeter-api-mcp-server

OpenMeter API

Project-agnostic reference for the OpenMeter REST API. Organized by the official API tags from the OpenAPI 3.0 spec.

Suite

SkillPurpose
tl-openmeter-apiThis skill: REST API reference
tl-openmeter-local-devLocal dev setup: Docker, ngrok, Stripe App, webhooks
tl-openmeter-api-mcp-serverMCP server for calling local OpenMeter from Cursor

When to Use

  • "How do I ingest events into OpenMeter?"
  • "Create an OpenMeter customer with subscription"
  • "Query usage for a meter"
  • "Set up notification rules for threshold alerts"
  • "Manage billing invoices"
  • "Install the Stripe marketplace app"
  • Debugging metering, billing, or subscription lifecycle

Resources

Official API Tags

The OpenMeter API organizes endpoints into these 15 tags:

#TagDescription
1AppsManage app integrations (list, get, update, uninstall)
2App: Custom InvoicingInterface third-party invoicing and payment systems
3App: StripeStripe billing support (API key, webhook, checkout)
4BillingBilling profiles, invoices, customer overrides, pending lines
5CustomersCustomer lifecycle, app data, Stripe linking, entitlement values
6DebugInternal metrics (Prometheus format)
7EntitlementsUsage limits, quota-based pricing, feature access
8EventsCloudEvents ingestion and listing
9Lookup InformationStatic data (currencies, progress)
10MetersAggregation rules, usage queries, group-by
11NotificationsChannels, rules, events for threshold alerts
12PortalConsumer-facing usage dashboards via scoped tokens
13Product CatalogPlans, features, addons (versioning, rate cards, publish lifecycle)
14SubjectsDeprecated — use Customers with usageAttribution.subjectKeys
15SubscriptionsCustomer plan assignments, cancel, change, migrate, restore

Base URL and Auth

  • Base URL: OPENMETER_URL (e.g. http://localhost:8888 for local, or your deployed URL)
  • Auth: Authorization: Bearer <OPENMETER_API_KEY>. Local self-hosted often runs unauthenticated.
  • Content-Type: application/json for most endpoints; application/cloudevents+json for POST /api/v1/events

Concepts

code
Meter (aggregates events) → Feature (metered entitlement) → Plan (limits + pricing)
                                                                    ↓
Customer (subject keys) ←→ Subscription (customer + plan = active entitlements)
                                    ↓
                              Billing Profile → Invoices (via Stripe/Sandbox/Custom App)
  • Meter: Aggregation rule for events (COUNT, SUM, etc.). Events reference a meter via type matching eventType.
  • Feature: Tied to a meter or boolean; used in plan rate cards for quotas and overage.
  • Plan: Contains phases and rate cards. Part of the Product Catalog alongside Features and Addons.
  • Addon: Modular rate card bundle, attachable to plans or subscriptions.
  • Customer: Has usageAttribution.subjectKeys; event subject must match for usage to attach.
  • Subscription: Links customer to plan; active subscription grants entitlements.
  • Entitlement: Per-customer access to a feature with usage tracking and limits.
  • Grant: One-time credit or usage allocation against an entitlement.
  • Notification: Automated alert when entitlement thresholds are reached.
  • App: Billing provider integration (Stripe, Sandbox, Custom Invoicing).

1. Events

Ingest: POST /api/v1/events | Content-Type: application/cloudevents+json

json
{
  "specversion": "1.0",
  "id": "unique-event-id",
  "type": "api_request",
  "source": "my-app",
  "subject": "user_abc123",
  "time": "2026-02-14T12:00:00Z",
  "data": { "value": 1, "path": "/v1/events", "method": "GET" }
}
FieldRequiredNotes
typeYesMust match meter's eventType
subjectYesMust match customer's usageAttribution.subjectKeys
sourceYesIdentifies the producing system
idYesIdempotency key (deduplication within 24h)
timeRecommendedISO 8601 timestamp
dataRecommendedArbitrary payload; meters use $.path for groupBy

List events: GET /api/v1/events?from=...&to=...&subject=...&hasError=...


2. Meters

OperationMethodPath
ListGET/api/v1/meters
CreatePOST/api/v1/meters
GetGET/api/v1/meters/{meterIdOrSlug}
UpdatePUT/api/v1/meters/{meterIdOrSlug}
DeleteDELETE/api/v1/meters/{meterIdOrSlug}
Query usageGET/api/v1/meters/{meterIdOrSlug}/query?subject=...&from=...&to=...&windowSize=HOUR
Query (POST)POST/api/v1/meters/{meterIdOrSlug}/query
Group-by valuesGET/api/v1/meters/{meterIdOrSlug}/group-by/{groupBy}/values
List subjectsGET/api/v1/meters/{meterIdOrSlug}/subjects

Aggregation types: COUNT, SUM, AVG, MIN, MAX, UNIQUE_COUNT

Window sizes: MINUTE, HOUR, DAY, MONTH


3. Product Catalog

Plans, Features, and Addons all live under this tag. See references/product-catalog.md for versioning lifecycle, rate cards, and detailed examples.

Features

OperationMethodPath
ListGET/api/v1/features
CreatePOST/api/v1/features
GetGET/api/v1/features/{featureId}
DeleteDELETE/api/v1/features/{featureId}

Plans

OperationMethodPath
ListGET/api/v1/plans
CreatePOST/api/v1/plans
GetGET/api/v1/plans/{planIdOrKey}
UpdatePUT/api/v1/plans/{planIdOrKey}
DeleteDELETE/api/v1/plans/{planIdOrKey}
Next versionPOST/api/v1/plans/{planIdOrKey}/next
PublishPOST/api/v1/plans/{planIdOrKey}/publish
ArchivePOST/api/v1/plans/{planIdOrKey}/archive
Plan AddonsCRUD/api/v1/plans/{planIdOrKey}/addons/...

Addons

OperationMethodPath
ListGET/api/v1/addons
CreatePOST/api/v1/addons
GetGET/api/v1/addons/{addonIdOrKey}
UpdatePUT/api/v1/addons/{addonIdOrKey}
DeleteDELETE/api/v1/addons/{addonIdOrKey}
PublishPOST/api/v1/addons/{addonIdOrKey}/publish
ArchivePOST/api/v1/addons/{addonIdOrKey}/archive

Critical: Plan/addon keys must be snake_case (^[a-z0-9]+(?:_[a-z0-9]+)*$). Rate card upToAmount must be a string. Subscription creation uses plan: { "key": "plan_key" }, not a raw planId. Plans follow a draft -> published -> archived lifecycle.


4. Customers

OperationMethodPath
ListGET/api/v1/customers?page=...&pageSize=...&subject=...&planKey=...
CreatePOST/api/v1/customers
GetGET/api/v1/customers/{customerIdOrKey}
DeleteDELETE/api/v1/customers/{id}
Get accessGET/api/v1/customers/{id}/access
SubscriptionsGET/api/v1/customers/{id}/subscriptions
Entitlement valueGET/api/v1/customers/{id}/entitlements/{featureKey}/value
Stripe dataGET/PUT/api/v1/customers/{id}/stripe
Stripe portalPOST/api/v1/customers/{id}/stripe/portal
App dataGET/PUT/DELETE/api/v1/customers/{id}/apps/{appIdOrType}

Gotcha: DELETE returns 409 if customer has active subscriptions or non-final invoices. See references/billing.md for the customer delete flow.


5. Subscriptions

OperationMethodPath
CreatePOST/api/v1/subscriptions
GetGET/api/v1/subscriptions/{id}
EditPATCH/api/v1/subscriptions/{id}
DeleteDELETE/api/v1/subscriptions/{id}
CancelPOST/api/v1/subscriptions/{id}/cancel
Change planPOST/api/v1/subscriptions/{id}/change
MigratePOST/api/v1/subscriptions/{id}/migrate
RestorePOST/api/v1/subscriptions/{id}/restore
Unschedule cancelPOST/api/v1/subscriptions/{id}/unschedule-cancelation
Subscription addonsGET/POST/api/v1/subscriptions/{id}/addons

6. Entitlements

OperationMethodPath
List allGET/api/v1/entitlements
Get by idGET/api/v1/entitlements/{id}
Per-customer valueGET/api/v1/customers/{id}/entitlements/{featureKey}/value
HistoryGET/api/v1/subjects/{subjectIdOrKey}/entitlements/{idOrKey}/history
Reset usagePOST/api/v1/subjects/{subjectIdOrKey}/entitlements/{id}/reset
OverridePUT/api/v1/subjects/{subjectIdOrKey}/entitlements/{idOrKey}/override
GrantsPOST/GET/DELETE/api/v1/subjects/.../entitlements/.../grants, /api/v1/grants/...

7. Billing

See references/billing.md for invoice lifecycle, customer delete flow, and rate card schemas.

ResourceOperationsBase Path
ProfilesList, Create, Get, Update, Delete/api/v1/billing/profiles
Customer overridesList, Upsert, Get, Delete/api/v1/billing/profiles/{id}/customer-overrides
InvoicesList, Get, Update, Delete, Simulate/api/v1/billing/invoices
Invoice actionsAdvance, Approve, Retry, Void, Snapshot, Recalculate taxPOST on /api/v1/billing/invoices/{id}/{action}
Pending linesCreate, Invoice/api/v1/billing/customers/{id}/invoices/pending-lines

Invoice lifecycle: gathering → draft → issuing → issued → (paid | void | uncollectible)


8. Notifications

See references/notifications.md for channels, rules, and event details.

ResourceOperationsBase Path
ChannelsList, Create, Get, Update, Delete/api/v1/notification/channels
RulesList, Create, Get, Update, Delete, Test/api/v1/notification/rules
EventsList, Get, Resend/api/v1/notification/events

Note: Channel creation via API is Cloud-only (Svix-backed). Self-hosted uses YAML config.


9. Apps

OperationMethodPath
List appsGET/api/v1/apps
Get appGET/api/v1/apps/{id}
Update appPUT/api/v1/apps/{id}
UninstallDELETE/api/v1/apps/{id}

App: Stripe

OperationMethodPath
Update Stripe keyPUT/api/v1/apps/{id}/stripe/api-key
Stripe webhookPOST/api/v1/apps/{id}/stripe/webhook
Checkout sessionPOST/api/v1/stripe/checkout/sessions

App: Custom Invoicing

OperationMethodPath
Draft syncedPOST/api/v1/apps/{id}/custom-invoicing/draft-synchronized
Issuing syncedPOST/api/v1/apps/{id}/custom-invoicing/issuing-synchronized
Update paymentPOST/api/v1/apps/{id}/custom-invoicing/update-payment-status

Marketplace

OperationMethodPath
List listingsGET/api/v1/marketplace/listings
Get listingGET/api/v1/marketplace/listings/{type}
Install (generic)POST/api/v1/marketplace/listings/{type}/install
Install (API key)POST/api/v1/marketplace/listings/{type}/install/apikey
Install (OAuth2 URL)GET/api/v1/marketplace/listings/{type}/install/oauth2
Install (OAuth2 auth)POST/api/v1/marketplace/listings/{type}/install/oauth2/authorize

10. Portal

OperationMethodPath
Create tokenPOST/api/v1/portal/tokens
List tokensGET/api/v1/portal/tokens
Invalidate tokensPOST/api/v1/portal/tokens/invalidate
Query meterGET/api/v1/portal/meters/{meterSlug}/query

11. Lookup Information

OperationMethodPath
List currenciesGET/api/v1/currencies
Get progressGET/api/v1/progress

12. Debug

OperationMethodPath
Get metricsGET/api/v1/debug/metrics

13. Subjects (Deprecated)

Use Customers with usageAttribution.subjectKeys instead.

OperationMethodPath
ListGET/api/v1/subjects
UpsertPOST/api/v1/subjects
GetGET/api/v1/subjects/{subjectIdOrKey}
DeleteDELETE/api/v1/subjects/{subjectIdOrKey}

Gotchas and Errors

SymptomCauseFix
409 on DELETE customerActive subscriptions or non-final invoicesCancel subs, void/delete invoices first
400 "single draft version"Duplicate plan draftSkip creation if plan key exists
400 "only Plans in [draft scheduled] can be published"Plan already activeExpected — skip publish
500 on POST /notification/channelsSelf-hosted: not implementedUse YAML config for local; API for Cloud only
405 on PATCH invoicePATCH not supportedUse POST subpaths: /advance, /approve, /void
Usage not attributedSubject mismatchEvent subject must match usageAttribution.subjectKeys
Plan not foundWrong key formatUse snake_case: pro, pro_plus
Event not meteredType mismatchEvent type must equal meter's eventType
Overage not billedTier formatupToAmount must be string; include both flatPrice and unitPrice
IDs look like 01G65Z...ULID formatStandard; regex: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$

Reference

The full OpenAPI 3.0 spec is bundled at assets/openapi-spec.json. Use it as the source of truth for request/response schemas, query parameters, and error codes.