コンテンツにスキップ
アカウントを作成
または
サインイン
Stripe ドキュメントのロゴ
/
AI に質問する
アカウントを作成
サインイン
始める
支払い
売上
プラットフォームおよびマーケットプレイス
資金管理
開発者向けリソース
概要
バージョン管理
変更ログ
API バージョンのアップグレード
SDK バージョンをアップグレードする
Essentials
SDK
API
テスト
Stripe CLI
サンプルプロジェクト
ツール
ワークベンチ
開発者ダッシュボード
Stripe Shell
Visual Studio Code をご利用の場合
機能
ワークフロー
イベントの送信先
Stripe 健全性アラートファイルのアップロード
AI ソリューション
エージェントツールキット
モデルコンテキストプロトコルBuild agentic AI SaaS Billing workflows
セキュリティとプライバシー
セキュリティ
Stripebot ウェブクローラー
プライバシー
Stripe を拡張する
Stripe Appsを構築する
Stripe アプリを使用する
パートナー
Partner Ecosystem
パートナー認定
ホーム開発者向けリソース

注

このページはまだ日本語ではご利用いただけません。より多くの言語で文書が閲覧できるように現在取り組んでいます。準備が整い次第、翻訳版を提供いたしますので、もう少しお待ちください。

Build agentic AI SaaS Billing workflows

Automate recurring Billing workflows using the Stripe API and AI-driven agents.

You can enable your AI agents to create and manage subscription-based SaaS Billing programs with Stripe. In this guide, you’ll learn how to:

  • Provision a new customer and subscription
  • Respond to subscription lifecycle events using webhooks
  • Invoke billing actions from an AI agent using the agent toolkit

はじめに

This guide assumes you have a working agent toolkit setup and a Stripe account. You’ll link to these resources throughout:

  • Agent toolkit
  • Adding payments to your agentic workflows
  • Building subscriptions
  • Subscriptions
  • Webhooks
  • Testing your integration

Additionally, make sure that you have the following:

  • Node.js 14 or later and an existing agent toolkit project
  • A Stripe test account with API keys
  • Either the Stripe Agent Toolkit installed or Model Context Protocol (MCP) server configured to talk to your Stripe account

Provision customers and subscriptions

To provision customers and subscriptions, your agent needs to create a new customer and attach a subscription. Here’s an example using the Stripe Node.js SDK:

import Stripe from 'stripe'; const stripe = new Stripe(process.env.STRIPE_SECRET_KEY); // Create a customer and subscription async function createSubscription(customerInfo, priceId) { // 1. Create or fetch the customer const customer = await stripe.customers.create({ email: customerInfo.email, name: customerInfo.name, }); // 2. Create the subscription const subscription = await stripe.subscriptions.create({ customer: customer.id, items: [{ price: priceId }], expand: ['latest_invoice.payment_intent'], }); }

See Build subscriptions for pricing and trial options.

Handle billing events with webhooks

Subscriptions in your application trigger various events such as renewals, failed payments, and cancellations. Some billing events are asynchronous, and you need your agent to respond to them. For example, if a subscription cancels, have your agent follow up with the customer or make an offer to retain them.

To manage these events, use webhooks to listen for and respond to these triggers.

The code example below demonstrates how to set up an Express server that listens for Stripe webhook events, validates incoming requests, and handles specific event types such as successful payments, failed payments, and subscription cancellations. After you capture these events, call into an agent to react accordingly.

import express from 'express'; import Stripe from 'stripe'; const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { apiVersion: '2022-11-15' }); const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET; const app = express(); app.post('/webhooks', express.raw({ type: 'application/json' }), (req, res) => { let event; try { event = stripe.webhooks.constructEvent(req.body, req.headers['stripe-signature'], endpointSecret); } catch (err) { return res.status(400).send(`Webhook Error: ${err.message}`); } switch (event.type) { case 'invoice.payment_succeeded': // Handle successful payment break; case 'invoice.payment_failed': // Call agent to retry or gather information to communicate with the buyer break; case 'customer.subscription.deleted': // Clean up access break; default: // Unexpected event } res.status(200).json({ received: true }); }); app.listen(4242, () => console.log('Webhook listener running on port 4242'));

Manage billing using the agent toolkit

You can use the agent toolkit to enable AI agents to automatically initiate billing flows.

You can implement this directly in code or in an application such as Claude or an MCP server.

Here’s an example using Vercel’s AI SDK:

import { StripeAgentToolkit } from '@stripe/agent-toolkit/ai-sdk'; import { openai } from '@ai-sdk/openai'; import { generateText } from 'ai'; const stripeAgentToolkit = new StripeAgentToolkit({ secretKey: process.env.STRIPE_SECRET_KEY!, configuration: { actions: { prices: { read: true, }, customers: { create: true, }, subscriptions: { create: true, }, }, }, }); const result = await generateText({ model: openai('gpt-4o'), tools: { ...stripeAgentToolkit.getTools(), }, maxSteps: 5, prompt: 'Sign up jenny.rosen@example.com to the Premium plan', });

Here’s an example using Stripe’s MCP server with OpenAI’s Responses API:

Command Line
curl https://api.openai.com/v1/responses -i \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "gpt-5", "tools": [ { "type": "mcp", "server_label": "Stripe", "server_url": "https://mcp.stripe.com", "require_approval": "never" } ], "input": "Sign up jenny.rosen@example.com to the Premium plan" }'

To view the full actions, see Add Stripe to your agentic workflows. Learn more about how to add payments to your LLM agentic workflows.

Testing

You can test your integration using Sandboxes. This allows you to simulate payment processing and other features without affecting your live account or data.

このページはお役に立ちましたか。
はいいいえ
  • お困りのことがございましたら 、サポートにお問い合わせください。
  • 早期アクセスプログラムにご参加ください。
  • 変更ログをご覧ください。
  • ご不明な点がございましたら、お問い合わせください。
  • LLM ですか?llms.txt を読んでください。
  • Powered by Markdoc