{
  "openapi": "3.0.3",
  "info": {
    "title": "TZ 图片 API",
    "version": "2026-11-19",
    "description": "图片模型按各自原生能力接受精确比例与分辨率组合；请查随附 native_outputs，不提供未验证的 Agent 扩展。"
  },
  "servers": [
    {
      "url": "https://new.tangzhi.org/v1"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/images/generations": {
      "post": {
        "operationId": "generateImage",
        "summary": "文生图 / JSON 参考图生成",
        "description": "同步返回。edits 必须有参考图。统一画布字段需成对提交。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImageRequest"
              },
              "example": {
                "model": "openai/gpt-image-2",
                "prompt": "白色桌面上的蓝色陶瓷杯，柔和自然光",
                "n": 1,
                "response_format": "url",
                "parameters": {
                  "output_ratio": "1:1",
                  "output_resolution": "1K",
                  "quality": "medium"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "生成完成；data 可能包含多张图片。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImageResponse"
                }
              }
            }
          },
          "default": {
            "description": "错误；客户端超时不代表任务取消。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/images/edits": {
      "post": {
        "operationId": "editImage",
        "summary": "参考图生成 / 编辑",
        "description": "同步返回。edits 必须有参考图。统一画布字段需成对提交。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImageRequest"
              },
              "example": {
                "model": "openai/gpt-image-2",
                "prompt": "白色桌面上的蓝色陶瓷杯，柔和自然光",
                "n": 1,
                "response_format": "url",
                "parameters": {
                  "output_ratio": "1:1",
                  "output_resolution": "1K",
                  "quality": "medium"
                },
                "images": [
                  "https://your-cdn.example/reference.png"
                ]
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/MultipartImageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "生成完成；data 可能包含多张图片。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImageResponse"
                }
              }
            }
          },
          "default": {
            "description": "错误；客户端超时不代表任务取消。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/models": {
      "get": {
        "operationId": "listModels",
        "summary": "获取当前令牌可访问的全部模型",
        "responses": {
          "200": {
            "description": "模型条目的 id 用于请求。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/tasks/{task_id}": {
      "get": {
        "operationId": "getImageTaskStatus",
        "summary": "已知任务 ID 时查询任务状态，不返回图片数组",
        "parameters": [
          {
            "name": "task_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "任务状态",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "task_id": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string"
                    },
                    "progress": {
                      "type": "string"
                    },
                    "fail_reason": {
                      "type": "string"
                    },
                    "created_at": {
                      "type": "integer"
                    },
                    "finished_at": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "任务不存在或当前用户不可见"
          }
        }
      }
    },
    "/chat/completions": {
      "post": {
        "summary": "Agent 文本对话，成功每次¥0.01",
        "operationId": "agentTextChat",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "messages"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "enum": [
                      "agent"
                    ]
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "role",
                        "content"
                      ],
                      "properties": {
                        "role": {
                          "type": "string",
                          "enum": [
                            "system",
                            "user",
                            "assistant"
                          ]
                        },
                        "content": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "stream": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OpenAI兼容文本结果或SSE分块文本；非图片模型响应。"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "ImageRequest": {
        "type": "object",
        "required": [
          "model",
          "prompt"
        ],
        "additionalProperties": false,
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "vertex/nano-banana-2-1",
              "vertex/nano-banana-2",
              "openai/gpt-image-2",
              "openai/gpt-image-2-5-sunburst",
              "openai/gpt-image-2-5-flare",
              "openai/gpt-image-2-6-sunburst",
              "openai/gpt-image-2-6-flare",
              "seedream/seedream-5-0-pro",
              "luma/uni-1-max",
              "bfl/flux-3-image",
              "fal/flux-2-pro",
              "fal/flux-2-max",
              "seedream/seedream-5-0",
              "seedream/seedream-4-5",
              "qwenimage/qwen-image-3-0-pro",
              "qwenimage/qwen-image-3-0",
              "youchuan/midjourney",
              "luma/uni-1",
              "vertex/anon-bob",
              "seedream/seedream-5-5",
              "minimax/minimax-h3-image",
              "vertex/nano-banana-2-lite",
              "seedream/seedream-4-0",
              "minimax/minimax-h3-image-highspeed",
              "kling/kling-image-4-0"
            ]
          },
          "prompt": {
            "type": "string",
            "minLength": 1,
            "description": "非空提示词；字符上限按模型分别确定。"
          },
          "n": {
            "type": "integer",
            "enum": [
              1
            ],
            "default": 1
          },
          "response_format": {
            "type": "string",
            "enum": [
              "url",
              "b64_json"
            ],
            "default": "url"
          },
          "images": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "HTTPS 图片 URL 或 png/jpeg/webp data URL；数量上限按模型。"
          },
          "parameters": {
            "type": "object",
            "description": "仅接受所选模型 native_outputs 内的比例与分辨率精确组合，以及该模型声明的控制字段。",
            "properties": {
              "output_ratio": {
                "type": "string",
                "enum": [
                  "1:1",
                  "3:2",
                  "2:3",
                  "4:3",
                  "3:4",
                  "5:4",
                  "4:5",
                  "16:9",
                  "9:16",
                  "21:9",
                  "9:21",
                  "2:1",
                  "1:2",
                  "3:1",
                  "1:3",
                  "4:1",
                  "1:4",
                  "8:1",
                  "1:8",
                  "1.91:1",
                  "auto"
                ]
              },
              "output_resolution": {
                "type": "string",
                "enum": [
                  "512",
                  "768",
                  "1K",
                  "1.5K",
                  "2K",
                  "3K",
                  "4K",
                  "auto",
                  "8K"
                ],
                "description": "8K 仅支持 Kling Image 4.0，其余按模型枚举。"
              }
            },
            "additionalProperties": true
          }
        }
      },
      "ImageResponse": {
        "type": "object",
        "required": [
          "created",
          "data"
        ],
        "properties": {
          "created": {
            "type": "integer",
            "format": "int64"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string"
                },
                "b64_json": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "code": {
                "type": "string"
              }
            }
          }
        }
      },
      "MultipartImageRequest": {
        "type": "object",
        "required": [
          "model",
          "prompt",
          "image"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "vertex/nano-banana-2-1",
              "vertex/nano-banana-2",
              "openai/gpt-image-2",
              "openai/gpt-image-2-5-sunburst",
              "openai/gpt-image-2-5-flare",
              "openai/gpt-image-2-6-sunburst",
              "openai/gpt-image-2-6-flare",
              "seedream/seedream-5-0-pro",
              "luma/uni-1-max",
              "bfl/flux-3-image",
              "fal/flux-2-pro",
              "fal/flux-2-max",
              "seedream/seedream-5-0",
              "seedream/seedream-4-5",
              "qwenimage/qwen-image-3-0-pro",
              "qwenimage/qwen-image-3-0",
              "youchuan/midjourney",
              "luma/uni-1",
              "vertex/anon-bob",
              "seedream/seedream-5-5",
              "minimax/minimax-h3-image",
              "vertex/nano-banana-2-lite",
              "seedream/seedream-4-0",
              "minimax/minimax-h3-image-highspeed",
              "kling/kling-image-4-0"
            ]
          },
          "prompt": {
            "type": "string"
          },
          "n": {
            "type": "integer",
            "enum": [
              1
            ]
          },
          "response_format": {
            "type": "string",
            "enum": [
              "url",
              "b64_json"
            ]
          },
          "parameters": {
            "type": "string",
            "description": "JSON 编码的参数对象"
          },
          "image": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "binary"
            },
            "description": "重复 image 字段上传；每张8 MiB，合计28 MiB，数量按模型限制。"
          }
        }
      }
    }
  }
}
