{
  "openapi": "3.0.3",
  "info": {
    "title": "混沌提纯机器学习分类 API",
    "version": "1.1.0",
    "description": "仅机器学习；每条成功分类人民币0.0001元。异步请求，先预留余额，失败释放预留。相同客户、request_id及消息重试不重复扣费。Token仅创建时展示，有效期90天。 新请求原文及分类历史加密保存180天，授权运营人员可访问并按配置同步采集总台；不用于训练。旧原文无法恢复。"
  },
  "servers": [
    {
      "url": "https://tichun.cunxx.com/api/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/classifications": {
      "post": {
        "summary": "提交1至100条消息",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Submission"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "返回相同请求已有的完成结果",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "202": {
            "description": "已受理或已有任务仍在处理，建议每秒查询一次",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "description": "可用余额不足，不创建任务"
          },
          "409": {
            "description": "相同request_id的消息编号、正文或顺序不同"
          },
          "413": {
            "description": "请求体超过1MiB或消息数组超过900000字节"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "description": "每客户每分钟最多120个新任务，最多20个待处理任务，读取最多300次；请退避重试"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/classifications/{id}": {
      "get": {
        "summary": "读取本人任务及结果",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{32}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "任务状态，失败不收费",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/balance": {
      "get": {
        "summary": "人民币余额",
        "responses": {
          "200": {
            "description": "十进制字符串金额",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "currency": {
                      "type": "string",
                      "enum": [
                        "CNY"
                      ]
                    },
                    "balance": {
                      "type": "string",
                      "example": "10.0000"
                    },
                    "reserved": {
                      "type": "string",
                      "example": "0.0100"
                    },
                    "available": {
                      "type": "string",
                      "example": "9.9900"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/billing/hourly": {
      "get": {
        "summary": "小时计费记录，北京时间",
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 90,
              "default": 7
            }
          }
        ],
        "responses": {
          "200": {
            "description": "仅成功计费的小时，hour_start为Unix毫秒",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "timezone": {
                      "type": "string",
                      "enum": [
                        "Asia/Shanghai"
                      ]
                    },
                    "price_per_message": {
                      "type": "string",
                      "example": "0.0001"
                    },
                    "hours": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "hour_start": {
                            "type": "integer",
                            "format": "int64"
                          },
                          "messages": {
                            "type": "integer"
                          },
                          "requests": {
                            "type": "integer"
                          },
                          "charged": {
                            "type": "string",
                            "example": "0.0100"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/messages": {
      "get": {
        "summary": "查询本人原文及分类历史",
        "description": "默认30条，最多100条。关键词在有上限的加密候选页中检索；items为空仍可能有next。只显示未到期历史。",
        "parameters": [
          {
            "in": "query",
            "name": "limit",
            "description": "每页1至100，默认30",
            "schema": {
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "before",
            "description": "上页next游标",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "q",
            "description": "原文/消息/请求编号关键词，最多100字符",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "label",
            "description": "分类标签",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "state",
            "description": "任务状态",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "since",
            "description": "起始Unix毫秒",
            "schema": {
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "until",
            "description": "结束Unix毫秒",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "分页历史",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      }
                    },
                    "next": {
                      "type": "string",
                      "nullable": true
                    },
                    "retention_days": {
                      "type": "integer",
                      "example": 180
                    },
                    "bounded_search": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Token无效"
          },
          "429": {
            "description": "读取限流"
          }
        }
      }
    },
    "/messages/{id}": {
      "get": {
        "summary": "查看本人消息原文与分类",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{32}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "消息详情",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                }
              }
            }
          },
          "401": {
            "description": "Token无效"
          },
          "404": {
            "description": "不存在、不属于本人或历史已到期"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "tck_ followed by 43 base64url characters"
      }
    },
    "responses": {
      "Error": {
        "description": "错误；正文为稳定error码及message，Accept-Language支持zh-CN或en，不包含用户消息或内部错误",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Submission": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "messages"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[A-Za-z0-9._:-]+$"
          },
          "messages": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "id",
                "text"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "text": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 8000,
                  "description": "长度以UTF-16代码单元计，非空白且无NUL；原文不进入训练库"
                }
              }
            }
          }
        }
      },
      "Job": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "request_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "succeeded",
              "failed"
            ]
          },
          "message_count": {
            "type": "integer"
          },
          "charged": {
            "type": "string",
            "example": "0.0001"
          },
          "reserved": {
            "type": "string",
            "example": "0.0000"
          },
          "model_version": {
            "type": "string",
            "nullable": true
          },
          "reused": {
            "type": "boolean",
            "description": "提交接口返回，表示已有相同请求"
          },
          "created_at": {
            "type": "integer",
            "format": "int64"
          },
          "completed_at": {
            "type": "integer",
            "format": "int64",
            "nullable": true
          },
          "error": {
            "type": "string",
            "nullable": true
          },
          "results": {
            "type": "array",
            "nullable": true,
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "label": {
                  "type": "string",
                  "enum": [
                    "demand",
                    "demand_reply",
                    "normal",
                    "ad",
                    "sexual_promotion",
                    "duplicate_obscene_ad",
                    "group_admin"
                  ]
                }
              }
            }
          }
        }
      },
      "Message": {
        "type": "object",
        "required": [
          "id",
          "message_id",
          "text",
          "status",
          "created_at",
          "expires_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-f0-9]{32}$"
          },
          "customer_id": {
            "type": "string"
          },
          "request_id": {
            "type": "string",
            "description": "内部任务编号"
          },
          "request_key": {
            "type": "string",
            "description": "客户提交的request_id，列表响应包含"
          },
          "message_id": {
            "type": "string"
          },
          "position": {
            "type": "integer"
          },
          "text": {
            "type": "string"
          },
          "label": {
            "type": "string",
            "nullable": true,
            "enum": [
              "demand",
              "demand_reply",
              "normal",
              "ad",
              "sexual_promotion",
              "duplicate_obscene_ad",
              "group_admin",
              null
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "succeeded",
              "failed"
            ]
          },
          "model_version": {
            "type": "string",
            "nullable": true
          },
          "created_at": {
            "type": "integer",
            "format": "int64"
          },
          "completed_at": {
            "type": "integer",
            "format": "int64",
            "nullable": true
          },
          "expires_at": {
            "type": "integer",
            "format": "int64"
          },
          "charged": {
            "type": "string",
            "example": "0.0001"
          }
        }
      }
    }
  }
}
