---
title: "Login With Code"
method: POST
path: "/api/v1/auth/login"
tags: ["auth"]
---

# Login With Code

`POST /api/v1/auth/login`

## Request

- Base URL: `https://api.ticktest.cn` (the document declares no server; this is the origin it was published from)
- URL: `https://api.ticktest.cn/api/v1/auth/login`
- Auth: none declared

邮箱验证码登录 — 第二步：验证身份 → 自动判断注册/登录 → 签发 session_token。

🔴 统一入口：未注册则自动注册（name=邮箱@前部分, plan=free, 送500信用点），
已注册则直接登录。前端根据 is_new_user 字段显示不同提示。

🔴 session_token（cs_ 前缀）与 API Token（tt_ 前缀）的区别：
- session_token：邮箱登录后返回，24h 过期，用于控制台 Web UI 认证
- API Token：长期密钥，用于 AI Agent 程序化调用回测 API

🔑 与 Key 恢复的关键区别：
- Key 恢复：吊销全部旧 API Token → 签发新 API Token（安全重置，适用于忘记/泄露 Key）
- 邮箱登录：仅签发新 session_token，不创建、不吊销任何 API Token
  如邮箱未注册，先自动注册再登录

适用于控制台 Web UI 用户登录，获取会话凭证后调用控制台 API。

## Request body

- LoginRequest: 登录 — 邮箱 + 验证码
  - `email` string, required: 注册时使用的邮箱
  - `verification_code` string, required: 邮箱验证码（6位数字）

## Response `200`

Successful Response

- LoginResponse: 登录响应 — 始终返回 session_token（控制台 API 认证用）
  - `status` string, required
  - `session_token` string, nullable
  - `session_token_prefix` string, nullable
  - `session_expires_at` string, nullable
  - `user_id` string, nullable
  - `name` string, nullable
  - `credits` integer, nullable
  - `plan` string, nullable
  - `tokens` object[]
  - `is_new_user` boolean
  - `message` string, nullable

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/ticktest/apis/ticktest-api.md) · [All operations](https://skmtc.dev/ticktest/apis/ticktest-api/llms.txt) · [OpenAPI document](https://skmtc.dev/ticktest/apis/ticktest-api/revisions/3e6d69d0eb1e?raw)
