{
  "openapi": "3.1.0",
  "info": {
    "title": "中转神探 开放API",
    "description": "中转神探 开放API：通过 AppID + ApiSecret（HMAC-SHA256 签名）访问站点/分组/模型数据。\n\n签名步骤：\n1. 构造签名串（固定 7 行 \\n 拼接）：METHOD、PATH、按 key 排序的 query、X-App-Id、X-Timestamp、X-Nonce、body 摘要（GET 无 body 为空串）；\n2. signature = HMAC-SHA256(api_secret, 签名串).hexdigest()；\n3. 请求头携带 X-App-Id / X-Timestamp / X-Nonce / X-Signature。\n时间戳须在 ±300 秒内，nonce 不可重复（防重放）。详见 C 端「开放API」文档页。",
    "version": "1.0.0"
  },
  "paths": {
    "/openapi/site": {
      "get": {
        "tags": [
          "openapi"
        ],
        "summary": "按 URL/API URL 查询站点详情",
        "operationId": "openapi_get_site_by_url",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "description": "站点域名 或 站点URL 或 API URL",
              "title": "Url"
            },
            "description": "站点域名 或 站点URL 或 API URL"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenApiEnvelope_OpenApiSiteInfo_"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/openapi/groups": {
      "get": {
        "tags": [
          "openapi"
        ],
        "summary": "按站点 ID 查询其下分组",
        "operationId": "openapi_get_groups_by_site",
        "parameters": [
          {
            "name": "site_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "description": "站点 ID",
              "title": "Site Id"
            },
            "description": "站点 ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenApiEnvelope_list_OpenApiGroupInfo__"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/openapi/group-stat": {
      "get": {
        "tags": [
          "openapi"
        ],
        "summary": "按分组 ID 查询模型状态",
        "operationId": "openapi_group_stat",
        "parameters": [
          {
            "name": "group_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "description": "分组 ID",
              "title": "Group Id"
            },
            "description": "分组 ID"
          },
          {
            "name": "model_key",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "可选：仅返回该模型的状态",
              "title": "Model Key"
            },
            "description": "可选：仅返回该模型的状态"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenApiEnvelope_list_OpenApiModelStat__"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/openapi/query-groups": {
      "get": {
        "tags": [
          "openapi"
        ],
        "summary": "按条件筛选站点+分组（最多 5 个站点）",
        "operationId": "openapi_query_groups",
        "parameters": [
          {
            "name": "model_key",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "模型 key",
              "title": "Model Key"
            },
            "description": "模型 key"
          },
          {
            "name": "model_family",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "模型家族（如 claude / gpt）",
              "title": "Model Family"
            },
            "description": "模型家族（如 claude / gpt）"
          },
          {
            "name": "max_ratio",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "number"
                },
                {
                  "type": "null"
                }
              ],
              "description": "最大倍率",
              "title": "Max Ratio"
            },
            "description": "最大倍率"
          },
          {
            "name": "max_ttft",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "number"
                },
                {
                  "type": "null"
                }
              ],
              "description": "最大平均响应延迟（秒，近似 ttft）",
              "title": "Max Ttft"
            },
            "description": "最大平均响应延迟（秒，近似 ttft）"
          },
          {
            "name": "min_success_rate",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "number"
                },
                {
                  "type": "null"
                }
              ],
              "description": "最小在线率（%，近似成功率）",
              "title": "Min Success Rate"
            },
            "description": "最小在线率（%，近似成功率）"
          },
          {
            "name": "min_concurrency",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "null"
                }
              ],
              "description": "最小并发数限制",
              "title": "Min Concurrency"
            },
            "description": "最小并发数限制"
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "排序字段：ratio(升序,默认) / ttft(升序) / success_rate(降序) / concurrency(降序)",
              "title": "Sort"
            },
            "description": "排序字段：ratio(升序,默认) / ttft(升序) / success_rate(降序) / concurrency(降序)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenApiEnvelope_list_OpenApiQueryGroupsItem__"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": {
              "$ref": "#/components/schemas/ValidationError"
            },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      },
      "OpenApiEnvelope_OpenApiSiteInfo_": {
        "properties": {
          "code": {
            "type": "string",
            "title": "Code",
            "description": "成功为 \"0\"，失败为业务错误码",
            "default": "0"
          },
          "message": {
            "type": "string",
            "title": "Message",
            "description": "人类可读的提示信息",
            "default": "ok"
          },
          "data": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/OpenApiSiteInfo"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "type": "object",
        "title": "OpenApiEnvelope[OpenApiSiteInfo]"
      },
      "OpenApiEnvelope_list_OpenApiGroupInfo__": {
        "properties": {
          "code": {
            "type": "string",
            "title": "Code",
            "description": "成功为 \"0\"，失败为业务错误码",
            "default": "0"
          },
          "message": {
            "type": "string",
            "title": "Message",
            "description": "人类可读的提示信息",
            "default": "ok"
          },
          "data": {
            "anyOf": [
              {
                "items": {
                  "$ref": "#/components/schemas/OpenApiGroupInfo"
                },
                "type": "array"
              },
              {
                "type": "null"
              }
            ],
            "title": "Data"
          }
        },
        "type": "object",
        "title": "OpenApiEnvelope[list[OpenApiGroupInfo]]"
      },
      "OpenApiEnvelope_list_OpenApiModelStat__": {
        "properties": {
          "code": {
            "type": "string",
            "title": "Code",
            "description": "成功为 \"0\"，失败为业务错误码",
            "default": "0"
          },
          "message": {
            "type": "string",
            "title": "Message",
            "description": "人类可读的提示信息",
            "default": "ok"
          },
          "data": {
            "anyOf": [
              {
                "items": {
                  "$ref": "#/components/schemas/OpenApiModelStat"
                },
                "type": "array"
              },
              {
                "type": "null"
              }
            ],
            "title": "Data"
          }
        },
        "type": "object",
        "title": "OpenApiEnvelope[list[OpenApiModelStat]]"
      },
      "OpenApiEnvelope_list_OpenApiQueryGroupsItem__": {
        "properties": {
          "code": {
            "type": "string",
            "title": "Code",
            "description": "成功为 \"0\"，失败为业务错误码",
            "default": "0"
          },
          "message": {
            "type": "string",
            "title": "Message",
            "description": "人类可读的提示信息",
            "default": "ok"
          },
          "data": {
            "anyOf": [
              {
                "items": {
                  "$ref": "#/components/schemas/OpenApiQueryGroupsItem"
                },
                "type": "array"
              },
              {
                "type": "null"
              }
            ],
            "title": "Data"
          }
        },
        "type": "object",
        "title": "OpenApiEnvelope[list[OpenApiQueryGroupsItem]]"
      },
      "OpenApiGroupInfo": {
        "properties": {
          "group_id": {
            "type": "integer",
            "title": "Group Id",
            "description": "分组 ID"
          },
          "group_name": {
            "type": "string",
            "title": "Group Name",
            "description": "分组（渠道）名称"
          },
          "ratio": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "title": "Ratio",
            "description": "计价倍率（相对官方基准价的加价比例）"
          },
          "models": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Models",
            "description": "分组提供的模型 key 列表"
          },
          "concurrency_limit": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Concurrency Limit",
            "description": "分组并发数限制（当前采集未填充时为 null）"
          }
        },
        "type": "object",
        "required": [
          "group_id",
          "group_name"
        ],
        "title": "OpenApiGroupInfo",
        "description": "分组详情"
      },
      "OpenApiModelStat": {
        "properties": {
          "model_key": {
            "type": "string",
            "title": "Model Key",
            "description": "模型 key"
          },
          "model_family": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Model Family",
            "description": "模型家族（如 claude / gpt）"
          },
          "model_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Model Name",
            "description": "模型展示名"
          },
          "available": {
            "type": "boolean",
            "title": "Available",
            "description": "当前是否可用（分组健康且站点未 outage）"
          },
          "ttft_p50_ms": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "title": "Ttft P50 Ms",
            "description": "首 token 时间全网基准中位数（毫秒，跨站可比；非该站实测值）"
          },
          "avg_latency_s": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "title": "Avg Latency S",
            "description": "该站该模型平均响应延迟（秒，实测）"
          },
          "online_rate": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "title": "Online Rate",
            "description": "在线率（%，检测结果聚合）"
          },
          "success_rate": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "title": "Success Rate",
            "description": "AI 请求成功率全网基准（%，跨站可比）"
          }
        },
        "type": "object",
        "required": [
          "model_key",
          "available"
        ],
        "title": "OpenApiModelStat",
        "description": "模型状态（分组下某模型的当前可用状态与性能指标）"
      },
      "OpenApiQueryGroupsItem": {
        "properties": {
          "site": {
            "$ref": "#/components/schemas/OpenApiSiteInfo"
          },
          "groups": {
            "items": {
              "$ref": "#/components/schemas/OpenApiGroupInfo"
            },
            "type": "array",
            "title": "Groups",
            "description": "符合条件的分组列表"
          }
        },
        "type": "object",
        "required": [
          "site"
        ],
        "title": "OpenApiQueryGroupsItem",
        "description": "queryGroups 返回项：一个站点及其下符合条件的分组"
      },
      "OpenApiSiteInfo": {
        "properties": {
          "site_id": {
            "type": "integer",
            "title": "Site Id",
            "description": "站点 ID"
          },
          "site_name": {
            "type": "string",
            "title": "Site Name",
            "description": "站点名称"
          },
          "url": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Url",
            "description": "站点首页 URL"
          },
          "api_urls": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Api Urls",
            "description": "站点 API URL 列表（主/备）"
          }
        },
        "type": "object",
        "required": [
          "site_id",
          "site_name"
        ],
        "title": "OpenApiSiteInfo",
        "description": "站点详情"
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "type": "array",
            "title": "Location"
          },
          "msg": {
            "type": "string",
            "title": "Message"
          },
          "type": {
            "type": "string",
            "title": "Error Type"
          },
          "input": {
            "title": "Input"
          },
          "ctx": {
            "type": "object",
            "title": "Context"
          }
        },
        "type": "object",
        "required": [
          "loc",
          "msg",
          "type"
        ],
        "title": "ValidationError"
      }
    },
    "securitySchemes": {
      "HmacSignature": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Signature",
        "description": "HMAC-SHA256 签名，需配合 X-App-Id / X-Timestamp / X-Nonce 请求头"
      }
    }
  },
  "security": [
    {
      "HmacSignature": []
    }
  ]
}