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

# Tokens

> Create and manage bearer tokens that authenticate API and CLI requests

Tokens authenticate requests to the SF Compute API. Use tokens for CI/CD (continuous integration and
delivery) pipelines, automation, and service accounts. Tokens use the `sk_live_` prefix.

## Creating a token

A token applies to your whole organization, not to a single workspace. Creating or deleting a token
requires a role with `token` permissions. See [Roles](https://docs.sfcompute.com/preview/roles.md#supported-resources-and-verbs).

```bash theme={null}
sf tokens create --name deploy
```

The CLI prints the token value (`sk_live_...`) once, at creation. Store it somewhere safe. You can't
retrieve it again.

To set an expiry, pass a duration with `--expires`.

```bash theme={null}
sf tokens create --name ci-runner --expires 90d
```

Without `--expires`, interactive runs prompt for an expiration and non-interactive runs default to
90 days. Pass `--no-expire` to create a token that never expires.

## Attaching a role

A token with no role attached cannot do anything. Attach a role at creation time with `--role`, and
pass `--workspace` to limit it to 1 workspace or `--org` to apply it organization-wide.

```bash theme={null}
sf tokens create --name ci-deploy --role training-operator --workspace production
```

`training-operator` is a custom role you create yourself. To run this as-is, attach a built-in role
like `operator`. See [Roles](https://docs.sfcompute.com/preview/roles.md).

As with other commands, `-w` and `SF_WORKSPACE` also set the workspace. `--org` overrides
`SF_WORKSPACE`, and can't be combined with `-w` or `--workspace`. With no workspace and no `--org`,
interactive runs let you pick a workspace or organization-wide, and non-interactive runs exit with
an error, so scripts pass `--workspace` or `--org`.

Pass `--role` multiple times to attach more than one role. Every role gets the same scope. Running
`sf tokens create` without `--role` shows an interactive multi-select picker over your available
roles.

To grant a role to an existing token, use `sf grants create`. See
[Grants](https://docs.sfcompute.com/preview/grants.md#token-grants).

## Listing tokens

List every token in your organization.

```bash theme={null}
sf tokens list
```

```text theme={null}
-----------------------------------------------------------
NAME    SUFFIX   CREATED         LAST USED  EXPIRES
deploy  ...FHbI  Mar 1, 12:00pm  Never      May 30, 12:00pm
admin   ...XyZ1  Feb 15, 9:00am  Never      May 16, 9:00am
```

## Deleting a token

Delete a token by name.

```bash theme={null}
sf tokens delete deploy
```

Deleting a token revokes it immediately. In-flight requests authenticated with the token fail.

## Using a token

See [Using the API](https://docs.sfcompute.com/preview/using-the-api.md) to authenticate requests with your token.
