The best way to control Claude Code, Codex and more from any computer or phone

main
mdx 69 lines 2.08 KB
Raw
1 ---
2 title: Tokens
3 description: Create tokens for apps that run outside your Stack.
4 ---
5
6 Turso has two kinds of tokens. A database token lets an app run SQL. An API token lets an app create and delete databases.
7
8 Workers that use [Connect](/turso/connections) or [ManageDatabases](/turso/database-per-tenant) get their tokens for you. Create one yourself when an app outside your Stack needs access.
9
10 ## A token for one database
11
12 ```typescript
13 const token = yield* Turso.DatabaseToken("Token", { database: db.name });
14 ```
15
16 Give `db.url` and `token.token` to your app. `token.token` is `Redacted`, so it doesn't show up in logs.
17
18 ## A read-only token that expires
19
20 ```typescript
21 const token = yield* Turso.DatabaseToken("Reader", {
22 database: db.name,
23 authorization: "read-only",
24 expiration: "2w",
25 });
26 ```
27
28 When the token is about to expire, the next deploy makes a new one.
29
30 ## A token for a whole group
31
32 ```typescript
33 const token = yield* Turso.GroupToken("Token", { group: group.name });
34 ```
35
36 A group token works for every database in the group, even ones created later.
37
38 ## You can't cancel one database token
39
40 Changing a token makes a new one, but the old one keeps working until it expires. Destroying it doesn't stop it either.
41
42 So give tokens you share an `expiration`. To cancel every token for a database at once, run `turso db tokens invalidate <database>`.
43
44 ## An API token
45
46 ```typescript
47 const token = yield* Turso.ApiToken("Ci", {});
48 ```
49
50 This token can change anything in your organization. Destroying it cancels it.
51
52 ## Limit it to one group
53
54 ```typescript
55 const token = yield* Turso.ApiToken("Provisioner", {
56 group: group.name,
57 scopes: ["read", "db:create", "db:delete", "db:mint-token"],
58 });
59 ```
60
61 This token only works on databases in `group`. `read-only` and `full-access` are shortcuts for common sets of scopes.
62
63 Changing `group` or `scopes` creates a new token and cancels the old one.
64
65 ## Where next
66
67 - [Database reference](/providers/turso/reference/database#databasetoken)
68 - [Group reference](/providers/turso/reference/group#grouptoken)
69 - [API Token reference](/providers/turso/reference/api-token)