尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

Agentic 怎么配置 pricingPlans 实现免费套餐与按请求量阶梯计费的 Stripe 订阅

Agentic 怎么配置 pricingPlans 实现免费套餐与按请求量阶梯计费的 Stripe 订阅 Agentic 怎么配置 pricingPlans 实现免费套餐与按请求量阶梯计费的 Stripe 订阅【免费下载链接】agenticYour API ⇒ Paid MCP. Instantly.项目地址: https://gitcode.com/GitHub_Trending/ag/agentic如果你的 MCP 产品或 OpenAPI 服务要通过 Agentic 的 MCP Gateway 对外收费核心任务就是在agentic.config.ts里写好pricingPlans一个free免费套餐加一个按每月请求量阶梯计费的付费套餐。Agentic 基于这套声明式配置通过 Stripe 订阅计费来处理客户订阅与扣款。前提已安装 Node.js你的 origin 服务器已部署到一个公开可访问的httpsURLMCP 需支持 Streamable HTTP 传输。准备条件安装 Agentic CLI 并登录然后在你的项目源码根目录创建agentic.config.tsTypeScript 配置可获得完整自动补全和类型检查需要先安装agentic/platform作为 dev 依赖npm i -g agentic/cli agentic loginnpm i -save-dev agentic/platformagentic.config.ts至少包含name、description和origin定价配置写在pricingPlans字段里import { defineConfig } from agentic/platform export default defineConfig({ name: My MCP Product, description: A brief description of your product, origin: { type: mcp, url: https://your-remote-mcp-server.example.com/mcp }, pricingPlans: [/* 见下文 */] })配置 pricingPlansfree 套餐 阶梯请求量付费套餐先理解几个关键概念依据 docs/publishing/config/pricing.mdxPricingPlan每个套餐需要name展示名如Free、Standard和slug小写 kebab-case跨部署保持稳定。除free外的套餐slug应带上interval后缀以便区分计费周期如starter-monthly、pro-annual。interval取值为day/week/month/year默认为month。PricingPlanLineItem每个套餐由一个或多个 LineItem 组成每个套餐最多 20 个每项映射到一个 Stripe Product / Pricemetered类型还会对应一个 Stripe Meter。usageType: licensed是固定价格项amount为每个计费周期收取的固定金额usageType: metered是按用量收费项billingScheme为per_unit或tiered。保留 slugbase专用于套餐的默认licensed项requests专用于按计费区间内请求数计费的metered项其他自定义项的 slug 必须以custom-开头。金额单位所有金额字段amount、unitAmount、flatAmount都以最小货币单位表示USD 为美分。100 $1.00 USD1000 $10.00 USD。阶梯计费billingScheme: tiered必须设置tiersMode和tiers不能再写unitAmount。tiersMode: volume按区间内的最大用量确定统一单价tiersMode: graduated单价随用量增长逐档变化。tiers中每一档的upTo是该档最大用量最后一档用字符串inf表示无上限每档unitAmount与flatAmount必须二选一不能同时出现。rateLimit套餐级限流interval可以是秒数正整数或时长字符串如10s、1m、1d、1w见 docs/publishing/config/rate-limits.mdx不设置时继承项目级defaultRateLimit用rateLimit.enabled: false可关闭该套餐限流。免费套餐agentic/platform导出的defaultFreePricingPlan就是项目未指定任何pricingPlans时的默认免费月度套餐可以直接复用也可以像下面这样显式写一个带限流的 free 套餐。pricingIntervals默认为[month]。只有一个计费周期时各套餐无需写interval若配置了多个周期如[month, year]每个非 free 套餐必须指定interval且每个周期都要有对应套餐。下面是一个完整的“免费 阶梯付费”双套餐配置基于 docs/publishing/config/examples.mdx 的 Usage-Based Tiered Pricing Example数值照原文保留import { defineConfig } from agentic/platform export default defineConfig({ name: My MCP Product, description: A brief description of your product, origin: { type: mcp, url: https://your-remote-mcp-server.example.com/mcp }, pricingPlans: [ { name: Free, slug: free, lineItems: [ { slug: requests, usageType: metered, billingScheme: per_unit, unitAmount: 0 } ], // Limit free-tier requests to 10 per day rateLimit: { interval: 1d, limit: 10 } }, { name: Standard, slug: standard, lineItems: [ { slug: base, usageType: licensed, // $10.00 USD base price per month amount: 1000 // in cents }, { slug: requests, usageType: metered, billingScheme: tiered, tiersMode: volume, tiers: [ { // Free for the first 1000 requests per month upTo: 1000, unitAmount: 0 // in cents }, { // After 10k requests, it costs $0.001 USD per request up to // 50k requests per month upTo: 50_000, unitAmount: 0.1 // in cents }, { // After 50k requests, it costs $0.0008 USD per request up to // 500k requests per month upTo: 500_000, unitAmount: 0.08 }, { // After 500k requests, it costs $0.0006 USD per request up to // 2.5M requests per month upTo: 2_500_000, unitAmount: 0.06 }, { // After 2.5M requests, it costs $0.0005 USD per request, with // no upper bound set upTo: inf, unitAmount: 0.05 } ] } ], // Rate limit set to 100 requests per second rateLimit: { interval: 1s, limit: 100 } } ] })这个结构里Standard套餐由两项构成base是每月 $10 的固定订阅费licensedrequests是按当月请求量阶梯计费的metered项Free套餐用unitAmount: 0的metered项保证不收费并靠rateLimit限制每日 10 次请求。如果你只需要“免费 固定月费”也可以直接复用导出的默认免费套餐import { defaultFreePricingPlan, defineConfig } from agentic/platform export default defineConfig({ // ... pricingPlans: [ defaultFreePricingPlan, { name: Basic, slug: basic, trialPeriodDays: 7, lineItems: [ { slug: base, usageType: licensed, amount: 499 // $4.99 USD } ] } ] })部署并用返回的 pricingPlans 验证配置在agentic.config.ts所在目录运行agentic deploy每次运行agentic deploy都会创建一个不可变的预览部署不会影响已发布的产品直到你运行agentic publish。部署成功时CLI 会返回该部署的 JSON其中pricingPlans字段展示解析后的套餐结构可以据此核对定价配置是否正确下面是文档中的示例输出字段结构可以参考具体 id、hash、数值以你实际部署返回为准{ identifier: dev/search42ad78bf, pricingPlans: [ { name: Free, slug: free, rateLimit: { interval: 86400, limit: 10, mode: approximate, enabled: true }, lineItems: [ { slug: requests, usageType: metered, billingScheme: per_unit, unitAmount: 0 } ] }, { name: Standard, slug: standard, interval: month, rateLimit: { interval: 1, limit: 100, mode: approximate, enabled: true }, lineItems: [ { slug: base, usageType: licensed, amount: 1000 }, { slug: requests, usageType: metered, billingScheme: tiered, tiersMode: volume, tiers: [ { unitAmount: 0, upTo: 1000 }, { unitAmount: 0.01, upTo: 50000 }, { unitAmount: 0.008, upTo: 500000 }, { unitAmount: 0.006, upTo: 2500000 }, { unitAmount: 0.005, upTo: inf } ] } ] } ], pricingIntervals: [month], gatewayMcpUrl: https://gateway.agentic.so/dev/search42ad78bf/mcp }核对要点两个套餐的lineItems是否如配置解析、requests项的billingScheme是否为tiered且tiers档位完整、各套餐的rateLimit是否生效。配置不合法时deploy 会直接报错常见校验包括每个pricingInterval至少要有一个对应套餐pricingPlans内各套餐slug必须唯一同一套餐内各 LineItemslug也必须唯一不同套餐中相同slug的 LineItem 必须使用相同的usageTypebase项必须是licensedrequests项必须是metered自定义项 slug 必须以custom-开头per_unit模式必须给unitAmount且不能有tiers/tiersModetiered模式必须给非空tiers和tiersMode且不能有unitAmount或transformQuantity。另外部署返回的 JSON 中不包含 origin 信息——origin 一旦部署到 Agentic 的 MCP Gateway 就被视为隐藏这是预期行为。发布后 Stripe 订阅生效验证无误后发布agentic publishCLI 会提示你确认一个semver版本号。发布后产品对外可用客户就可以通过 Stripe 订阅你的产品支付经由 Stripe Connect 处理你可以在 Agentic dashboard 跟踪客户用量与收入。Agentic 会基于你的声明式配置自动创建和管理所有相关 Stripe 资源products、prices、meters、subscriptions、customers 等。每次修改定价并创建新部署时相关 Stripe 资源会被惰性 upsert未变更的资源会继续复用这对已订阅的客户很重要——这也是各slug必须跨部署保持稳定、licensed与metered项切换时必须使用不同 slug 的原因。更完整的字段定义与更多套餐示例如按请求量分档的 Pay-As-You-Go 方案见 docs/publishing/config/pricing.mdx 与 docs/publishing/config/examples.mdx发布与测试流程见 docs/publishing/guides/existing-mcp-server.mdx。【免费下载链接】agenticYour API ⇒ Paid MCP. Instantly.项目地址: https://gitcode.com/GitHub_Trending/ag/agentic创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表