{
  "openapi": "3.1.0",
  "info": {
    "title": "南北绿豆站图片请求 API",
    "version": "20261104.2",
    "description": "按实际出图结果计费. 支持异步提交、幂等重试、状态查询与原结果取回."
  },
  "servers": [
    {
      "url": "https://hajimi.165201.xyz"
    }
  ],
  "security": [
    {
      "ApiKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "ImageRequest": {
        "type": "object",
        "properties": {
          "request_id": {
            "type": "string"
          },
          "generation_status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "completed",
              "failed",
              "unconfirmed",
              "expired"
            ]
          },
          "delivery_status": {
            "type": "string",
            "enum": [
              "waiting",
              "sent",
              "interrupted"
            ]
          },
          "billing": {
            "type": "object",
            "properties": {
              "status": {
                "type": "string",
                "enum": [
                  "pending",
                  "charged",
                  "not_charged"
                ]
              },
              "amount": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "currency": {
                "type": "string",
                "const": "CNY"
              }
            }
          },
          "model": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "status_url": {
            "type": "string"
          },
          "result_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "result_expires_at": {
            "type": [
              "number",
              "null"
            ]
          }
        }
      }
    }
  },
  "paths": {
    "/v1/image-requests": {
      "post": {
        "summary": "异步提交图片任务",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "endpoint",
                  "request"
                ],
                "properties": {
                  "endpoint": {
                    "type": "string",
                    "description": "原出图接口路径"
                  },
                  "request": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "原请求体"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "任务状态",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "$ref": "#/components/schemas/ImageRequest"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "请求格式错误或缺少幂等键"
          },
          "401": {
            "description": "密钥无效"
          },
          "409": {
            "description": "同幂等键对应不同请求内容"
          }
        }
      },
      "get": {
        "summary": "列出当前密钥最近 100 条任务",
        "parameters": [
          {
            "name": "idempotency_key",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "任务列表",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ImageRequest"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/image-requests/{request_id}": {
      "get": {
        "summary": "查询生成与计费状态",
        "parameters": [
          {
            "name": "request_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "任务状态",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "$ref": "#/components/schemas/ImageRequest"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "任务不存在或无权读取"
          }
        }
      }
    },
    "/v1/image-requests/{request_id}/result": {
      "get": {
        "summary": "取回原出图响应, 不再次生成或扣费",
        "parameters": [
          {
            "name": "request_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "原协议的图片结果",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "202": {
            "description": "任务状态",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "$ref": "#/components/schemas/ImageRequest"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "任务不存在或无权读取"
          },
          "410": {
            "description": "结果保存期限已过"
          }
        }
      }
    }
  }
}
