Agent Toolkit
    Agent Toolkit

    Agent Toolkit

    Python and TypeScript library for integrating the Stripe API into agentic workflows

    4.3

    GitHub Stats

    Stars

    880

    Forks

    123

    Release Date

    4/22/2025

    about 2 months ago

    Detailed Description

    stripe agent toolkit

    the stripe agent toolkit enables popular agent frameworks including openai's agent sdk, langchain, crewai, vercel's ai sdk, and model context protocol (mcp) to integrate with stripe apis through function calling. the library is not exhaustive of the entire stripe api. it includes support for both python and typescript and is built directly on top of the stripe python and node sdks.

    included below are basic instructions, but refer to the python and typescript packages for more information.

    python

    installation

    you don't need this source code unless you want to modify the package. if you just want to use the package run:

    pip install stripe-agent-toolkit
    

    requirements

    • python 3.11+

    usage

    the library needs to be configured with your account's secret key which is available in your stripe dashboard.

    from stripe_agent_toolkit.openai.toolkit import stripeagenttoolkit
    
    stripe_agent_toolkit = stripeagenttoolkit(
        secret_key="sk_test_...",
        configuration={
            "actions": {
                "payment_links": {
                    "create": true,
                },
            }
        },
    )
    

    the toolkit works with openai's agent sdk, langchain, and crewai and can be passed as a list of tools. for example:

    from agents import agent
    
    stripe_agent = agent(
        name="stripe agent",
        instructions="you are an expert at integrating with stripe",
        tools=stripe_agent_toolkit.get_tools()
    )
    

    examples for openai's agent sdk,langchain, and crewai are included in /examples.

    context

    in some cases you will want to provide values that serve as defaults when making requests. currently, the account context value enables you to make api calls for your connected accounts.

    stripe_agent_toolkit = stripeagenttoolkit(
        secret_key="sk_test_...",
        configuration={
            "context": {
                "account": "acct_123"
            }
        }
    )
    

    typescript

    installation

    you don't need this source code unless you want to modify the package. if you just want to use the package run:

    npm install @stripe/agent-toolkit
    

    requirements

    • node 18+

    usage

    the library needs to be configured with your account's secret key which is available in your stripe dashboard. additionally, configuration enables you to specify the types of actions that can be taken using the toolkit.

    import { stripeagenttoolkit } from "@stripe/agent-toolkit/langchain";
    
    const stripeagenttoolkit = new stripeagenttoolkit({
      secretkey: process.env.stripe_secret_key!,
      configuration: {
        actions: {
          paymentlinks: {
            create: true,
          },
        },
      },
    });
    

    tools

    the toolkit works with langchain and vercel's ai sdk and can be passed as a list of tools. for example:

    import { agentexecutor, createstructuredchatagent } from "langchain/agents";
    
    const tools = stripeagenttoolkit.gettools();
    
    const agent = await createstructuredchatagent({
      llm,
      tools,
      prompt,
    });
    
    const agentexecutor = new agentexecutor({
      agent,
      tools,
    });
    

    context

    in some cases you will want to provide values that serve as defaults when making requests. currently, the account context value enables you to make api calls for your connected accounts.

    const stripeagenttoolkit = new stripeagenttoolkit({
      secretkey: process.env.stripe_secret_key!,
      configuration: {
        context: {
          account: "acct_123",
        },
      },
    });
    

    metered billing

    for vercel's ai sdk, you can use middleware to submit billing events for usage. all that is required is the customer id and the input/output meters to bill.

    import { stripeagenttoolkit } from "@stripe/agent-toolkit/ai-sdk";
    import { openai } from "@ai-sdk/openai";
    import {
      generatetext,
      experimental_wraplanguagemodel as wraplanguagemodel,
    } from "ai";
    
    const stripeagenttoolkit = new stripeagenttoolkit({
      secretkey: process.env.stripe_secret_key!,
      configuration: {
        actions: {
          paymentlinks: {
            create: true,
          },
        },
      },
    });
    
    const model = wraplanguagemodel({
      model: openai("gpt-4o"),
      middleware: stripeagenttoolkit.middleware({
        billing: {
          customer: "cus_123",
          meters: {
            input: "input_tokens",
            output: "output_tokens",
          },
        },
      }),
    });
    

    model context protocol

    the stripe agent toolkit also supports the model context protocol (mcp).

    to run the stripe mcp server using npx, use the following command:

    npx -y @stripe/mcp --tools=all --api-key=your_stripe_secret_key
    

    replace your_stripe_secret_key with your actual stripe secret key. or, you could set the stripe_secret_key in your environment variables.

    alternatively, you can set up your own mcp server. for example:

    import { stripeagenttoolkit } from "@stripe/agent-toolkit/modelcontextprotocol";
    import { stdioservertransport } from "@modelcontextprotocol/sdk/server/stdio.js";
    
    const server = new stripeagenttoolkit({
      secretkey: process.env.stripe_secret_key!,
      configuration: {
        actions: {
          paymentlinks: {
            create: true,
          },
          products: {
            create: true,
          },
          prices: {
            create: true,
          },
        },
      },
    });
    
    async function main() {
      const transport = new stdioservertransport();
      await server.connect(transport);
      console.error("stripe mcp server running on stdio");
    }
    
    main().catch((error) => {
      console.error("fatal error in main():", error);
      process.exit(1);
    });
    

    supported api methods

    Star History

    Star History

    Nov 14Dec 4Dec 31Jan 28Feb 25Mar 15Apr 3Apr 23May 12May 31Jul 402505007501,000
    Powered by MSeeP Analytics

    About the Project

    This app has not been claimed by its owner yet.

    Claim Ownership

    Receive Updates

    Security Updates

    Get notified about trust rating changes

    to receive email notifications.