| 1 | --- |
| 2 | title: Setup |
| 3 | description: Connect alchemy to PlanetScale — account, credentials, and profiles. |
| 4 | --- |
| 5 | |
| 6 | Sign up at [planetscale.com](https://planetscale.com) and create a |
| 7 | [service token](https://planetscale.com/docs/concepts/service-tokens). |
| 8 | Register the provider next to your cloud's: |
| 9 | |
| 10 | ```typescript |
| 11 | // alchemy.run.ts |
| 12 | import * as Planetscale from "alchemy/Planetscale"; |
| 13 | |
| 14 | providers: Layer.mergeAll(Cloudflare.providers(), Planetscale.providers()), |
| 15 | ``` |
| 16 | |
| 17 | Run `alchemy profile edit --add Planetscale` and pick between two local options: |
| 18 | |
| 19 | - **OAuth.** Sign in through a browser. Alchemy refreshes the token automatically. |
| 20 | - **Stored service token.** Enter the token interactively. Alchemy saves it under |
| 21 | `~/.alchemy/credentials/<profile>/planetscale-stored.json`. |
| 22 | |
| 23 | When `CI=true`, profiles are bypassed. Set `PLANETSCALE_API_TOKEN_ID`, |
| 24 | `PLANETSCALE_API_TOKEN`, and `PLANETSCALE_ORGANIZATION`; Alchemy reads them |
| 25 | directly and persists nothing. |
| 26 | |
| 27 | See [Profiles](/environments/profiles) for how credentials are stored |
| 28 | and switched. |
| 29 | |
| 30 | ## Programmatic credentials |
| 31 | |
| 32 | Skip profiles entirely by building the `Credentials` layer from a token |
| 33 | you already have in hand — useful in tests: |
| 34 | |
| 35 | ```typescript |
| 36 | Effect.provide( |
| 37 | Planetscale.fromToken({ |
| 38 | tokenId: "abcd1234", |
| 39 | token: "api-token-secret", |
| 40 | organization: "my-org", |
| 41 | }), |
| 42 | ) |
| 43 | ``` |
| 44 | |
| 45 | `tokenId` and `token` accept plain strings or `Redacted` values. |
| 46 | |
| 47 | ## API base URL |
| 48 | |
| 49 | Requests go to `https://api.planetscale.com/v1` by default. Set |
| 50 | `PLANETSCALE_API_BASE_URL` to point profile-resolved credentials at a |
| 51 | different endpoint; `fromToken` takes an `apiBaseUrl` option instead. |
| 52 | |
| 53 | ## Next steps |
| 54 | |
| 55 | - [PlanetScale overview](/planetscale) — resources and compositions. |