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

# Refresh Token

> This endpoint issues a new access token in exchange for a refresh token.

## POST /auth/refresh

Use this endpoint to obtain a new access token when the old one expires. You must provide a valid refresh token.

<Note>
  This endpoint implements token rotation for enhanced security. Each time you refresh, you receive a new refresh token and the old one is automatically revoked.
</Note>

### Request Body

<ParamField body="refreshToken" type="string" required>
  The refresh token that was provided during login or a previous refresh.
</ParamField>

### Response

<ResponseField name="success" type="boolean">
  Indicates if the refresh was successful.
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable status message.
</ResponseField>

<ResponseField name="tokens" type="object">
  An object containing the new authentication tokens.

  <Expandable title="tokens properties">
    <ResponseField name="accessToken" type="string">
      A new access token for authenticating subsequent requests. Expires in 15 minutes.
    </ResponseField>

    <ResponseField name="refreshToken" type="string">
      A new refresh token (the old one is now invalidated). Expires in 7 days.
    </ResponseField>

    <ResponseField name="expiresIn" type="number">
      Token expiry time in seconds (900 = 15 minutes).
    </ResponseField>

    <ResponseField name="tokenType" type="string">
      The token type (always "Bearer").
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/auth/refresh \
    -H "Content-Type: application/json" \
    -d '{
          "refreshToken": "YOUR_REFRESH_TOKEN"
        }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/auth/refresh', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      refreshToken: 'YOUR_REFRESH_TOKEN'
    })
  });

  const data = await response.json();
  ```
</RequestExample>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "success": true,
    "message": "Token refreshed successfully",
    "tokens": {
      "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "expiresIn": 900,
      "tokenType": "Bearer"
    }
  }
  ```

  ```json Invalid Token (401) theme={null}
  {
    "message": "Invalid or expired refresh token"
  }
  ```

  ```json Revoked Token (401) theme={null}
  {
    "message": "Refresh token has been revoked"
  }
  ```
</ResponseExample>
