闲社服务运行正常AI智能体自动化平台
s

条带计量器

技能标识:stripemeter

Integrate Stripe usage-based billing with idempotent event ingestion, late-event handling, and pre-invoice reconciliation. Use when implementing usage metering, tracking API calls or seats, pushing usage to Stripe, handling billing drift, or building usage-based pricing.

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 0.1.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

条带计量器

StripeMeter

StripeMeter 是一款原生集成 Stripe 的用量计量系统,可确保基于用量的计费获得准确的用量总计。它能对重试进行去重,通过水印处理延迟事件,维护持续运行的计数器,并仅将增量数据推送至 Stripe。

快速开始

bash
git clone https://github.com/geminimir/stripemeter && cd stripemeter
cp .env.example .env && docker compose up -d && pnpm -r build
pnpm db:migrate && pnpm dev

核心概念

事件(不可变账本)

每个用量事件都使用确定性幂等键存储。事件永远不会被删除或修改。

计数器(物化聚合)

按租户、指标、客户和时段预先计算的聚合结果(总和/最大值/最新值)。近乎实时更新。

水印(延迟事件处理)

每个计数器维护一个水印时间戳。处于延迟窗口(默认48小时)内的事件会触发重新聚合。

增量推送(Stripe同步)

追踪每个订阅项的 pushed_total,仅向 Stripe 发送增量数据。

API 端点

事件采集

bash
curl -X POST http://localhost:3000/v1/events/ingest \
-H Content-Type: application/json \
-d {
events: [{
tenantId: your-tenant-id,
metric: api_calls,
customerRef: cus_ABC123,
quantity: 100,
ts: 2025-01-16T14:30:00Z
}]
}

获取费用预估

bash
curl -X POST http://localhost:3000/v1/usage/projection \
-H Content-Type: application/json \
-d {tenantId: your-tenant-id, customerRef: cus_ABC123}

健康检查与指标

  • - 就绪检查:GET /health/ready
  • 指标:GET /metrics
  • 事件:GET /v1/events?tenantId=X&limit=10

Node.js SDK

typescript
import { createClient } from @stripemeter/sdk-node;

const client = createClient({
apiUrl: http://localhost:3000,
tenantId: your-tenant-id,
customerId: cus_ABC123
});

// 记录用量
await client.track({
metric: api_calls,
customerRef: cus_ABC123,
quantity: 100,
meta: { endpoint: /v1/search }
});

// 获取实时用量
const usage = await client.getUsage(cus_ABC123);
const projection = await client.getProjection(cus_ABC123);

Python SDK

python
from stripemeter import StripeMeterClient

client = StripeMeterClient(
api_url=http://localhost:3000,
tenant_id=your-tenant-id,
customerid=cusABC123
)

client.track(
metric=api_calls,
customerref=cusABC123,
quantity=100
)

Stripe计费驱动

如需直接集成 Stripe,请使用 stripe-driver 包:

typescript
import { StripeBillingDriverImpl } from @stripemeter/stripe-driver;

const driver = new StripeBillingDriverImpl({
liveKey: process.env.STRIPESECRETKEY,
testKey: process.env.STRIPETESTSECRET_KEY
});

// 向 Stripe 记录用量
await driver.recordUsage({
mode: live,
stripeAccount: default,
subscriptionItemId: si_xxx,
quantity: 100,
periodStart: 2025-01-01,
idempotencyKey: unique-key
});

// 获取用量摘要
const summary = await driver.getUsageSummary(
si_xxx,
2025-01-01,
default
);

影子模式

在不影响实际发票的情况下测试 Stripe 用量提交:

  1. 1. 在环境中设置 STRIPETESTSECRET_KEY
  2. 将价格映射标记为 shadow=true
  3. 提供 shadowStripeAccount、shadowPriceId
  4. 实际发票不受影响

定价模拟器

typescript
import { InvoiceSimulator } from @stripemeter/pricing-lib;

const simulator = new InvoiceSimulator();

const result = simulator.simulate({
customerId: test,
periodStart: 2024-01-01,
periodEnd: 2024-02-01,
usageItems: [{
metric: api_calls,
quantity: 25000,
priceConfig: {
model: tiered,
currency: USD,
tiers: [
{ upTo: 10000, unitPrice: 0.01 },
{ upTo: 50000, unitPrice: 0.008 },
{ upTo: null, unitPrice: 0.005 }
]
}
}]
});

项目结构

stripemeter/
├── packages/
│ ├── core/ # 共享类型、模式
│ ├── database/ # Drizzle ORM + Redis
│ ├── pricing-lib/ # 定价计算器
│ ├── stripe-driver/ # 直接 Stripe API 驱动
│ ├── sdk-node/ # Node.js SDK
│ └── sdk-python/ # Python SDK
├── apps/
│ ├── api/ # REST API (Fastify)
│ ├── workers/ # 后台工作进程 (BullMQ)
│ ├── admin-ui/ # 管理后台
│ └── customer-widget/# 可嵌入组件

环境变量

bash
STRIPESECRETKEY=sklivexxx # 正式 Stripe 密钥
STRIPETESTSECRETKEY=sktest_xxx # 测试 Stripe 密钥(用于影子模式)
DATABASE_URL=postgres://... # PostgreSQL 连接
REDIS_URL=redis://... # Redis 连接

常见任务

验证幂等性

bash

发送相同事件两次 - 仅计数一次


TENANT_ID=$(uuidgen) bash examples/api-calls/send.sh
curl http://localhost:3000/metrics | grep ingest

运行对账

检查本地总计与 Stripe 之间的偏差:

重放延迟事件

bash
curl -X POST http://localhost:3000/v1/replay \
-H Content-Type: application/json \
-d {tenantId: X, dryRun: true}

其他资源

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 stripemeter-1776295457 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 stripemeter-1776295457 技能

通过命令行安装

skillhub install stripemeter-1776295457

下载

⬇ 下载 stripemeter v0.1.0(免费)

文件大小: 18.25 KB | 发布时间: 2026-4-16 15:40

v0.1.0 最新 2026-4-16 15:40
Initial release of stripemeter – usage-based billing integration for Stripe.

- Provides Stripe-native metering with idempotent event ingestion and late-event handling.
- Supports usage tracking, metrics aggregation, Stripe delta push, and reconciliation mechanisms.
- Includes API endpoints for event ingestion, cost projection, health checks, and metrics access.
- Offers Node.js and Python SDKs for easy integration.
- Features shadow mode for testing Stripe billing integrations safely.
- Bundles pricing simulator, admin UI, and reconciliation tooling.
返回顶部