{
  "openapi": "3.1.0",
  "info": {
    "title": "NoAIVibe API",
    "version": "0.1.0",
    "description": "API for creating NoAIVibe image processing jobs, checking status, and downloading completed results."
  },
  "servers": [
    {
      "url": "https://noaivibe.com"
    }
  ],
  "paths": {
    "/api/v1/uploads": {
      "post": {
        "summary": "Upload an image for automation",
        "operationId": "uploadImage",
        "security": [
          {
            "apiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UploadImageRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Image uploaded and ready for job creation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadImageResponse"
                }
              }
            }
          },
          "400": {
            "description": "Unsupported file type or malformed upload."
          }
        }
      }
    },
    "/api/v1/images/jobs": {
      "post": {
        "summary": "Create an image processing job",
        "operationId": "createImageJob",
        "security": [
          {
            "apiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateImageJobRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted and credits reserved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateImageJobResponse"
                }
              }
            }
          },
          "402": {
            "description": "Not enough credits."
          }
        }
      }
    },
    "/api/v1/images/generate": {
      "post": {
        "summary": "Create an image generation and enhancement job",
        "operationId": "createImageGenerationJob",
        "security": [
          {
            "apiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateImageGenerationRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Generation job accepted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateImageJobResponse"
                }
              }
            }
          },
          "402": {
            "description": "Not enough credits."
          }
        }
      }
    },
    "/api/v1/text/polish": {
      "post": {
        "summary": "Polish publishing copy",
        "operationId": "polishText",
        "security": [
          {
            "apiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TextPolishRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Text polished and one credit spent.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TextPolishResponse"
                }
              }
            }
          },
          "402": {
            "description": "Not enough credits."
          }
        }
      }
    },
    "/api/v1/images/jobs/{job_id}": {
      "get": {
        "summary": "Get image job status",
        "operationId": "getImageJob",
        "security": [
          {
            "apiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/JobId"
          }
        ],
        "responses": {
          "200": {
            "description": "Job status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImageJob"
                }
              }
            }
          },
          "404": {
            "description": "Job not found."
          }
        }
      }
    },
    "/api/v1/images/jobs/{job_id}/download": {
      "get": {
        "summary": "Download a completed image result",
        "operationId": "downloadImageResult",
        "security": [
          {
            "apiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/JobId"
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to a signed result URL."
          },
          "409": {
            "description": "Job is not complete yet."
          }
        }
      }
    },
    "/api/v1/api-keys": {
      "get": {
        "summary": "List account API keys",
        "operationId": "listApiKeys",
        "security": [
          {
            "cookieSessionAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "API key metadata and per-key usage for the current account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListApiKeysResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create an API key for automation",
        "operationId": "createApiKey",
        "security": [
          {
            "cookieSessionAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "images:write",
                        "images:read",
                        "text:write"
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "API key created. The secret is shown once.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateApiKeyResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/api-keys/{key_id}": {
      "delete": {
        "summary": "Delete an API key",
        "operationId": "deleteApiKey",
        "security": [
          {
            "cookieSessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "key_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "API key deleted. Historical usage remains visible.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "key"
                  ],
                  "properties": {
                    "key": {
                      "$ref": "#/components/schemas/ApiKey"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "API key not found."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "Use `Bearer noaivibe_live_...`."
      },
      "cookieSessionAuth": {
        "type": "apiKey",
        "in": "cookie",
        "name": "noaivibe_session",
        "description": "Browser session cookie for account management endpoints."
      }
    },
    "parameters": {
      "JobId": {
        "name": "job_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "UploadImageRequest": {
        "type": "object",
        "required": [
          "filename",
          "content_type",
          "data_base64"
        ],
        "properties": {
          "filename": {
            "type": "string"
          },
          "content_type": {
            "type": "string",
            "enum": [
              "image/jpeg",
              "image/png",
              "image/webp"
            ]
          },
          "data_base64": {
            "type": "string",
            "description": "Base64-encoded image bytes."
          }
        }
      },
      "UploadImageResponse": {
        "type": "object",
        "required": [
          "image_url",
          "storage_key",
          "size",
          "content_type"
        ],
        "properties": {
          "image_url": {
            "type": "string",
            "format": "uri"
          },
          "storage_key": {
            "type": "string"
          },
          "size": {
            "type": "integer"
          },
          "content_type": {
            "type": "string"
          }
        }
      },
      "CreateImageJobRequest": {
        "type": "object",
        "required": [
          "mode",
          "image_url"
        ],
        "properties": {
          "mode": {
            "type": "string",
            "enum": [
              "clean",
              "realistic"
            ]
          },
          "image_url": {
            "type": "string",
            "format": "uri"
          },
          "output_scale": {
            "type": "integer",
            "enum": [
              1,
              2,
              3,
              4
            ],
            "default": 1
          },
          "webhook_url": {
            "type": "string",
            "format": "uri"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "CreateImageGenerationRequest": {
        "type": "object",
        "required": [
          "prompt"
        ],
        "properties": {
          "prompt": {
            "type": "string"
          },
          "mode": {
            "type": "string",
            "enum": [
              "realistic",
              "clean"
            ],
            "default": "realistic"
          },
          "output_scale": {
            "type": "integer",
            "enum": [
              1,
              2,
              3,
              4
            ],
            "default": 1
          },
          "webhook_url": {
            "type": "string",
            "format": "uri"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "TextPolishRequest": {
        "type": "object",
        "required": [
          "text"
        ],
        "properties": {
          "text": {
            "type": "string"
          }
        }
      },
      "TextPolishResponse": {
        "type": "object",
        "required": [
          "status",
          "id",
          "text",
          "ledger"
        ],
        "properties": {
          "status": {
            "type": "integer",
            "enum": [
              200
            ]
          },
          "id": {
            "type": "string"
          },
          "text": {
            "type": "string"
          },
          "ledger": {
            "$ref": "#/components/schemas/LedgerSnapshot"
          }
        }
      },
      "ImageJob": {
        "type": "object",
        "required": [
          "id",
          "type",
          "mode",
          "status",
          "cost"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "enhance_image",
              "generate_then_enhance"
            ]
          },
          "mode": {
            "type": "string",
            "enum": [
              "clean",
              "realistic"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "processing",
              "completed",
              "failed"
            ]
          },
          "cost": {
            "type": "integer"
          },
          "imageUrl": {
            "type": "string",
            "format": "uri"
          },
          "resultUrl": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "webhookUrl": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          },
          "error": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "LedgerSnapshot": {
        "type": "object",
        "required": [
          "balance"
        ],
        "properties": {
          "balance": {
            "type": "integer"
          }
        }
      },
      "CreateImageJobResponse": {
        "type": "object",
        "required": [
          "status",
          "job",
          "ledger"
        ],
        "properties": {
          "status": {
            "type": "integer",
            "enum": [
              202
            ]
          },
          "job": {
            "$ref": "#/components/schemas/ImageJob"
          },
          "ledger": {
            "$ref": "#/components/schemas/LedgerSnapshot"
          }
        }
      },
      "ApiKeyUsage": {
        "type": "object",
        "required": [
          "credits_spent",
          "jobs_count",
          "text_requests_count",
          "last_used_at"
        ],
        "properties": {
          "credits_spent": {
            "type": "integer"
          },
          "jobs_count": {
            "type": "integer"
          },
          "text_requests_count": {
            "type": "integer"
          },
          "last_used_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "ApiKey": {
        "type": "object",
        "required": [
          "id",
          "name",
          "scopes",
          "prefix",
          "created_at",
          "status",
          "usage"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "images:write",
                "images:read",
                "text:write"
              ]
            }
          },
          "prefix": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "revoked_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "deleted_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "revoked",
              "deleted"
            ]
          },
          "usage": {
            "$ref": "#/components/schemas/ApiKeyUsage"
          }
        }
      },
      "ListApiKeysResponse": {
        "type": "object",
        "required": [
          "keys"
        ],
        "properties": {
          "keys": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ApiKey"
            }
          }
        }
      },
      "CreateApiKeyResponse": {
        "type": "object",
        "required": [
          "api_key",
          "key"
        ],
        "properties": {
          "api_key": {
            "type": "string"
          },
          "key": {
            "$ref": "#/components/schemas/ApiKey"
          }
        }
      }
    }
  }
}