The best way to control Claude Code, Codex and more from any computer or phone
| 1 | --- |
| 2 | title: Setup |
| 3 | description: Connect alchemy to Stripe — secret key, profiles, CI, and how Worker bindings get their credentials. |
| 4 | --- |
| 5 | |
| 6 | import PackageManagers from "../../../components/PackageManagers.astro"; |
| 7 | |
| 8 | ## Get a key |
| 9 | |
| 10 | Sign up at [stripe.com](https://stripe.com). Every account has a |
| 11 | **test mode** with its own keys and data — use that for everything |
| 12 | until you're ready to charge real cards. Copy the test secret key |
| 13 | (`sk_test_…`) from |
| 14 | [Developers → API keys](https://dashboard.stripe.com/test/apikeys). |
| 15 | |
| 16 | ## Register the provider |
| 17 | |
| 18 | Install `@alchemy.run/stripe`: |
| 19 | |
| 20 | <PackageManagers add="@alchemy.run/stripe" /> |
| 21 | |
| 22 | Then add its providers to the stack: |
| 23 | |
| 24 | ```typescript |
| 25 | // alchemy.run.ts |
| 26 | import * as Alchemy from "alchemy"; |
| 27 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 28 | import * as Stripe from "@alchemy.run/stripe"; |
| 29 | import * as Effect from "effect/Effect"; |
| 30 | import * as Layer from "effect/Layer"; |
| 31 | |
| 32 | export default Alchemy.Stack( |
| 33 | "MyApp", |
| 34 | { |
| 35 | providers: Layer.mergeAll(Cloudflare.providers(), Stripe.providers()), |
| 36 | state: Alchemy.localState(), |
| 37 | }, |
| 38 | Effect.gen(function* () { |
| 39 | // resources go here |
| 40 | }), |
| 41 | ); |
| 42 | ``` |
| 43 | |
| 44 | ## Store the key |
| 45 | |
| 46 | The first `alchemy deploy` that touches a Stripe resource prompts for |
| 47 | the key and saves it under `~/.alchemy/credentials/<profile>/`. To set |
| 48 | it up ahead of time, or to add Stripe to an existing profile: |
| 49 | |
| 50 | ```sh |
| 51 | alchemy profile edit --add Stripe |
| 52 | ``` |
| 53 | |
| 54 | An optional API base URL overrides `https://api.stripe.com` (useful for |
| 55 | [stripe-mock](https://github.com/stripe/stripe-mock)). |
| 56 | |
| 57 | In CI (`CI=true`) profiles are bypassed and alchemy reads |
| 58 | `STRIPE_API_KEY` from the environment. `STRIPE_API_BASE_URL` is |
| 59 | optional. |
| 60 | |
| 61 | See [Profiles](/environments/profiles) for switching between accounts |
| 62 | and stages. |
| 63 | |
| 64 | ## Test mode is real |
| 65 | |
| 66 | A `sk_test_…` key talks to a fully working Stripe account. Products, |
| 67 | Prices, Customers, Checkout Sessions, and webhook deliveries all |
| 68 | behave exactly as in live mode; the only difference is that cards |
| 69 | like `4242 4242 4242 4242` succeed and no money moves. Deploy, destroy, |
| 70 | and redeploy freely. |
| 71 | |
| 72 | ## How Workers get credentials |
| 73 | |
| 74 | A Worker that calls Stripe at runtime needs a key on the host. You |
| 75 | never wire that up by hand. Each binding you yield — |
| 76 | `Stripe.CreateCustomer()`, `Stripe.CreateCheckoutSession()`, and so |
| 77 | on — declares the permission it needs (`customers_write`, |
| 78 | `checkout_sessions_write`, …) on a |
| 79 | [`RestrictedApiKey`](/providers/stripe/restrictedapikey) resource |
| 80 | that alchemy creates per Worker. The key's value is injected as a |
| 81 | `secret_text` binding. |
| 82 | |
| 83 | Today Stripe has no public API for minting restricted keys, so the |
| 84 | value alchemy injects is your account secret key. The permissions are |
| 85 | still recorded on the resource, which means: |
| 86 | |
| 87 | - you can see exactly which Stripe scopes each Worker uses in the plan |
| 88 | output, and |
| 89 | - if you'd rather the Worker hold a narrower key, create one in |
| 90 | [Dashboard → API keys → Restricted keys](https://dashboard.stripe.com/test/apikeys) |
| 91 | with those scopes and pass it as `value` — bindings will use it |
| 92 | unchanged. |
| 93 | |
| 94 | When Stripe ships a mint API the same declarations will drive it with |
| 95 | no code change in your Worker. |
| 96 | |
| 97 | ## Enable Connect (platforms only) |
| 98 | |
| 99 | If you're going to create connected accounts, Connect must be switched |
| 100 | on once at |
| 101 | [dashboard.stripe.com/connect](https://dashboard.stripe.com/test/connect). |
| 102 | There's no API for that step; `POST /v1/accounts` returns an error |
| 103 | until it's done. |
| 104 | |
| 105 | ## Next |
| 106 | |
| 107 | - [Sell a subscription](/stripe/guides/subscriptions) |
| 108 | - [Onboard merchants with Connect](/stripe/guides/connect) |