> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dari.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Sandboxes And Workers

> Give a sandbox its own short-lived token, locked to one model.

Don't hand your user's access token to a sandbox. Mint a **child token** instead:

```ts Node theme={null}
import { childToken } from "@mupt-ai/dari-gateway/link/client";

const sandbox = await childToken({
  gatewayUrl: DARI_GATEWAY_URL,
  clientId: CLIENT_ID,
  clientSecret: CLIENT_SECRET,
  refreshToken,
  models: [{ model: "gpt-5.5", thinking: "high" }],
  expiresIn: 6 * 3600,          // up to 12 hours
  tags: { run: "r1", trial: "7" },
});

// pass sandbox.accessToken (dlk_ct_…) into the sandbox
```

```python Python theme={null}
import requests

sandbox = requests.post(f"{DARI_GATEWAY_URL}/v1/link/token",
    auth=(CLIENT_ID, CLIENT_SECRET),
    data={
        "grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
        "subject_token": access_token,
        "subject_token_type": "urn:ietf:params:oauth:token-type:access_token",
        "model": "gpt-5.5",
        "thinking": "high",
        "expires_in": 6 * 3600,  # up to 12 hours
        "tags": "run=r1,trial=7",
    }).json()

# pass sandbox["access_token"] (dlk_ct_…) into the sandbox
```

```go Go theme={null}
form := url.Values{
	"grant_type":         {"urn:ietf:params:oauth:grant-type:token-exchange"},
	"subject_token":      {accessToken},
	"subject_token_type": {"urn:ietf:params:oauth:token-type:access_token"},
	"model":              {"gpt-5.5"},
	"thinking":           {"high"},
	"expires_in":         {"21600"}, // seconds, up to 12 hours
	"tags":               {"run=r1,trial=7"},
}
req, _ := http.NewRequest("POST", dariGatewayURL+"/v1/link/token",
	strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.SetBasicAuth(clientID, clientSecret)
res, err := http.DefaultClient.Do(req)
if err != nil {
	return err
}
defer res.Body.Close()
var sandbox struct {
	AccessToken string `json:"access_token"`
}
json.NewDecoder(res.Body).Decode(&sandbox)

// pass sandbox.AccessToken (dlk_ct_…) into the sandbox
```

```bash cURL theme={null}
curl -X POST $DARI_GATEWAY_URL/v1/link/token -u "$CLIENT_ID:$CLIENT_SECRET" \
  -d grant_type=urn:ietf:params:oauth:grant-type:token-exchange \
  -d subject_token=$ACCESS_TOKEN \
  -d subject_token_type=urn:ietf:params:oauth:token-type:access_token \
  -d model=gpt-5.5 -d thinking=high -d expires_in=21600 -d tags=run=r1,trial=7
```

In the Python, Go, and cURL tabs, the subject token is the user's access token. One call makes it from the refresh token you saved, and it lasts an hour: see [Refresh](https://docs.dari.dev/link/reference/http.md#refresh). The Node client makes it for you.

In the sandbox it is an ordinary API key: base URL `DARI_GATEWAY_URL/v1` for OpenAI clients, `DARI_GATEWAY_URL` for Anthropic ones. A model or thinking level the connection can't serve fails here, with `invalid_target`, before anything starts.

## What A Child Token Can Do

| Can | Can't |
| - | - |
| Call the models you listed (up to 16) | Call any other model, or `dari/routing` |
| Use the thinking level you pinned | Refresh, or mint more tokens |
| Tag its requests for usage | Read the grant or usage |

It stops working when it expires or the user disconnects.

## Network

The sandbox only needs HTTPS to your Dari gateway's host. It never talks to OpenAI, Anthropic, or your app.

## Get A Trial's Cost

```ts Node theme={null}
import { usage } from "@mupt-ai/dari-gateway/link/client";

const report = await usage({
  gatewayUrl: DARI_GATEWAY_URL,
  clientId: CLIENT_ID,
  clientSecret: CLIENT_SECRET,
  refreshToken,
  tags: { trial: "7" },
});
```

```python Python theme={null}
import requests

report = requests.get(f"{DARI_GATEWAY_URL}/v1/link/usage",
    params={"tag": "trial=7"},
    headers={"Authorization": f"Bearer {access_token}"}).json()
```

```go Go theme={null}
query := url.Values{"tag": {"trial=7"}}
endpoint := dariGatewayURL + "/v1/link/usage?" + query.Encode()
req, _ := http.NewRequest("GET", endpoint, nil)
req.Header.Set("Authorization", "Bearer "+accessToken)
report, err := http.DefaultClient.Do(req) // the body is the report, as JSON
```

```bash cURL theme={null}
curl "$DARI_GATEWAY_URL/v1/link/usage?tag=trial%3D7" -H "Authorization: Bearer $ACCESS_TOKEN"
```

See [Usage And Budgets](https://docs.dari.dev/link/usage-and-budgets.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.