# Grants

Mint a short-lived token for one VM's API, scope it to methods, paths and arguments, use it, and rotate every grant at once.

Source: https://slashinfra.com/docs/platform/grants
Last modified: 2026-11-30T16:36:19.000Z

A grant is a short-lived token for one VM’s API. Give it to a person or a program instead of your key; it admits only the methods, paths and arguments you name, and anyone who holds it can use that scope until it expires.

The samples use a new VM named `shared`; [VMs](https://slashinfra.com/docs/platform/vms) shows how to create one. A grant reaches the VM’s [files](https://slashinfra.com/docs/platform/files) and [commands](https://slashinfra.com/docs/platform/commands-and-jobs).

## Create a grant

The create request returns a link that carries the token. The API keeps no record of a grant, so save the link when it is returned; there is no list of grants.

This grant admits `GET` under `/home/user/` for one hour. The path is a glob: `/home/user/**` covers the folder and every file beneath it.

### CLI

```bash
si svm grant create shared --method GET --path '/home/user/**' --ttl 1h
```

Output

```text
https://6f1c0f0e8a.slashinfra.dev/?si_access=eyJ...
```

### curl

```bash
curl -sS -X POST "https://api.slashinfra.com/svms/shared/grants" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d '{"methods":["GET"],"paths":["/home/user/**"],"ttl_s":3600}'
```

Output

```text
{"url":"https://6f1c0f0e8a.slashinfra.dev/?si_access=eyJ...","expires_at":1795963173000,"generation":0}
```

### Python

```python
import os, requests

res = requests.post(
"https://api.slashinfra.com/svms/shared/grants",
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
json={"methods": ["GET"], "paths": ["/home/user/**"], "ttl_s": 3600},
)
res.raise_for_status()
print(res.json()["url"])
```

Output

```text
https://6f1c0f0e8a.slashinfra.dev/?si_access=eyJ...
```

### TypeScript

```ts
const res = await fetch('https://api.slashinfra.com/svms/shared/grants', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SI_API_KEY!}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ methods: ['GET'], paths: ['/home/user/**'], ttl_s: 3600 }),
})
if (!res.ok) throw new Error(await res.text())
const grant = (await res.json()) as { url: string }
console.log(grant.url)
```

Output

```text
https://6f1c0f0e8a.slashinfra.dev/?si_access=eyJ...
```

The link points at `/` on the VM’s host. Add the path of the file you want after the host, and keep `?si_access=`, or send the token in a header. A scope that does not include `/` refuses the bare link with 403 `forbidden`.

The reply gives the expiry in `expires_at`, in milliseconds since the Unix epoch, and the `generation` that the grant is bound to.

To pin the arguments of a run, repeat `--arg` for each exact value. A grant for [`POST /bin/bash`](https://slashinfra.com/docs/api-reference/svm#runProgram) with `--arg -c --arg 'make test'` runs only that command.

## Use a grant

The token is the part after `si_access=` in the link. Send it in `Authorization` or `X-Si-Authorization` as a bearer token, or in `?si_access=`. A key starts with `si_` and a grant token does not, so the gate tells them apart. A header keeps the token out of the URL, so it does not land in browser history or a screenshot.

A grant works only on the VM’s own host, not on the control API.

Set `VM` and `GRANT` once. Use the VM’s id and the token after `si_access=` in the link.

```bash
export VM=6f1c0f0e8a
export GRANT=eyJ...
```

The examples read `/home/user/.profile`, a file every VM starts with. The guest resolves the path beneath the scope root, so a symlink cannot leave the folder you named.

### curl

```bash
curl -sS "https://$VM.slashinfra.dev/home/user/.profile" \
-H "Authorization: Bearer $GRANT"
```

Output

```text
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

...
```

### Python

```python
import os, requests

res = requests.get(
f"https://{os.environ['VM']}.slashinfra.dev/home/user/.profile",
headers={"Authorization": f"Bearer {os.environ['GRANT']}"},
)
res.raise_for_status()
print(res.text, end="")
```

Output

```text
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

...
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/home/user/.profile`, {
headers: { Authorization: `Bearer ${process.env.GRANT!}` },
})
if (!res.ok) throw new Error(await res.text())
process.stdout.write(await res.text())
```

Output

```text
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

...
```

## What a refused grant answers

| Answer | When |
| --- | --- |   
| 401 `unauthorized` | The grant is malformed, expired, for another VM, or was minted before the last rotation. | 
| 403 `forbidden` | The grant is valid, but the method, path or `arg` list is outside its scope. |

The gate answers both before the request reaches the VM, so neither wakes it. A request the grant admits does reach the VM and can wake it.

The samples send a `PUT` with the token in the query. The grant admits only `GET`, so the gate refuses it.

### curl

```bash
curl -sS -i -X PUT "https://$VM.slashinfra.dev/home/user/notes.txt?si_access=$GRANT" \
--data-binary 'hello'
```

Output

```text
HTTP/2 403
...
x-si-error: forbidden
...
This request is not allowed. (forbidden)
```

### Python

```python
import os, requests

res = requests.put(
f"https://{os.environ['VM']}.slashinfra.dev/home/user/notes.txt",
params={"si_access": os.environ["GRANT"]},
data=b"hello",
)
print(res.status_code, res.headers["X-Si-Error"])
```

Output

```text
403 forbidden
```

### TypeScript

```ts
const url = new URL(`https://${process.env.VM!}.slashinfra.dev/home/user/notes.txt`)
url.searchParams.set('si_access', process.env.GRANT!)
const res = await fetch(url, { method: 'PUT', body: 'hello' })
console.log(res.status, res.headers.get('X-Si-Error'))
```

Output

```text
403 forbidden
```

## Rotate the grants of a VM

Rotate ends every grant the VM has issued at once. You cannot revoke one grant alone. The gate applies the new generation within 30 seconds; until then, an older grant can still work. Port links have their own generation and keep working.

### CLI

```bash
si svm grant rotate shared
```

Output

```text
rotated every SVM API grant of SVM "shared"
```

### curl

```bash
curl -sS -X POST "https://api.slashinfra.com/svms/shared/grants/rotate" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
{"generation":1}
```

### Python

```python
import os, requests

res = requests.post(
"https://api.slashinfra.com/svms/shared/grants/rotate",
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.json()["generation"])
```

Output

```text
1
```

### TypeScript

```ts
const res = await fetch('https://api.slashinfra.com/svms/shared/grants/rotate', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
const rotated = (await res.json()) as { generation: number }
console.log(rotated.generation)
```

Output

```text
1
```

The gate applies a rotation within 30 seconds; after that, the grant from Create a grant answers 401 `unauthorized`.

### curl

```bash
curl -sS -i "https://$VM.slashinfra.dev/home/user/.profile" \
-H "Authorization: Bearer $GRANT"
```

Output

```text
HTTP/2 401
...
x-si-error: unauthorized
...
Sign in or send a valid API key. (unauthorized)
```

### Python

```python
import os, requests

res = requests.get(
f"https://{os.environ['VM']}.slashinfra.dev/home/user/.profile",
headers={"Authorization": f"Bearer {os.environ['GRANT']}"},
)
print(res.status_code, res.headers["X-Si-Error"])
```

Output

```text
401 unauthorized
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/home/user/.profile`, {
headers: { Authorization: `Bearer ${process.env.GRANT!}` },
})
console.log(res.status, res.headers.get('X-Si-Error'))
```

Output

```text
401 unauthorized
```

## Options

| Field | Type | Default | Allowed values | What it changes |
| --- | --- | --- | --- | --- |   
| `methods` (`--method`) | array of strings | Required | 1 to 16 uppercase methods; the CLI accepts `GET`, `HEAD`, `POST`, `PUT`, `PATCH` and `DELETE` | The methods a request may use. Another method answers 403 `forbidden`. | 
| `paths` (`--path`) | array of strings | Required | 1 to 32 absolute path globs; `*` stays in one segment and `**` crosses segments | The paths a request may reach. Another path answers 403 `forbidden`. | 
| `args` (`--arg`) | array of strings | Open | 0 to 64 exact values, matched in order | The `arg` values a request must carry. Omitting it leaves every argument list open; an empty list admits only a request with no arguments. | 
| `ttl_s` (`--ttl`) | number | `3600` | Whole seconds from 1 to 30 days; `--ttl` also accepts a number with `s`, `m`, `h` or `d` | The life of the grant. A longer life answers 400 `invalid_ttl`. | 
| `ref` (path) | string | Required | The VM’s name or its id | The VM whose API the grant reaches. | 
| `project` (`--project`) | string | `default` | A project name, or its `proj_` id | The project that holds the VM. |

## Errors

| Code | When | Fix |
| --- | --- | --- |   
| [`invalid_scope`](https://slashinfra.com/docs/reference/errors#invalid_scope) | Create sends an empty method or path list, a list over the cap, a method that is not uppercase, or a path that is not absolute or has a `.` or `..` segment. | Send 1 to 16 uppercase methods and 1 to 32 absolute globs. | 
| [`invalid_ttl`](https://slashinfra.com/docs/reference/errors#invalid_ttl) | Create sends a lifetime that is not a whole number of seconds from 1 to the plan’s maximum. | Send whole seconds from 1 to 30 days, or omit it for 3600. | 
| [`svm_not_found`](https://slashinfra.com/docs/reference/errors#svm_not_found) | The ref names no VM in the project. | Check the VM name or id, and the project. | 
| [`project_not_found`](https://slashinfra.com/docs/reference/errors#project_not_found) | The `project` value names no project of the organization or key scope. | Check the project name or id. | 
| [`deleting`](https://slashinfra.com/docs/reference/errors#deleting) | The VM is being deleted. | Wait for the delete to finish, or create another VM. |

Errors that any request can return are in the [error catalog](https://slashinfra.com/docs/reference/errors).

## Permissions

| Operation | Who can | Key action |
| --- | --- | --- |   
| Create a grant | Any member | `svm:write` | 
| Use a grant | Anyone who holds the link | None | 
| Rotate the grants of a VM | Any member | `svm:write` |

## Limits

- A grant names 1 to 16 methods and 1 to 32 path globs. A list outside that range answers 400 `invalid_scope`. 
- A grant pins 0 to 64 arguments. Omitting `args` leaves every argument list open. 
- A method, path or argument has 1 to 4096 characters. A path glob is absolute and has no `.` or `..` segment. 
- A grant lives 1 second to 30 days; the default is 3600 seconds. 
- A rotation ends every grant of the VM at once and the gate applies it within 30 seconds. Port links keep their own generation. 
- A token is bound to one VM and one generation. A token for another VM, another generation, or a past expiry answers 401 `unauthorized`.

The full list is in [Limits](https://slashinfra.com/docs/reference/limits).

## Next

- [Who can reach your VM](https://slashinfra.com/docs/how/access): grants beside roles, keys and port links. 
- [Web addresses](https://slashinfra.com/docs/platform/web-addresses): port links keep their own generation when you rotate grants. 
- [Control API grants](https://slashinfra.com/docs/api-reference/control/grants): every operation, field and status code.
