> ## 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/login

用户通过邮箱和密码登录。鉴权成功后将返回访问令牌与刷新令牌，用于后续 API 请求。

### 请求体

<ParamField body="email" type="string" required>
  用户邮箱地址。
</ParamField>

<ParamField body="password" type="string" required>
  账户密码。
</ParamField>

### 响应

<ResponseField name="success" type="boolean">
  登录是否成功。
</ResponseField>

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

<ResponseField name="user" type="object">
  用户信息对象。

  <Expandable title="user 字段">
    <ResponseField name="id" type="string">
      用户唯一标识。
    </ResponseField>

    <ResponseField name="email" type="string">
      用户邮箱。
    </ResponseField>

    <ResponseField name="name" type="string">
      用户全名。
    </ResponseField>

    <ResponseField name="emailVerified" type="boolean">
      邮箱是否已验证。
    </ResponseField>

    <ResponseField name="updatedAt" type="string">
      最近更新时间（ISO 8601）。
    </ResponseField>
  </Expandable>
</ResponseField>

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

  <Expandable title="tokens 字段">
    <ResponseField name="accessToken" type="string">
      用于后续请求的访问令牌。在 `Authorization` 请求头中以 Bearer 方式携带。有效期 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/login \
    -H "Content-Type: application/json" \
    -d '{
          "email": "user@example.com",
          "password": "securePassword123"
        }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/auth/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      email: 'user@example.com',
      password: 'securePassword123'
    })
  });

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.llmgenerator.com/api/v1/auth/login',
      json={
          'email': 'user@example.com',
          'password': 'securePassword123'
      }
  )

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

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "success": true,
    "message": "Login successful",
    "user": {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "email": "user@example.com",
      "name": "John Doe",
      "emailVerified": true,
      "updatedAt": "2026-01-29T12:00:00.000Z"
    },
    "tokens": {
      "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "expiresIn": 900,
      "tokenType": "Bearer"
    }
  }
  ```

  ```json Invalid Credentials (401) theme={null}
  {
    "message": "Invalid email or password"
  }
  ```
</ResponseExample>
