> ## 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.

# 刷新令牌

> 用刷新令牌换取新的访问令牌。

## POST /auth/refresh

当访问令牌过期时，调用此接口获取新的访问令牌。须提供有效的刷新令牌。

<Note>
  本接口采用令牌轮换以增强安全：每次刷新都会签发新的刷新令牌，旧令牌自动作废。
</Note>

### 请求体

<ParamField body="refreshToken" type="string" required>
  登录或上次刷新时获得的刷新令牌。
</ParamField>

### 响应

<ResponseField name="success" type="boolean">
  刷新是否成功。
</ResponseField>

<ResponseField name="message" type="string">
  可读的状态说明。
</ResponseField>

<ResponseField name="tokens" type="object">
  新的鉴权令牌对象。

  <Expandable title="tokens 字段">
    <ResponseField name="accessToken" type="string">
      新的访问令牌，有效期 15 分钟。
    </ResponseField>

    <ResponseField name="refreshToken" type="string">
      新的刷新令牌（旧令牌已失效），有效期 7 天。
    </ResponseField>

    <ResponseField name="expiresIn" type="number">
      令牌过期时间（秒）（900 = 15 分钟）。
    </ResponseField>

    <ResponseField name="tokenType" type="string">
      令牌类型（始终为 "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>
