> For the complete documentation index, see [llms.txt](https://docs.tonic.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tonic.ai/textual/tonic-textual-api/jwt-for-authentication.md).

# Obtaining JWT tokens for authentication

Instead of an API key, you can use the Textual API to obtain a JSON Web Token (JWT) to use for authentication.

## Configuring the JWT and refresh token lifetimes <a href="#jwt-env-variables" id="jwt-env-variables"></a>

### JWT lifetime

By default, a JWT is valid for 30 minutes.

On a self-hosted instance, to configure a different lifetime, set the [environment variable ](/textual/textual-install-administer/configuring-textual/textual-env-var-configure.md)`SOLAR_JWT_EXPIRATION_IN_MINUTES`.

### Refresh token lifetime

You use a refresh token to obtain a new JWT. By default, a refresh token is valid for 10,000 minutes, which is roughly equivalent to 7 days.

On a self-hosted instance, to configure a different lifetime, set the environment variable `SOLAR_REFRESH_TOKEN_EXPIRATION_IN_MINUTES.`

## Obtaining your first JWT and refresh token <a href="#obtain-first-jwt-and-token" id="obtain-first-jwt-and-token"></a>

To obtain your first JWT and refresh token, you make a login request to the Textual API. Before you can make this call, you must have a Textual account.

To make the call, perform a `POST` operation against:

```
<Textual_URL>/api/auth/login
```

The request payload is:

```
{"userName": "<Textual username>",
"password": "<Textual password>"}
```

For example:

```
{"userName": "jdoe@company.com",
"password": "MyPassword123!"}
```

In the response:

* The `jwt` property contains the JWT.
* The `refreshToken` property contains the refresh token.

## Obtaining a new JWT and refresh token <a href="#obtain-first-jwt-and-token" id="obtain-first-jwt-and-token"></a>

You use the refresh token to obtain both a new JWT and a new refresh token.

To obtain the new JWT and token, perform a POST operation against:

```
<TEXTUAL_URL>/api/auth/token_refresh
```

The request payload is:

```
{"refreshToken": "<refresh token>"}
```

In the response:

* The `jwt` property contains the new JWT.
* The `refreshToken` property contains the new refresh token.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tonic.ai/textual/tonic-textual-api/jwt-for-authentication.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
