---
title: "Stripe API: connect it to a tool built with AI (2026)"
url: https://while.sh/en/guides/connect-stripe-api-ai-tool/
author: "Aloïs Oddon, co-founder of Nextmap"
updated: 2026-11-18
---

# Connect Stripe to a tool built with Claude or ChatGPT (2026)

Your tool built with Claude needs to read Stripe's payments: failed charges to follow up, unpaid invoices, the month's revenue. The Stripe credential touches your customers' money, and it must end up neither in the code nor in the conversation. On while, it stays in while, and your AI never sees it. Here is how.

Stripe holds your payments, customers, subscriptions and invoices. A tool built with Claude or ChatGPT becomes valuable when it **reads that data**: the list of failed payments to follow up, unpaid invoices, the month's revenue by plan. To do that, it needs a **Stripe API credential**, and that credential touches your customers' money.

That is where things often go wrong: **the secret key ends up pasted into the code**, or into the conversation with the AI, where it can leak. On while, the Stripe credential **stays in while**. The tool calls Stripe without ever holding it, and your AI never sees it.

> **The short version.** Create a restricted key in Stripe, read only if the tool writes nothing. Ask your AI to connect Stripe, then paste the key into while through the link it gives you. The tool reads your payments, every call is logged, and a refund waits for your approval if you ask.

## Secret key or restricted key: which one to give

Stripe offers several kinds of keys, and only one fits a tool (sources 1 and 2).

| | Secret key | Restricted key |
|---|---|---|
| It starts with | sk_live_ or sk_test_ | rk_live_ or rk_test_ |
| What it opens | The whole account, with no restriction | Only the resources you choose |
| Permissions | Cannot be reduced | None, Read or Write, resource by resource |
| Stripe's advice | Not advised for new uses | Recommended for most uses |

A **restricted key** limits the risk to what you allowed. If the tool only reads, it cannot write anything, even with the key in hand.

## Connect Stripe to your tool, in three steps

The whole thing takes a few minutes, and you have no code to write.

1. **Create a restricted key in Stripe.** On the Dashboard's **API keys** page, click **Create restricted key**. For each resource, choose None, Read or Write, for example read access to payments, customers and invoices. Click Create key, and copy it: in live mode, Stripe shows it **only once** (sources 1 and 2).
2. **Ask your AI to connect Stripe.** It declares the connection in while and gives you a link.
3. **Paste the restricted key into while.** You open the link, paste the key and confirm. Neither your AI nor the tool's code sees it.

Start with a **test environment**, with an rk_test_ key: payments are not actually processed there (source 1). Switch to the live key once the tool is ready.

> You, to your AI: Connect Stripe to this tool, read only, and show this week's failed payments with the customer and the amount, so we can follow up.

<figure class="illus"><img src="/illustrations/stripe-relais-1200.webp" srcset="/illustrations/stripe-relais-768.webp 768w, /illustrations/stripe-relais-1200.webp 1200w" sizes="(min-width: 48rem) 46rem, 100vw" width="1536" height="1024" loading="lazy" decoding="async" alt="The tool built with AI calls the Stripe API through while: the restricted key is added to each call inside while, out of the code, every read of payments is logged and a refund waits for a person's approval" /><figcaption>The tool calls Stripe through while, which adds the credential to each call.</figcaption></figure>

## What while does on each call

The tool calls Stripe **through while**, without a credential. while adds the restricted key to each call, and logs it in the history. For the first seven days, reads go through and teach while what the tool calls. **A write**, like creating a customer or a refund, goes through once you approve its rule. After that, an unexpected call is refused, and your AI is told.

For payments, caution makes sense. You can ask for your approval before a sensitive call.

> You, to your AI: Ask me before every refund the tool makes in Stripe.

Each refund then waits for your approval in while before reaching Stripe. The credentials of your software are detailed on our [security](/en/security/) page, and the same mechanism works for any API in [connect an API with no credentials in the code](/en/guides/api-keys-out-of-code/).

## Changing the credential

Stripe lets you expire and roll a key from the API keys page, and advises changing it when someone who had access leaves the company (source 1). When it changes, **paste the new one into while**: the tool uses it from the next call, without being put back in place.

## What while adds around it

- **Your colleagues** use the tool with a while account for up to 3 people, or, on the Pro plan, with their email account, Google or Microsoft. See [keep a tool for your colleagues](/en/guides/internal-tool-company-sign-in/).
- **Connected software**: one on the Libre plan, and 25 on the Pro plan, Stripe included.
- **The tool's data** is backed up every day, and your tools are hosted in France by Nextmap.

To track incoming money, see [the cash flow forecast](/en/guides/cash-flow-forecast-small-business-ai-2026/), and for related connections, [Qonto](/en/guides/connect-qonto-api-ai-tool/) and [Pennylane](/en/guides/connect-pennylane-api-ai-tool/).

## Try it with your tool

Give this message to your AI, then ask it to connect Stripe. The trial is **free, with no sign-up**, and your tool has its address **in 3 minutes**.

```text titre="The message to give your AI"
Read while.sh/agents and help me get started with while.
```

## Sources

1. [Stripe, API keys](https://docs.stripe.com/keys), 2026-11-18
2. [Stripe, Restricted API keys](https://docs.stripe.com/keys/restricted-api-keys), 2026-11-18

## Questions

### Which Stripe key should you give a tool built with AI?

A restricted key, which starts with rk_. Stripe recommends it for most uses: you choose None, Read or Write for each resource. The secret key, sk_, opens the whole account and is not advised for new uses (sources 1 and 2).

### How do you create a restricted key in Stripe?

On the Dashboard's API keys page, click Create restricted key, choose the permissions resource by resource, then Create key. Stripe shows it only once in live mode (sources 1 and 2).

### Does my AI see the Stripe credential?

No. Your AI declares the connection to Stripe and gives you a link. You paste the restricted key into while there, and neither your AI nor the tool's code sees it.

### Can you test without touching real payments?

Yes. First create a restricted key in a test environment, which starts with rk_test_. Payments are not actually processed there (sources 1 and 2).

### Can you block a refund made by the tool?

Yes. Give the key read access only if the tool writes nothing. If it must issue refunds, ask on while for your approval before each refund: it waits for your approval before reaching Stripe.
