Content

How to Connect Stripe to an AI Agent Without Double Refunds

An agent can call Stripe through an execution layer. The model names the action. The runtime holds the key, picks sandbox or production, and retries a write only with the same idempotency key.

IntegrationsOct 16, 2026

Key takeaways

  • -Stripe access for an agent is a list of methods you turn on, never a secret key sitting in the prompt.
  • -Find the current Stripe method with swy discover, scoped to the Stripe project. Don't hardcode a method name from memory, since catalog IDs change.
  • -Stripe amounts are in the smallest currency unit. Read the schema for that method instead of guessing the conversion.
  • -A retried Stripe write without the same idempotency key is a second charge or a second refund, whatever agent framework or chat client is driving the call.
  • -Sandbox or production is set once with swy init and stored in .swytchcode/tooling.json. The model never chooses the mode.

Payments are a bad place for an agent to improvise. A wrong method, a wrong amount, or a retry that Stripe treats as a new request shows up on a bank statement, not in a log you can quietly fix.

Swytchcode is the execution kernel that sits between the agent and Stripe, whatever is driving the agent: a coding assistant, a custom LangGraph or CrewAI build, or any MCP client. The model decides what it wants. The runtime checks the allow list, validates the input, evaluates policy, attaches the credential, sends the request, and returns a result. Requests go straight from your machine to Stripe, and the key never enters the model's context. The same stages are covered in more depth in AI agent execution layer architecture. If your agent happens to be Claude Code specifically, How to Connect Stripe to Claude Code walks through that one setup in more detail.

Start from the job, not a remembered method

swy get stripe downloads the integration, and from there you add only the methods this particular agent may call. swy discover prints the current name for whatever job you describe, and that's the name worth using. Catalog IDs change over time, so a method name copied from an old note isn't really a permission anymore, just a guess. swy info on whatever discover printed gives you the schema: which fields exist and what they actually mean. swy auth connect stripe stores the credential separately. The agent names the tool it wants; the runtime is the one that attaches the key.

There's no single “refund” in the sense a reviewer could just approve once. Stripe exposes several different writes, and they genuinely don't do the same thing to a customer's money. The reviewable answer is always the specific list of methods you added. Anything outside that list stops before a request is ever sent.

Amounts, policy, and the retry

Stripe takes amounts in the smallest unit of the currency. A support message that says “refund 500” and a model that just copies 500 straight into the field won't do what the person meant, in either direction. Read the field with swy info rather than leaving the unit conversion as an assumption buried in the prompt.

Policy is separate from the allow list. The allow list decides what can run at all; policy decides whether this particular call should run right now. A rule can allow, deny, or hold the call, and it can read the arguments to make that decision, not just the method name. Policy runs before the credential is ever injected. Approval workflows, available on Business and Enterprise, hold the call for Slack or Telegram, and if nobody approves within 48 hours, the call simply never runs. Policy-as-Code for AI Agents covers how to write those rules.

Agent stacks retry failed calls as a matter of course, and a write that timed out has often already succeeded at Stripe's end. If the retry goes out as a brand-new request, the customer gets refunded or charged twice. Retries back off on rate limits, and a POST or PATCH is only retried when an idempotency key is set, with the runtime holding onto that same key across attempts. The response is checked on the way back too, including the case where a 200 hides a body that actually says the refund failed. See How Swytchcode Retries Failed API Calls and Idempotency Explained for the mechanics.

Test it before you trust it: run one write in sandbox, drop the response on purpose, and run the same call again. Getting back the same result both times is the pass.

Test keys and live keys

Sandbox or production is the project's mode, set once with swy init and stored in tooling.json. It isn’t an environment variable you pass around. Initialize with --mode=sandbox until you genuinely mean to go live, and keep in mind the model itself never gets to choose the mode.

The network log shows what actually ran. The policy log shows what was refused or held, with sensitive values redacted and everything kept local. Exit codes are covered in “swy exec” Explained, and why the key stays out of the model entirely is credential brokering.

Stripe's API is how money actually moves for a business: charges, refunds, and payouts, all through the same kind of authenticated call. The risk for an agent isn't that Stripe is complicated, it's that a wrong amount unit or a retried write turns into a second charge or a second refund on a real bank statement, not a line in a log you can quietly correct. Swytchcode solves that by only allowing the specific Stripe methods a task needs, reading the amount against the real schema instead of guessing the unit, and retrying a timed-out write with the same idempotency key so a retry can't become a duplicate.

FAQ

How do I connect Stripe to an AI agent?

Download the integration, discover the method you actually need, add it, and connect the credential outside the prompt entirely. The agent calls exec; it never receives the secret itself.

Why did the amount come out wrong?

The API wants the smallest currency unit, and the model likely copied a human-readable figure, or converted a figure that was already in that unit a second time. Read the schema for the exact method you added rather than guessing.

How do I stop duplicate refunds?

Retry the exact same call so the idempotency key gets reused. A genuinely new request is a genuinely new refund, no matter how quickly it follows the first one.

Can the agent see the Stripe key?

Not when the runtime is the one attaching it. If the key ends up in the prompt, or in a file the model happens to read, then yes, and that's worth fixing immediately.

How do I stay on test mode?

Initialize in sandbox, and the runtime will use the sandbox endpoint automatically. Don't put both the test and live keys in the chat just to be safe, either, since that defeats the point entirely.

Can I build an AI agent on top of Stripe with Swytchcode?

Yes. swy get stripe downloads the integration, swy discover finds the exact method for the job, and swy add method turns on only that one. The agent calls exec; it never holds the API key or chooses which Stripe action is available.

Can Swytchcode stop an agent from issuing a refund, even if it's asked to?

Yes, in two ways. If the refund method was never added to the allow list, the call stops before it's ever sent. If it was added, a policy rule can still deny it outright or hold it for approval in Slack or Telegram, and if nobody approves within 48 hours it never runs.

If an agent retries a Stripe call after a timeout, will Swytchcode let it duplicate a refund?

No, as long as the retry reuses the same idempotency key, which the runtime holds onto across attempts. Stripe treats that as the same request and returns the same result instead of processing a second refund. A genuinely new request, with a new key, is a genuinely new refund.

More content