{
  "openapi": "3.1.0",
  "info": {
    "title": "UPI-GIT5 API",
    "version": "1.2.0",
    "description": "UPI-GIT5 Rust 公共 API：提供提链 CDK 租户会话、批量任务、任务状态、代理处理及自动支付接口。公开基础 URL 为 https://rustupi.agiapi.top。"
  },
  "servers": [
    {
      "url": "https://rustupi.agiapi.top",
      "description": "公开 API 基础 URL"
    }
  ],
  "x-python-api-compatibility": {
    "version": "1.1.0",
    "mode": "backward-compatible-superset",
    "documented_operations": 28,
    "routable_upi_server_operations": 24,
    "migration": "Python upi_server 中实际注册的 24 个公开操作保留方法、路径、请求字段、响应码和 X-Link-CDK-Session，只修改 Base URL。旧文档另外列出的姓名 GET/POST 与 CAPTCHA 入口也已兼容；未注册到 upi_server 的 POST /api/checkout 在 Rust 中作为需提链 CDK 会话的兼容入口提供。"
  },
  "tags": [
    {"name": "Service", "description": "服务配置和统计"},
    {"name": "Link CDK", "description": "提链 CDK 与租户会话"},
    {"name": "Proxy", "description": "代理处理接口"},
    {"name": "Batch", "description": "批量提链和任务状态"},
    {"name": "Payment", "description": "自动支付配置与提交"},
    {"name": "Compatibility", "description": "Python 辅助入口的 Rust 兼容层"}
  ],
  "paths": {
    "/api/health": {
      "get": {
        "tags": ["Service"],
        "summary": "服务健康与全站统计",
        "operationId": "getHealth",
        "responses": {
          "200": {"description": "服务正常", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HealthResponse"}}}}
        }
      }
    },
    "/api/config": {
      "get": {
        "tags": ["Service"],
        "summary": "读取服务配置",
        "operationId": "getConfig",
        "responses": {"200": {"description": "服务配置", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ConfigResponse"}}}}}
      }
    },
    "/api/recent-results": {
      "get": {
        "tags": ["Service"],
        "summary": "读取最近任务结果统计",
        "operationId": "getRecentResults",
        "parameters": [{"name": "hours", "in": "query", "schema": {"type": "number", "default": 12, "minimum": 0.0167}}],
        "responses": {
          "200": {"description": "任务结果统计", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}},
          "400": {"$ref": "#/components/responses/BadRequest"}
        }
      }
    },
    "/api/fingerprint-stats": {
      "get": {
        "tags": ["Service"],
        "summary": "读取 Firefox 指纹统计",
        "operationId": "getFingerprintStats",
        "responses": {"200": {"description": "指纹统计", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}}}
      }
    },
    "/api/random-indian-name": {
      "get": {
        "tags": ["Compatibility"],
        "summary": "生成印度姓名",
        "description": "使用 Rust 内置姓名词库生成结构化姓名；按客户端 IP 应用独立的 PAY153_NAME_API_RPM 限流。",
        "operationId": "getRandomIndianName",
        "parameters": [
          {"name": "count", "in": "query", "schema": {"type": "integer", "minimum": 1, "maximum": 50, "default": 1}},
          {"name": "gender", "in": "query", "schema": {"type": "string", "enum": ["random", "male", "female"], "default": "random"}},
          {"name": "given_names_count", "in": "query", "schema": {"type": "integer", "minimum": 1, "maximum": 4, "default": 1}},
          {"name": "surnames_count", "in": "query", "schema": {"type": "integer", "minimum": 1, "maximum": 2, "default": 1}},
          {"name": "westernized", "in": "query", "schema": {"type": "boolean", "default": true}}
        ],
        "responses": {
          "200": {"description": "姓名列表", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/IndianNameResponse"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "429": {"$ref": "#/components/responses/TooManyRequests"},
          "502": {"$ref": "#/components/responses/BadGateway"}
        }
      },
      "post": {
        "tags": ["Compatibility"],
        "summary": "生成印度姓名",
        "description": "GET 的 JSON 请求体版本，使用相同的字段、校验和独立客户端 IP 限流。",
        "operationId": "postRandomIndianName",
        "requestBody": {"required": false, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/IndianNameOptions"}}}},
        "responses": {
          "200": {"description": "姓名列表", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/IndianNameResponse"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "429": {"$ref": "#/components/responses/TooManyRequests"},
          "502": {"$ref": "#/components/responses/BadGateway"}
        }
      }
    },
    "/api/captcha-only": {
      "get": {
        "tags": ["Compatibility"],
        "summary": "读取 CAPTCHA 桥接页",
        "operationId": "getCaptchaOnlyBridge",
        "responses": {
          "200": {"description": "最小 HTML 桥接页", "content": {"text/html": {"schema": {"type": "string"}}}}
        }
      }
    },
    "/api/link-cdk/status": {
      "post": {
        "tags": ["Link CDK"],
        "summary": "验证提链 CDK 并读取余额",
        "operationId": "getLinkCdkStatus",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LinkCdkCodeRequest"}}}},
        "responses": {
          "200": {"description": "CDK 状态", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LinkCdkStatusResponse"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/link-cdk/session": {
      "post": {
        "tags": ["Link CDK"],
        "summary": "创建提链 CDK 租户会话",
        "operationId": "createLinkCdkSession",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LinkCdkCodeRequest"}}}},
        "responses": {
          "200": {"description": "会话已创建", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LinkCdkSessionResponse"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/link-cdk/session/logout": {
      "post": {
        "tags": ["Link CDK"],
        "summary": "注销提链 CDK 租户会话",
        "operationId": "logoutLinkCdkSession",
        "security": [{"LinkCdkSession": []}],
        "responses": {"200": {"$ref": "#/components/responses/Ok"}}
      }
    },
    "/api/link-cdk/fuse": {
      "post": {
        "tags": ["Link CDK"],
        "summary": "融合提链 CDK 额度",
        "description": "来源 CDK 的全部剩余额度转入目标 CDK。不可融合 CDK 可以接收额度，但不能作为来源转出额度。",
        "operationId": "fuseLinkCdk",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["target_code", "source_code"], "properties": {"target_code": {"type": "string"}, "source_code": {"type": "string"}}}}}},
        "responses": {
          "200": {"description": "融合完成", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "409": {"$ref": "#/components/responses/Conflict"}
        }
      }
    },
    "/api/proxy/optimize": {
      "post": {
        "tags": ["Proxy"],
        "summary": "处理单个代理",
        "description": "返回标准化处理结果；未接受时通过 accepted=false 和 error 提供客户端可见结果。",
        "operationId": "optimizeProxy",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProxyOptimizeRequest"}}}},
        "responses": {
          "200": {"description": "代理处理结果", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProxyAssessment"}}}},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/proxy/optimize-batch": {
      "post": {
        "tags": ["Proxy"],
        "summary": "流式处理代理列表",
        "description": "返回 application/x-ndjson。首行为 start，随后输出带 0 基 index 的 result，末行为 complete。",
        "operationId": "optimizeProxyBatch",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProxyOptimizeBatchRequest"}}}},
        "responses": {
          "200": {"description": "NDJSON 代理处理流", "headers": {"X-Accel-Buffering": {"schema": {"type": "string", "const": "no"}}}, "content": {"application/x-ndjson": {"schema": {"type": "string"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/upi-git5/batch": {
      "post": {
        "tags": ["Batch"],
        "summary": "创建 UPI-GIT5 批量任务",
        "description": "异步创建 UPI-GIT5 批量任务，并返回批次标识和任务列表。",
        "operationId": "createUpiGit5Batch",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BatchCreateRequest"}}}},
        "responses": {
          "202": {"description": "批次已创建", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BatchCreateResponse"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "409": {"$ref": "#/components/responses/Conflict"},
          "429": {"$ref": "#/components/responses/TooManyRequests"}
        }
      }
    },
    "/api/upi-git5/batch/{batch_id}": {
      "get": {
        "tags": ["Batch"],
        "summary": "读取批次完整详情",
        "operationId": "getUpiGit5Batch",
        "security": [{"LinkCdkSession": []}],
        "parameters": [{"$ref": "#/components/parameters/BatchId"}],
        "responses": {
          "200": {"description": "批次详情", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BatchSnapshot"}}}},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "404": {"$ref": "#/components/responses/NotFound"}
        }
      }
    },
    "/api/upi-git5/batch/{batch_id}/progress": {
      "get": {
        "tags": ["Batch"],
        "summary": "读取批次轻量进度",
        "operationId": "getUpiGit5BatchProgress",
        "security": [{"LinkCdkSession": []}],
        "parameters": [
          {"$ref": "#/components/parameters/BatchId"},
          {"name": "summary_only", "in": "query", "description": "只返回汇总计数，不返回任务数组", "schema": {"type": "boolean", "default": false}},
          {"name": "since", "in": "query", "description": "上次响应的 cursor；只返回之后变化的任务", "schema": {"type": "number", "minimum": 0, "default": 0}},
          {"name": "result", "in": "query", "description": "任务结果载荷级别；高并发轮询使用 compact", "schema": {"type": "string", "enum": ["none", "compact", "full"], "default": "full"}},
          {"name": "include_payment", "in": "query", "description": "是否在任务快照中携带支付状态", "schema": {"type": "boolean", "default": true}},
          {"name": "offset", "in": "query", "description": "当前变化集的分页偏移", "schema": {"type": "integer", "minimum": 0, "default": 0}},
          {"name": "limit", "in": "query", "description": "本页任务数上限", "schema": {"type": "integer", "minimum": 1, "maximum": 1000}}
        ],
        "responses": {
          "200": {"description": "批次增量进度", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BatchProgressSnapshot"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "404": {"$ref": "#/components/responses/NotFound"}
        }
      }
    },
    "/api/upi-git5/batch/{batch_id}/cleanup": {
      "post": {
        "tags": ["Batch"],
        "summary": "取消并清理整个批次",
        "operationId": "cleanupUpiGit5Batch",
        "security": [{"LinkCdkSession": []}],
        "parameters": [{"$ref": "#/components/parameters/BatchId"}],
        "requestBody": {"required": false, "content": {"application/json": {"schema": {"type": "object", "properties": {"wait_seconds": {"type": "number", "minimum": 0, "maximum": 30, "default": 0}}}}}},
        "responses": {
          "200": {"description": "批次工作与支付任务清理结果", "content": {"application/json": {"schema": {"type": "object", "required": ["ok", "batch_id", "found", "clean", "pending_workers", "pending_payments", "removed_jobs"], "additionalProperties": true}}}},
          "202": {"description": "清理已启动，仍有工作或支付任务退出中", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "404": {"$ref": "#/components/responses/NotFound"}
        }
      }
    },
    "/api/checkout": {
      "post": {
        "tags": ["Compatibility", "Batch"],
        "summary": "创建单个兼容 Checkout 任务",
        "description": "将 Python 单任务请求映射到 Rust 异步批次队列；固定 Plus 套餐、促销流程和 UPI-GIT5 完整 OAICS/Stripe 状态机。",
        "operationId": "createCheckoutCompat",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/CheckoutCompatRequest"}}}},
        "responses": {
          "202": {"description": "单任务已加入批次队列", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/CheckoutCompatResponse"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "409": {"$ref": "#/components/responses/Conflict"},
          "429": {"$ref": "#/components/responses/TooManyRequests"}
        }
      }
    },
    "/api/checkout-progress": {
      "get": {
        "tags": ["Batch"],
        "summary": "读取单个任务进度",
        "operationId": "getCheckoutProgress",
        "security": [{"LinkCdkSession": []}],
        "parameters": [{"$ref": "#/components/parameters/JobIdQuery"}],
        "responses": {
          "200": {"description": "任务快照", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Job"}}}},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "404": {"$ref": "#/components/responses/NotFound"}
        }
      }
    },
    "/api/checkout-qr": {
      "get": {
        "tags": ["Batch"],
        "summary": "获取任务支付二维码",
        "operationId": "getCheckoutQr",
        "security": [{"LinkCdkSession": []}],
        "parameters": [{"$ref": "#/components/parameters/JobIdQuery"}],
        "responses": {
          "200": {"description": "二维码 PNG", "content": {"image/png": {"schema": {"type": "string", "contentEncoding": "base64"}}}},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "404": {"$ref": "#/components/responses/NotFound"}
        }
      }
    },
    "/api/checkout-cancel": {
      "post": {
        "tags": ["Batch"],
        "summary": "停止单个任务",
        "operationId": "cancelCheckout",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/JobIdRequest"}}}},
        "responses": {
          "200": {"$ref": "#/components/responses/Ok"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "404": {"$ref": "#/components/responses/NotFound"}
        }
      }
    },
    "/api/payment/status": {
      "get": {
        "tags": ["Payment"],
        "summary": "读取当前租户支付配置",
        "operationId": "getPaymentStatus",
        "security": [{"LinkCdkSession": []}],
        "responses": {
          "200": {"description": "支付配置", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentStatusResponse"}}}},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/payment/teams": {
      "get": {
        "tags": ["Payment"],
        "summary": "读取当前租户支付团队",
        "operationId": "getPaymentTeams",
        "security": [{"LinkCdkSession": []}],
        "parameters": [{"name": "provider_id", "in": "query", "schema": {"$ref": "#/components/schemas/PaymentProviderId"}}],
        "responses": {
          "200": {"description": "支付平台团队及当前选择", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "502": {"$ref": "#/components/responses/BadGateway"}
        }
      }
    },
    "/api/payment/configure": {
      "post": {
        "tags": ["Payment"],
        "summary": "保存并登录支付平台 CDK",
        "operationId": "configurePayment",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["provider_id", "cdk"], "properties": {"provider_id": {"$ref": "#/components/schemas/PaymentProviderId"}, "cdk": {"type": "string"}}}}}},
        "responses": {
          "200": {"description": "平台 CDK 已配置", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderStatus"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "502": {"$ref": "#/components/responses/BadGateway"}
        }
      }
    },
    "/api/payment/settings": {
      "post": {
        "tags": ["Payment"],
        "summary": "切换平台及自动提交开关",
        "operationId": "setPaymentSettings",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["provider_id", "enabled"], "properties": {"provider_id": {"$ref": "#/components/schemas/PaymentProviderId"}, "enabled": {"type": "boolean"}}}}}},
        "responses": {
          "200": {"description": "支付设置已更新", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderStatus"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/payment/clear": {
      "post": {
        "tags": ["Payment"],
        "summary": "清空指定平台支付 CDK",
        "operationId": "clearPaymentCdk",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderRequest"}}}},
        "responses": {
          "200": {"description": "平台 CDK 已清空", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderStatus"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/payment/quota": {
      "post": {
        "tags": ["Payment"],
        "summary": "刷新支付 CDK 剩余额度",
        "operationId": "refreshPaymentQuota",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderRequest"}}}},
        "responses": {
          "200": {"description": "支付额度已刷新", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderStatus"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "502": {"$ref": "#/components/responses/BadGateway"}
        }
      }
    },
    "/api/payment/manual-submit": {
      "post": {
        "tags": ["Payment"],
        "summary": "批量手动提交未提交支付的任务",
        "operationId": "manualSubmitPayment",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["job_ids"], "properties": {"job_ids": {"type": "array", "maxItems": 5000, "items": {"type": "string"}}}}}}},
        "responses": {
          "202": {"description": "任务已进入支付队列", "content": {"application/json": {"schema": {"type": "object", "properties": {"ok": {"type": "boolean"}, "provider_id": {"type": "string"}, "queued": {"type": "array", "items": {"type": "string"}}, "skipped": {"type": "array", "items": {"type": "object", "additionalProperties": true}}}}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "502": {"$ref": "#/components/responses/BadGateway"}
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "LinkCdkSession": {"type": "apiKey", "in": "header", "name": "X-Link-CDK-Session", "description": "由 POST /api/link-cdk/session 返回"}
    },
    "parameters": {
      "BatchId": {"name": "batch_id", "in": "path", "required": true, "schema": {"type": "string"}},
      "JobIdQuery": {"name": "job_id", "in": "query", "required": true, "schema": {"type": "string"}}
    },
    "responses": {
      "Ok": {"description": "操作完成", "content": {"application/json": {"schema": {"type": "object", "required": ["ok"], "properties": {"ok": {"type": "boolean"}}, "additionalProperties": true}}}},
      "BadRequest": {"description": "请求参数错误", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "Unauthorized": {"description": "会话缺失或失效", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "Forbidden": {"description": "CDK 不可用或资源不属于当前租户", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "NotFound": {"description": "资源不存在", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "Conflict": {"description": "资源占用或状态冲突", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "TooManyRequests": {"description": "请求频率受限", "headers": {"Retry-After": {"schema": {"type": "integer"}}}, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "BadGateway": {"description": "支付平台网络或响应错误", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}}
    },
    "schemas": {
      "ErrorEnvelope": {
        "type": "object",
        "properties": {
          "ok": {"type": "boolean", "const": false},
          "error": {
            "oneOf": [
              {"type": "string"},
              {"type": "object", "required": ["code", "message"], "properties": {"code": {"type": "string"}, "message": {"type": "string"}}}
            ]
          }
        }
      },
      "ConfigResponse": {
        "type": "object",
        "required": ["plans", "link_types", "provider_defaults", "batch", "payment", "link_cdk", "capabilities"],
        "properties": {
          "plans": {"type": "array", "items": {"type": "string"}, "examples": [["plus"]]},
          "link_types": {"type": "array", "minItems": 1, "maxItems": 1, "items": {"type": "string", "const": "upi-git5"}, "examples": [["upi-git5"]]},
          "provider_defaults": {
            "type": "object",
            "required": ["upi-git5"],
            "properties": {
              "upi-git5": {"type": "object", "required": ["country", "currency"], "properties": {"country": {"type": "string", "const": "IN"}, "currency": {"type": "string", "const": "INR"}}, "additionalProperties": false}
            },
            "additionalProperties": false
          },
          "batch": {
            "type": "object",
            "required": ["max_tokens", "max_proxies", "workers"],
            "properties": {
              "max_tokens": {"type": "integer", "const": 5000},
              "max_proxies": {"type": "integer", "const": 5000},
              "workers": {"type": "integer", "minimum": 1}
            },
            "additionalProperties": true
          },
          "payment": {"type": "object", "additionalProperties": true},
          "link_cdk": {"type": "object", "additionalProperties": true},
          "capabilities": {"type": "object", "additionalProperties": true}
        },
        "additionalProperties": true
      },
      "IndianNameOptions": {
        "type": "object",
        "properties": {
          "count": {"type": "integer", "minimum": 1, "maximum": 50, "default": 1},
          "gender": {"type": "string", "enum": ["random", "male", "female"], "default": "random"},
          "given_names_count": {"type": "integer", "minimum": 1, "maximum": 4, "default": 1},
          "surnames_count": {"type": "integer", "minimum": 1, "maximum": 2, "default": 1},
          "westernized": {"type": "boolean", "default": true}
        },
        "additionalProperties": false
      },
      "IndianNameResponse": {
        "type": "object",
        "required": ["ok", "data"],
        "properties": {
          "ok": {"type": "boolean", "const": true},
          "data": {
            "type": "object",
            "required": ["names", "items", "meta"],
            "properties": {
              "names": {"type": "array", "items": {"type": "string"}},
              "items": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": ["name", "full_name", "gender", "given_names", "surnames"],
                  "properties": {
                    "name": {"type": "string"},
                    "full_name": {"type": "string"},
                    "gender": {"type": "string", "enum": ["male", "female"]},
                    "given_names": {"type": "array", "items": {"type": "string"}},
                    "surnames": {"type": "array", "items": {"type": "string"}}
                  }
                }
              },
              "meta": {
                "type": "object",
                "required": ["language", "gender", "count", "given_names_count", "surnames_count", "westernized", "provider"],
                "properties": {
                  "language": {"type": "string", "const": "hindi"},
                  "gender": {"type": "string", "enum": ["random", "male", "female"]},
                  "count": {"type": "integer"},
                  "given_names_count": {"type": "integer"},
                  "surnames_count": {"type": "integer"},
                  "westernized": {"type": "boolean"},
                  "provider": {"type": "string", "const": "rust-builtin"}
                }
              }
            }
          }
        }
      },
      "CheckoutCompatRequest": {
        "type": "object",
        "properties": {
          "plan": {"type": "string", "const": "plus", "default": "plus"},
          "link_type": {"type": "string", "const": "upi-git5", "default": "upi-git5"},
          "token": {"type": "string"},
          "tokens": {"type": "array", "minItems": 1, "maxItems": 5000, "items": {"type": "string"}},
          "api_proxy": {"type": "string"},
          "proxy": {"type": "string"},
          "entry_proxy": {"type": "string"},
          "entry_proxies": {
            "oneOf": [
              {"type": "string"},
              {"type": "array", "minItems": 1, "maxItems": 5000, "items": {"type": "string"}}
            ]
          },
          "link_cdk": {"type": "string", "description": "提供时必须与当前租户会话一致"},
          "payment_provider_id": {"$ref": "#/components/schemas/PaymentProviderId"},
          "use_promo": {"type": "boolean", "const": true, "default": true},
          "promo_campaign": {"type": "string", "default": "plus-1-month-free"}
        },
        "allOf": [
          {"anyOf": [{"required": ["token"]}, {"required": ["tokens"]}]},
          {"anyOf": [{"required": ["api_proxy"]}, {"required": ["proxy"]}, {"required": ["entry_proxy"]}, {"required": ["entry_proxies"]}]}
        ],
        "additionalProperties": true
      },
      "CheckoutCompatResponse": {
        "type": "object",
        "required": ["ok", "job_id", "batch_id", "link_type", "country", "currency", "queue_position", "global_rpm", "ip_rpm"],
        "properties": {
          "ok": {"type": "boolean", "const": true},
          "job_id": {"type": "string"},
          "batch_id": {"type": "string"},
          "link_type": {"type": "string", "const": "upi-git5"},
          "country": {"type": "string", "const": "IN"},
          "currency": {"type": "string", "const": "INR"},
          "queue_position": {"type": "integer", "minimum": 1},
          "global_rpm": {"type": "integer", "minimum": 1},
          "ip_rpm": {"type": "integer", "minimum": 1}
        }
      },
      "ProxyOptimizeRequest": {
        "type": "object",
        "required": ["proxy"],
        "properties": {"proxy": {"type": "string", "minLength": 1, "description": "支持 URL、host:port、host:port:user:pass、user:pass@host:port 等格式"}}
      },
      "ProxyOptimizeBatchRequest": {
        "type": "object",
        "required": ["proxies"],
        "properties": {"proxies": {"type": "array", "minItems": 1, "maxItems": 5000, "items": {"type": "string", "minLength": 1}}}
      },
      "ProxyAssessment": {
        "type": "object",
        "required": ["ok", "proxy", "accepted"],
        "properties": {
          "ok": {"type": "boolean", "const": true},
          "proxy": {"type": "string"},
          "normalized_proxy": {"type": "string"},
          "accepted": {"type": "boolean"},
          "decision": {"type": "string"},
          "rejection_code": {"type": ["string", "null"]},
          "error": {"type": "string", "description": "未接受或处理失败时的客户端可见说明"}
        },
        "additionalProperties": true
      },
      "HealthResponse": {
        "type": "object",
        "required": ["ok", "service", "link_type", "global_concurrency_limit", "configured_global_concurrency_limit", "network_concurrency_limit", "payment_submit_concurrency", "payment_tracking_concurrency", "active_jobs", "queued_jobs", "running_jobs", "payment_success_jobs"],
        "properties": {
          "ok": {"type": "boolean"},
          "service": {"type": "string"},
          "link_type": {"type": "string"},
          "global_concurrency_limit": {"type": "integer"},
          "configured_global_concurrency_limit": {"type": "integer"},
          "network_concurrency_limit": {"type": "integer"},
          "payment_submit_concurrency": {"type": "integer"},
          "payment_tracking_concurrency": {"type": "integer"},
          "active_jobs": {"type": "integer"},
          "queued_jobs": {"type": "integer"},
          "running_jobs": {"type": "integer"},
          "payment_success_jobs": {"type": "integer"}
        }
      },
      "LinkCdkCodeRequest": {
        "type": "object",
        "required": ["code"],
        "properties": {"code": {"type": "string", "examples": ["UPI-CDK-598D-9C61-541B"]}}
      },
      "LinkCdkStatus": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "code_masked": {"type": "string"},
          "status": {"type": "string", "enum": ["active", "disabled", "deleted", "merged", "exhausted"]},
          "remaining_uses": {"type": "integer"},
          "reserved_uses": {"type": "integer"},
          "available_uses": {"type": "integer"},
          "concurrency_limit": {"type": "integer"},
          "fusion_allowed": {"type": "boolean"}
        },
        "additionalProperties": true
      },
      "LinkCdkStatusResponse": {
        "allOf": [
          {"type": "object", "properties": {"ok": {"type": "boolean"}}},
          {"$ref": "#/components/schemas/LinkCdkStatus"}
        ]
      },
      "LinkCdkSessionResponse": {
        "type": "object",
        "required": ["ok", "token", "expires_at", "link_cdk"],
        "properties": {
          "ok": {"type": "boolean"},
          "token": {"type": "string"},
          "expires_at": {"type": "number"},
          "link_cdk": {"$ref": "#/components/schemas/LinkCdkStatus"}
        }
      },
      "PaymentProviderId": {"type": "string", "enum": ["foarge", "xxsyun", "astrascan", "cdkscan"], "default": "foarge"},
      "PaymentProviderRequest": {
        "type": "object",
        "required": ["provider_id"],
        "properties": {"provider_id": {"$ref": "#/components/schemas/PaymentProviderId"}}
      },
      "PaymentProviderStatus": {
        "type": "object",
        "properties": {
          "ok": {"type": "boolean"},
          "provider_id": {"$ref": "#/components/schemas/PaymentProviderId"},
          "label": {"type": "string"},
          "submit_interval_seconds": {"type": "number"},
          "configured": {"type": "boolean"},
          "enabled": {"type": "boolean"},
          "quota_remaining": {"type": ["integer", "null"]},
          "quota_known": {"type": "boolean"},
          "quota_updated_at": {"type": "number"},
          "quota_blocked": {"type": "boolean"}
        },
        "additionalProperties": true
      },
      "PaymentStatusResponse": {
        "type": "object",
        "properties": {
          "ok": {"type": "boolean"},
          "selected_provider_id": {"$ref": "#/components/schemas/PaymentProviderId"},
          "enabled": {"type": "boolean"},
          "providers": {"type": "array", "items": {"$ref": "#/components/schemas/PaymentProviderStatus"}}
        }
      },
      "BatchCreateRequest": {
        "type": "object",
        "required": ["tokens", "entry_proxies", "link_cdk"],
        "properties": {
          "tokens": {"type": "array", "minItems": 1, "maxItems": 5000, "items": {"type": "string"}},
          "entry_proxies": {"type": "array", "minItems": 1, "maxItems": 5000, "description": "批次代理数组，最多 5000 条", "items": {"type": "string"}},
          "link_cdk": {"type": "string"},
          "payment_provider_id": {"$ref": "#/components/schemas/PaymentProviderId"},
          "use_promo": {"type": "boolean", "default": true, "enum": [true], "description": "UPI-GIT5 严格 0 元模式固定开启"},
          "promo_campaign": {"type": "string", "default": "plus-1-month-free"}
        }
      },
      "BatchCreateResponse": {
        "type": "object",
        "required": ["ok", "batch_id", "batch_size", "jobs"],
        "properties": {
          "ok": {"type": "boolean"},
          "batch_id": {"type": "string"},
          "batch_size": {"type": "integer"},
          "jobs": {"type": "array", "items": {"type": "object", "properties": {"index": {"type": "integer"}, "account_email": {"type": "string"}, "job_id": {"type": "string"}, "queue_position": {"type": "integer"}}}},
          "workers": {"type": "integer"},
          "batch_workers": {"type": "integer"},
          "global_concurrency": {"type": "integer", "description": "管理员配置的全站并发，与 Python 版 workers 字段兼容"},
          "configured_global_concurrency_limit": {"type": "integer"},
          "effective_workers": {"type": "integer", "description": "全站配置与网络硬上限共同约束后的实际任务并发"},
          "effective_global_concurrency": {"type": "integer"},
          "global_concurrency_limit": {"type": "integer"},
          "network_concurrency_limit": {"type": "integer"},
          "payment_provider_id": {"type": "string"},
          "use_promo": {"type": "boolean"},
          "payment_auto_submit": {"type": "boolean"}
        },
        "additionalProperties": true
      },
      "JobPayment": {
        "type": "object",
        "properties": {
          "provider_id": {"type": "string"},
          "status": {"type": "string", "enum": ["not_submitted", "awaiting_worker", "queued", "submission_waiting", "submitting", "submit_failed", "tracking_retrying", "tracking_failed", "quota_insufficient", "completed", "failed", "expired", "cancelled"]},
          "order_id": {"type": "string"},
          "order_status": {"type": "string"},
          "text": {"type": "string"},
          "code": {"type": "string"},
          "error": {"type": "string"},
          "attempts": {"type": "integer"},
          "updated_at": {"type": "number"}
        },
        "additionalProperties": true
      },
      "Job": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "batch_id": {"type": "string"},
          "batch_index": {"type": "integer"},
          "batch_size": {"type": "integer"},
          "account_email": {"type": "string"},
          "status": {"type": "string", "enum": ["queued", "running", "done", "error", "cancelled"]},
          "percent": {"type": "integer", "minimum": 0, "maximum": 100},
          "text": {"type": "string", "description": "任务进度说明"},
          "queue_position": {"type": "integer"},
          "error": {
            "type": "string",
            "description": "任务失败时的客户端可见错误；客户端应按结构化错误码或稳定前缀分类，不依赖具体中文文本。"
          },
          "result": {"type": ["object", "null"], "additionalProperties": true},
          "payment": {"$ref": "#/components/schemas/JobPayment"},
          "created_at": {"type": "number"},
          "link_completed_at": {"type": "number", "description": "提链首次成功的冻结时间戳；后续支付更新不会改变"},
          "updated_at": {"type": "number"}
        },
        "additionalProperties": true
      },
      "BatchSnapshot": {
        "type": "object",
        "required": ["batch_id", "batch_size", "running", "completed", "succeeded", "failed", "cancelled", "jobs"],
        "properties": {
          "batch_id": {"type": "string"},
          "batch_size": {"type": "integer"},
          "running": {"type": "boolean"},
          "completed": {"type": "integer"},
          "succeeded": {"type": "integer"},
          "failed": {"type": "integer"},
          "cancelled": {"type": "integer"},
          "jobs": {"type": "array", "items": {"$ref": "#/components/schemas/Job"}},
          "logs": {"type": "array", "items": {"type": "object", "additionalProperties": true}}
        }
      },
      "BatchProgressSnapshot": {
        "type": "object",
        "required": ["batch_id", "batch_size", "running", "completed", "succeeded", "failed", "cancelled", "payment_active", "cursor", "since", "matching", "returned", "offset", "summary_only", "result_mode", "jobs"],
        "properties": {
          "batch_id": {"type": "string"},
          "batch_size": {"type": "integer"},
          "running": {"type": "boolean"},
          "completed": {"type": "integer"},
          "succeeded": {"type": "integer"},
          "failed": {"type": "integer"},
          "cancelled": {"type": "integer"},
          "payment_active": {"type": "integer"},
          "cursor": {"type": "number"},
          "since": {"type": "number"},
          "matching": {"type": "integer"},
          "returned": {"type": "integer"},
          "offset": {"type": "integer"},
          "next_offset": {"type": ["integer", "null"]},
          "summary_only": {"type": "boolean"},
          "result_mode": {"type": "string", "enum": ["none", "compact", "full"]},
          "jobs": {"type": "array", "items": {"$ref": "#/components/schemas/Job"}}
        }
      },
      "JobIdRequest": {
        "type": "object",
        "required": ["job_id"],
        "properties": {"job_id": {"type": "string"}}
      }
    }
  }
}
