{
  "openapi": "3.1.0",
  "info": {
    "title": "全自动接码客户 API",
    "version": "2026-11-11",
    "description": "使用 AUTO CDK 会话提交异步任务，按 result.status 判断任务结果。短信接码按到码扣次，自动授权按成功扣次，实际扣次以 chargedTimes 为准。账号资料仅用于自动登录和授权，必要时加密提交给接入的授权服务。提交及重试使用同一 clientRequestId，避免重复执行。"
  },
  "servers": [
    {
      "url": "https://autosms.xiaoliai.shop",
      "description": "客户 HTTPS 入口"
    }
  ],
  "tags": [
    {
      "name": "CDK",
      "description": "兑换与会话"
    },
    {
      "name": "自动接码",
      "description": "单账号异步任务与结果"
    }
  ],
  "security": [
    {
      "CdkSession": []
    }
  ],
  "paths": {
    "/api/public/auto/config": {
      "get": {
        "tags": [
          "自动接码"
        ],
        "operationId": "getAutoConfig",
        "summary": "查询功能配置",
        "security": [],
        "responses": {
          "200": {
            "description": "配置，不保证当前有空闲槽或库存",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Envelope"
                    },
                    {
                      "properties": {
                        "result": {
                          "type": "object",
                          "required": [
                            "enabled",
                            "retentionHours",
                            "requestIdempotency"
                          ],
                          "properties": {
                            "enabled": {
                              "type": "boolean"
                            },
                            "retentionHours": {
                              "type": "integer",
                              "minimum": 1
                            },
                            "requestIdempotency": {
                              "type": "boolean"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/public/cdk/redeem": {
      "post": {
        "tags": [
          "CDK"
        ],
        "operationId": "redeemCdk",
        "summary": "兑换 CDK 取得会话令牌",
        "security": [],
        "description": "同一 IP 10 分钟最多 10 次。兑换不扣次。检查响应 tier 为 AUTO；耗尽 CDK 不能再次兑换。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "cdk"
                ],
                "properties": {
                  "cdk": {
                    "type": "string",
                    "description": "有效 CDK，支持大小写和短横线归一化",
                    "example": "DEMO-DEMO-DEMO-DEMO"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "CDK 会话，当前默认 30 天有效，以 expiresAt 为准",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Envelope"
                    },
                    {
                      "properties": {
                        "result": {
                          "allOf": [
                            {
                              "$ref": "#/components/schemas/CdkInfo"
                            },
                            {
                              "type": "object",
                              "required": [
                                "accessToken",
                                "expiresAt"
                              ],
                              "properties": {
                                "accessToken": {
                                  "type": "string",
                                  "description": "本站 CDK 会话令牌，非 OpenAI AT"
                                },
                                "expiresAt": {
                                  "type": "string",
                                  "format": "date-time"
                                }
                              }
                            }
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/public/cdk/session": {
      "get": {
        "tags": [
          "CDK"
        ],
        "operationId": "getCdkSession",
        "summary": "查询会话与 CDK 余额",
        "responses": {
          "200": {
            "description": "当前 CDK 状态，不重复返回令牌和过期时间",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Envelope"
                    },
                    {
                      "properties": {
                        "result": {
                          "$ref": "#/components/schemas/CdkInfo"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/public/auto/jobs": {
      "get": {
        "tags": [
          "自动接码"
        ],
        "operationId": "listAutoJobs",
        "summary": "查询当前 CDK 的任务列表",
        "description": "返回当前 CDK 最近提交的 100 个任务，按提交时间倒序排列。用于多任务前端在刷新后恢复每个 jobId 的状态、停止操作和 CPA 下载入口。没有任务时 result 为空数组。响应禁止缓存。",
        "responses": {
          "200": {
            "description": "任务对象数组",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Envelope"
                    },
                    {
                      "properties": {
                        "result": {
                          "type": "array",
                          "maxItems": 100,
                          "items": {
                            "$ref": "#/components/schemas/AutoJob"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "tags": [
          "自动接码"
        ],
        "operationId": "submitAutoJob",
        "summary": "提交一个账号的全自动任务",
        "description": "仅支持 AUTO CDK。account 支持邮箱----密码----Base32 2FA 密钥，以及追加 ----取码链接的四段格式。仅在登录要求邮箱验证码时取码。每个请求一个账号，account 最长 4096 字符，请求体最多 16 KiB；同一 CDK 10 分钟最多 6 次提交。使用同一 clientRequestId 重放请求以核对原任务。HTTP 200 表示受理，后台自动登录、等待号码和获取 CPA；缺少并发槽返回 429，CDK 可用次数不足返回 409。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "account"
                ],
                "properties": {
                  "account": {
                    "type": "string",
                    "maxLength": 4096,
                    "description": "支持邮箱----密码----2FA密钥或邮箱----密码----2FA密钥----取码链接。2FA 为有效 Base32 密钥而非六位验证码；取码链接为 HTTP/HTTPS 公网地址，只在邮箱验证码页使用且仅存当前任务内存。示例中的尖括号部分需要替换。",
                    "example": "demo@example.com----<PASSWORD>----<BASE32_2FA_SECRET>"
                  },
                  "clientRequestId": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{16,128}$",
                    "description": "建议使用随机请求编号；同一 CDK 下网络重试复用原编号，主动新建任务使用新编号。相同编号绑定其他账号返回 409。"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Job"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/public/auto/jobs/by-request/{clientRequestId}": {
      "get": {
        "tags": [
          "自动接码"
        ],
        "operationId": "getAutoJobByRequest",
        "summary": "按提交编号核对原任务",
        "description": "只查询当前 CDK；返回任务或 null。只有 HTTP 200/result=null 表示此时未发现受理记录，可按原编号重放 POST。查询错误不代表未受理，必须继续查询。",
        "parameters": [
          {
            "name": "clientRequestId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "原任务或 null",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Envelope"
                    },
                    {
                      "properties": {
                        "result": {
                          "oneOf": [
                            {
                              "$ref": "#/components/schemas/AutoJob"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/public/auto/jobs/current": {
      "get": {
        "tags": [
          "自动接码"
        ],
        "operationId": "getLatestAutoJob",
        "summary": "查询此 CDK 最近一次任务",
        "description": "最近任务可为运行中或终态，无任务时 result 为 null。此接口不是历史列表；后续提交会改变最近任务。",
        "responses": {
          "200": {
            "description": "任务或 null",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Envelope"
                    },
                    {
                      "properties": {
                        "result": {
                          "oneOf": [
                            {
                              "$ref": "#/components/schemas/AutoJob"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/public/auto/jobs/{jobId}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/JobId"
        }
      ],
      "get": {
        "tags": [
          "自动接码"
        ],
        "operationId": "getAutoJob",
        "summary": "查询指定任务进度",
        "description": "推荐每 4 秒轮询。按 status 判定终态，不要仅依靠 stage、message 或 HTTP 200。任务执行失败也可 HTTP 200，result.status 为 FAILED。其他 CDK 的任务返回 404。",
        "responses": {
          "200": {
            "$ref": "#/components/responses/Job"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/public/auto/jobs/{jobId}/stop": {
      "parameters": [
        {
          "$ref": "#/components/parameters/JobId"
        }
      ],
      "post": {
        "tags": [
          "自动接码"
        ],
        "operationId": "stopAutoJob",
        "summary": "请求异步停止任务",
        "description": "请求停止后仍可能 RUNNING/STOPPING，继续轮询至终态。验证阶段可能无法取消；已取号码仍在后台结算，收到短信可能扣次。停止请求不代表已经取消，对终态任务调用仅返回原任务。",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {}
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Job"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/public/auto/jobs/{jobId}/cpa": {
      "parameters": [
        {
          "$ref": "#/components/parameters/JobId"
        }
      ],
      "get": {
        "tags": [
          "自动接码"
        ],
        "operationId": "downloadCpa",
        "summary": "下载成功任务的 CPA ZIP",
        "description": "任务必须属于当前 CDK 且成功、未超过 resultExpiresAt。有效会话下 CDK 次数为零仍可下载。ZIP 内为 codex-{账号邮箱}.json，例如 codex-aesopsparksnet-split-b49bcb@dr.com.json；包含敏感账号访问令牌，禁止写日志。每次成功请求计一次下载审计。",
        "responses": {
          "200": {
            "description": "二进制 ZIP 文件，无 JSON 包装",
            "headers": {
              "Content-Disposition": {
                "schema": {
                  "type": "string"
                },
                "description": "attachment; filename=\"cpa-{jobId}.zip\""
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/zip": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "CdkSession": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "CDK session token",
        "description": "使用兑换返回的 accessToken，不使用 OpenAI AT 或管理员密钥"
      }
    },
    "parameters": {
      "JobId": {
        "name": "jobId",
        "in": "path",
        "required": true,
        "description": "提交任务返回的 result.id，非 activationId",
        "schema": {
          "type": "string"
        },
        "example": "11111111111111111111111111111111"
      }
    },
    "responses": {
      "Error": {
        "description": "业务错误：HTTP 状态与 code 一致。网关层错误可能为 HTML。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "example": {
              "code": 409,
              "message": "该 CDK 当前剩余次数不足以再并发提交任务",
              "result": null
            }
          }
        }
      },
      "Job": {
        "description": "任务对象；异步提交或停止均不保证已到终态",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Envelope"
                },
                {
                  "properties": {
                    "result": {
                      "$ref": "#/components/schemas/AutoJob"
                    }
                  }
                }
              ]
            }
          }
        }
      }
    },
    "schemas": {
      "Envelope": {
        "type": "object",
        "required": [
          "code",
          "message",
          "result"
        ],
        "properties": {
          "code": {
            "type": "integer",
            "const": 200
          },
          "message": {
            "type": "string",
            "const": "success"
          },
          "result": {}
        }
      },
      "ApiError": {
        "type": "object",
        "required": [
          "code",
          "message",
          "result"
        ],
        "properties": {
          "code": {
            "type": "integer",
            "description": "与 HTTP 错误状态一致"
          },
          "message": {
            "type": "string"
          },
          "errorCode": {
            "type": "string",
            "description": "可选结构化错误标识；request_conflict 表示请求编号已绑定其他账号"
          },
          "result": {
            "type": "null"
          }
        }
      },
      "CdkInfo": {
        "type": "object",
        "required": [
          "cdkSuffix",
          "tier",
          "tierName",
          "remainingTimes",
          "usedTimes",
          "status"
        ],
        "properties": {
          "cdkSuffix": {
            "type": "string"
          },
          "tier": {
            "type": "string",
            "enum": [
              "LOW",
              "HIGH",
              "AUTO"
            ]
          },
          "tierName": {
            "type": "string"
          },
          "remainingTimes": {
            "type": "integer",
            "minimum": 0
          },
          "usedTimes": {
            "type": "integer",
            "minimum": 0
          },
          "status": {
            "type": "string",
            "enum": [
              "ACTIVE",
              "DISABLED"
            ]
          }
        }
      },
      "AutoJob": {
        "type": "object",
        "required": [
          "id",
          "email",
          "status",
          "stage",
          "message",
          "createdAt",
          "remainingTimes",
          "chargedTimes",
          "phoneVerified",
          "attempts",
          "activation"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "description": "脱敏邮箱"
          },
          "canStop": {
            "type": "boolean",
            "description": "是否可以请求停止；验证阶段可能不可取消，请继续查询最终状态。"
          },
          "clientRequestId": {
            "type": [
              "string",
              "null"
            ],
            "description": "客户端原请求编号；旧任务为 null"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "terminal": {
            "type": "boolean",
            "description": "任务是否已结束；号码可能仍在后台结算"
          },
          "status": {
            "type": "string",
            "enum": [
              "QUEUED",
              "RUNNING",
              "SUCCESS",
              "FAILED",
              "CANCELLED",
              "INTERRUPTED"
            ]
          },
          "stage": {
            "type": "string",
            "description": "步骤或错误标识，可扩展；按 status 判断终态"
          },
          "message": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "remainingTimes": {
            "type": "integer",
            "minimum": 0
          },
          "chargedTimes": {
            "type": "integer",
            "minimum": 0,
            "description": "本任务已扣次，独立于授权成功/失败"
          },
          "phoneVerified": {
            "type": "boolean",
            "description": "是否已确认完成手机验证；false 也可能表示无可报告的验证明细"
          },
          "attempts": {
            "type": "integer",
            "minimum": 0,
            "description": "客户侧取号次数；无号码明细的自动授权成功后至少为 1，已有多次取号记录时保留原次数"
          },
          "activation": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/AutoActivationState"
              },
              {
                "type": "null"
              }
            ],
            "description": "客户可见的脱敏号码状态，不包含手机号、国家、取号记录编号或短信验证码"
          },
          "customerResult": {
            "$ref": "#/components/schemas/CustomerResult",
            "description": "仅任务 SUCCESS 时返回"
          }
        }
      },
      "AutoActivationState": {
        "type": "object",
        "required": [
          "status",
          "autoCancelAt",
          "cancelPending"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "WAITING",
              "SUCCESS",
              "CANCELLED",
              "EXPIRED",
              "PROVIDER_ERROR"
            ]
          },
          "autoCancelAt": {
            "type": "string",
            "format": "date-time"
          },
          "cancelPending": {
            "type": "boolean"
          }
        }
      },
      "CustomerResult": {
        "type": "object",
        "required": [
          "id",
          "email",
          "cdkCode",
          "cdkSuffix",
          "createdAt",
          "resultExpiresAt",
          "cpaAvailable"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "description": "完整成功邮箱；历史记录可能仅能返回脱敏值"
          },
          "cdkCode": {
            "type": [
              "string",
              "null"
            ],
            "description": "完整 CDK；历史未保存时为 null"
          },
          "cdkSuffix": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "任务提交时间"
          },
          "resultExpiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "CPA 文件下载期限，与令牌有效期不同"
          },
          "cpaAvailable": {
            "type": "boolean"
          }
        }
      }
    }
  }
}
