# 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](/reference/sql-syntax/ddl/alter-api_token.md) 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="/pages/VqwCIosvUQkC2nR6FFJD">/pages/VqwCIosvUQkC2nR6FFJD</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# 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.deltastream.io/reference/sql-syntax/ddl/create-api_token.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
