Scripts2026年5月8日·1 分钟阅读

Stripe Agent Toolkit — Payments SDK for LLM Agents

Stripe Agent Toolkit gives LangChain, OpenAI Agents SDK, CrewAI, and Vercel AI SDK direct tool access to charges, customers, and refunds.

简介

Stripe Agent Toolkit 是 Stripe 官方开源 SDK,把 Stripe API 暴露成 LLM agent 的 tool call。Python 和 TypeScript 双版本,自带 LangChain / OpenAI Agents SDK / CrewAI / Vercel AI SDK 适配器。适合 AI 购物助手、计费聊天机器人、退款客服 agent —— 任何需要 LLM 实际动钱的场景。兼容任何接受 tools 列表的框架 —— Claude、GPT-4o、Gemini、Llama 都行。装机时间 3 分钟(npm/pip + STRIPE_SECRET_KEY)。


安装

# Python
pip install stripe-agent-toolkit

# TypeScript
npm install @stripe/agent-toolkit

LangChain(Python)

from stripe_agent_toolkit.langchain.toolkit import StripeAgentToolkit
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_tool_calling_agent

stripe_toolkit = StripeAgentToolkit(
    secret_key="sk_test_...",
    configuration={
        "actions": {
            "payment_links": {"create": True},
            "products":      {"create": True, "read": True},
            "prices":        {"create": True},
            "customers":     {"read": True},
        }
    },
)

llm = ChatOpenAI(model="gpt-4o")
agent = create_tool_calling_agent(llm, stripe_toolkit.get_tools(), prompt)
executor = AgentExecutor(agent=agent, tools=stripe_toolkit.get_tools())

executor.invoke({"input": "建一个 50 美元一次性商品「Founders T-Shirt」并返回支付链接。"})

OpenAI Agents SDK(TypeScript)

import { StripeAgentToolkit } from "@stripe/agent-toolkit/openai";
import OpenAI from "openai";

const stripe = new StripeAgentToolkit({
  secretKey: process.env.STRIPE_SECRET_KEY!,
  configuration: {
    actions: {
      paymentLinks: { create: true },
      invoices: { create: true, update: true },
    },
  },
});

const tools = stripe.getTools();
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "给 Acme Corp 开一张 5000 美元的 5 月留存费发票并发邮件。" }],
  tools,
});

动作覆盖

资源 可用动作
Customers create / read / update
Products + Prices create / read
Payment Links create
Invoices + Items create / update / finalize
Refunds create
Subscriptions read / update / cancel

受限 key

agent 永远用 Stripe 受限 key(rk_live_...),仅授权它需要的动作 —— 别用完整 secret key。在 dashboard.stripe.com/apikeys → Restricted keys 生成。


FAQ

Q: Agent Toolkit 生产环境安全吗? A: 安全 —— 底层就是 Stripe SDK,只是把动作面缩窄给 LLM 调。用受限 key、限制动作、把 agent 发起的 charge 当作用户已确认处理(高价值写操作前加 human-in-the-loop)。

Q: 支持测试模式吗? A: 支持 —— 传任意 sk_test_... key 即可。Stripe 测试模式覆盖整套 API(payment link / subscription / refund 都有),不动真钱。测试卡号:4242 4242 4242 4242。

Q: 能加自定义 Stripe 动作吗? A: 能 —— toolkit 导出基础 Tool 类。继承它、指向任意 Stripe API endpoint、注册到 toolkit。适合组织专属流程,比如自定义 metadata 写入或 Connect 平台动作。


🙏

来源与感谢

Built by Stripe. Licensed under MIT.

stripe/agent-toolkit — ⭐ 1,400+

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产