Stripe Agent Toolkit

0.7.0 · active · verified Thu Apr 16

The Stripe Agent Toolkit is a Python library (current version 0.7.0) enabling popular agent frameworks like OpenAI's Agent SDK, LangChain, and CrewAI to integrate with Stripe APIs through function calling. It's built directly on top of the Stripe Python SDK, providing a subset of Stripe's API functionality to facilitate agentic workflows for payments, billing, and more. The library is actively maintained, with updates following the Stripe API's monthly minor releases and twice-yearly major releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `stripe-agent-toolkit` with your Stripe secret key and configure its available actions. It emphasizes the use of Restricted API Keys (rk_*) for enhanced security and outlines how to retrieve the tools that an AI agent can then utilize. The example includes a basic setup, indicating where an agent framework would integrate with the toolkit's provided tools, and strongly recommends setting the Stripe API key via environment variables.

import asyncio
import os
from stripe_agent_toolkit.openai.toolkit import create_stripe_agent_toolkit

async def main():
    # It is strongly recommended to use a Restricted API Key (rk_*) for better security.
    # Store your secret key securely, e.g., in an environment variable.
    stripe_secret_key = os.environ.get('STRIPE_SECRET_KEY', 'sk_test_YOUR_TEST_KEY')

    if not stripe_secret_key or stripe_secret_key == 'sk_test_YOUR_TEST_KEY':
        print("Warning: Please set the STRIPE_SECRET_KEY environment variable ",
              "or replace 'sk_test_YOUR_TEST_KEY' with a real (test) key.")
        return

    # Initialize the toolkit with your secret key and specify allowed actions.
    # Tool availability is determined by permissions on the restricted key.
    toolkit = await create_stripe_agent_toolkit(
        secret_key=stripe_secret_key,
        configuration={
            "actions": {
                "payment_links": {
                    "create": True
                }
            }
        }
    )

    try:
        tools = toolkit.get_tools()
        print(f"Available Stripe Agent Tools: {[tool.name for tool in tools]}")

        # Example: Integrate with an agent framework (e.g., OpenAI's Agent SDK or LangChain)
        # This part assumes an agent framework is set up to consume these tools.
        # For a full agent example, refer to the Stripe Agent Toolkit documentation.

        # In a real agent workflow, the agent would call these tools based on user prompts.
        # For demonstration, let's pretend to call a tool.
        if 'create_payment_link' in [tool.name for tool in tools]:
            print("\n'create_payment_link' tool is available. Your agent can now create payment links.")
            # Example of how an agent might use a tool (simplified representation):
            # agent_response = await agent.run("Create a payment link for a product 'Premium Widget' for $25.00.")
            # print(agent_response)

    finally:
        # Clean up resources when done.
        await toolkit.close()

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →