{
  "openapi": "3.1.0",
  "info": {
    "title": "Giky API Task API",
    "version": "1.0.0",
    "description": "Asynchronous image and video generation. Use enabled, priced model configurations. Tasks are scoped to the submitting API key. Prepaid balance purchases are available through the signed-in account workspace."
  },
  "security": [
    {
      "apiKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              }
            }
          }
        }
      },
      "Task": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "enum": [
              "queued",
              "submitting",
              "running",
              "succeeded",
              "failed",
              "needs_review"
            ]
          },
          "error_code": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "CreateTask": {
        "type": "object",
        "required": [
          "model",
          "operation",
          "input"
        ],
        "additionalProperties": false,
        "properties": {
          "model": {
            "type": "string",
            "description": "Exact public catalog slug"
          },
          "operation": {
            "type": "string"
          },
          "input": {
            "type": "object",
            "description": "Exact schema from GET /api/catalog; extra input fields are rejected"
          },
          "callback": {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "endpoint_id"
                ],
                "additionalProperties": false,
                "properties": {
                  "endpoint_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "description": "Endpoint created in the signed-in Webhooks dashboard."
              },
              {
                "type": "object",
                "required": [
                  "url",
                  "secret"
                ],
                "additionalProperties": false,
                "description": "Legacy integration on an administrator-approved origin.",
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "secret": {
                    "type": "string",
                    "minLength": 32
                  }
                }
              }
            ]
          }
        }
      }
    }
  },
  "paths": {
    "/v1/tasks": {
      "get": {
        "summary": "List tasks owned by this API key",
        "parameters": [
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "in": "query",
            "name": "before",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque cursor from next_cursor; ordering is stable by UUID, not creation time"
          }
        ],
        "responses": {
          "200": {
            "description": "data and next_cursor"
          },
          "401": {
            "description": "Invalid, expired, disabled or IP-restricted key"
          },
          "429": {
            "description": "Rate limit; Retry-After is in seconds"
          }
        }
      },
      "post": {
        "summary": "Create an asynchronous generation task",
        "description": "May incur a generation charge. HTTP 202 acknowledges task creation, not completion. Preserve idempotency key and request body across uncertain submit responses.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTask"
              },
              "example": {
                "model": "seedream-5-flash",
                "operation": "text-to-image",
                "input": {
                  "prompt": "A blue cup on a white table",
                  "resolution": "2K"
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Task accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input or idempotency key"
          },
          "401": {
            "description": "Invalid or restricted key"
          },
          "409": {
            "description": "Configuration changed or idempotency conflict"
          },
          "413": {
            "description": "Body exceeds 64 KiB"
          },
          "415": {
            "description": "Uncompressed JSON required"
          },
          "429": {
            "description": "Rate limited; Retry-After seconds"
          },
          "503": {
            "description": "Service unavailable; submission may be uncertain"
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{8,128}$"
            }
          }
        ]
      }
    },
    "/v1/tasks/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Read a task without exposing prompt, credentials or callback secrets",
        "responses": {
          "200": {
            "description": "Task",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                }
              }
            }
          },
          "404": {
            "description": "Task absent or belongs to a different API key"
          }
        }
      }
    },
    "/v1/tasks/{id}/events": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Read callback delivery status, attempts and next retry time",
        "responses": {
          "200": {
            "description": "Delivery records without destination credentials"
          },
          "404": {
            "description": "Task not found"
          }
        }
      }
    },
    "/v1/tasks/{id}/cancel": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "summary": "Cancel an unsubmitted queued task",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cancelled before submission; no financial operation"
          },
          "409": {
            "description": "Cannot cancel an already claimed or submitted task"
          }
        }
      }
    },
    "/api/catalog": {
      "get": {
        "summary": "Public model catalog, parameters and published USD prices",
        "security": [],
        "responses": {
          "200": {
            "description": "Currency and public models",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "currency",
                    "models"
                  ],
                  "properties": {
                    "currency": {
                      "const": "USD"
                    },
                    "models": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "slug",
                          "name",
                          "kind",
                          "parameters",
                          "prices",
                          "generationAvailable"
                        ],
                        "properties": {
                          "slug": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "kind": {
                            "type": "string"
                          },
                          "parameters": {
                            "type": "object"
                          },
                          "prices": {
                            "type": "array",
                            "items": {
                              "type": "object"
                            }
                          },
                          "generationAvailable": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Catalog unavailable"
          }
        }
      }
    }
  },
  "servers": [
    {
      "url": "https://gikyapi.com"
    }
  ]
}
