Accéder directement au contenu
Créez un compte
ou
connecter-vous
Logo de la documentation Stripe
/
Demander à l'assistant IA
Créez un compte
Connectez-vous
Démarrer
Paiements
Revenus
Plateformes et places de marché
Gestion de fonds
Ressources pour les développeurs
Aperçu
Gestion des versions
Journal des modifications
Mettre à niveau votre version de l'API
Actualiser votre version du SDK
Essentials
SDK
API
Tests
CLI Stripe
Exemples de projets
Outils
Workbench
Dashboard des développeurs
Shell Stripe
Stripe pour Visual Studio Code
Fonctionnalités
Workflows
Destinations d'événements
Alertes d'intégrité de StripeChargements de fichiers
Solutions d'IA
Boîte à outils des agents
Modèle de protocole contextuelBuild agentic AI SaaS Billing workflows
Sécurité et confidentialité
Sécurité
Robot d'exploration Web Stripebot
Confidentialité
Extensions Stripe
Créer des applications Stripe
Utiliser les applications de Stripe
Partenaires
Partner ecosystem
Certification des partenaires
AccueilRessources pour les développeurs

Remarque

Cette page n'est pas encore disponible dans cette langue. Nous faisons tout notre possible pour proposer notre documentation dans davantage de langues et nous vous fournirons la version traduite dès qu'elle sera disponible.

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

Avant de commencer

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.

Cette page vous a-t-elle été utile ?
OuiNon
  • Besoin d'aide ? Contactez le service Support.
  • Rejoignez notre programme d'accès anticipé.
  • Consultez notre log des modifications.
  • Des questions ? Contactez l'équipe commerciale.
  • LLM ? Lire llms.txt.
  • Propulsé par Markdoc