Weiter zum Inhalt
Konto erstellen
oder
anmelden
Das Logo der Stripe-Dokumentation
/
KI fragen
Konto erstellen
Anmelden
Jetzt starten
Zahlungen
Umsatz
Plattformen und Marktplätze
Geldmanagement
Entwicklerressourcen
Übersicht
Versionierung
Änderungsprotokoll
Aktualisieren Sie Ihre API-Version
Ihre SDK-Version aktualisieren
Essentials
SDKs
API
Tests
Stripe-CLI
Beispiel-Projekte
Tools
Workbench
Entwickler-Dashboard
Stripe Shell
Stripe für Visual Studio Code
Funktionen
Arbeitsabläufe
Ereignisziele
Stripe-StatuswarnungenHochgeladene Dateien
KI-Lösungen
Agent-Toolkit
Model Context ProtocolBuild agentic AI SaaS Billing workflows
Sicherheit und Datenschutz
Sicherheit
Stripebot-Webcrawler
Datenschutz
Extend Stripe
Erstellen Sie Stripe-Apps
Verwenden Sie Apps von Stripe
Partner
Partner-Ecosystem
Partner-Zertifizierung
StartseiteEntwicklerressourcen

Notiz

Bis jetzt ist diese Seite noch nicht in dieser Sprache verfügbar. Wir arbeiten aber verstärkt daran, unsere Dokumentation in weiteren Sprachen bereitzustellen, und werden die Übersetzung sofort anzeigen, sobald diese verfügbar ist.

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

Bevor Sie loslegen

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.

War diese Seite hilfreich?
JaNein
  • Benötigen Sie Hilfe? Kontaktieren Sie den Kundensupport.
  • Nehmen Sie an unserem Programm für frühzeitigen Zugriff teil.
  • Schauen Sie sich unser Änderungsprotokoll an.
  • Fragen? Sales-Team kontaktieren.
  • LLM? Lesen Sie llms.txt.
  • Unterstützt von Markdoc