# CREATE API\_TOKEN

## Syntax <a href="#synopsis" id="synopsis"></a>

```sql
CREATE API_TOKEN api_token_name WITH (api_token_parameter = value [, ...]);;
```

## Description <a href="#description" id="description"></a>

You can use an `API_TOKEN` for automated systems to access Deltastream. Use [alter-api\_token](https://docs.deltastream.io/reference/sql-syntax/ddl/alter-api_token "mention") command to refresh an existing `API_TOKEN`.

{% hint style="warning" %}
When you use an `API_TOKEN`, it assumes all roles and privileges of the role\_name parameter.
{% endhint %}

### Arguments <a href="#parameters" id="parameters"></a>

#### api\_token\_name

This specifies the name of the new `API_TOKEN`. This name is used only for managing the API token within the organization.

### Token Parameters

| Parameter Name          | Description                                                                                                                                                                                                                                            |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| token.role\_name        | <p>Name of the role the token should use.<br></p><p><strong>Required:</strong> Yes<br><strong>Type:</strong> String<br><strong>Valid values:</strong> See list of existing roles with <a data-mention href="../command/list-roles">list-roles</a>.</p> |
| token.expires\_in\_days | <p>Number of days until the token expires.<br><br><strong>Required:</strong> No<br><strong>Type:</strong> Integer<br><strong>Default:</strong> 90</p>                                                                                                  |

## Examples <a href="#example" id="example"></a>

#### Create a new API\_TOKEN

The following creates an `API_TOKEN` named `my_token`.

```sh
<no-db>/<no-store># CREATE API_TOKEN my_token WITH ( 'token.role_name' = sysadmin );
+------------+------------+------------+------------------------------------------+------------------------+
|  Type      |  Name      |  Command   |  Summary                                 |  Token                 |
+============+============+============+==========================================+========================+
| api_token  | my_token   | CREATE     | api_token my_token was successfully      | <api_token_redacted>   |
+------------+------------+------------+------------------------------------------+------------------------+
```

#### Use an API\_TOKEN with cli

```sh
$ /deltastream-cli -a [my-access-token]
mydb.public/prod# 
```

#### Use an API\_TOKEN with cli - env property

```bash
$ DS_TOKEN=[my-access-token]
$ /deltastream-cli
mydb.public/prod# 
```
