{
  "openapi": "3.0.0",
  "info": {
    "title": "YGO API: Get text generation status",
    "version": "2.0.0"
  },
  "servers": [
    {
      "url": "https://api.ygo.ai",
      "description": "Production and Sandbox (determined by API key)"
    }
  ],
  "paths": {
    "/v2/project/content/getTextGenerationStatus": {
      "post": {
        "summary": "Get text generation status",
        "description": "Retrieve the status and progress of a text-generation run by its UUID. Use this to poll the asynchronous run started by generateText until its Status becomes 'complete' or 'failed'. A run that does not belong to the calling project returns 404.",
        "operationId": "getTextGenerationStatus",
        "tags": [
          "Content Enrichment API/Text Generation"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/X-Project-ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GetTextGenerationStatusRequest"
              },
              "examples": {
                "processing": {
                  "summary": "Poll a run by its UUID (still in progress)",
                  "value": {
                    "RunID": "0192fb50-8bb2-7abc-8def-112233445566"
                  }
                },
                "complete": {
                  "summary": "Poll a run by its UUID (finished)",
                  "value": {
                    "RunID": "0192fb50-8bb2-7abc-8def-112233445566"
                  }
                },
                "failed": {
                  "summary": "Poll a run by its UUID (failed)",
                  "value": {
                    "RunID": "0192fb50-8bb2-7abc-8def-112233445566"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Text-generation run status retrieved successfully.",
            "headers": {
              "X-Trace-ID": {
                "$ref": "#/components/headers/X-Trace-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetTextGenerationStatusResponse"
                },
                "examples": {
                  "processing": {
                    "summary": "A run still in progress",
                    "value": {
                      "Data": {
                        "ID": "0192fb50-8bb2-7abc-8def-112233445566",
                        "Status": "processing",
                        "Progress": {
                          "Total": 5,
                          "Generated": 2,
                          "Failed": 0,
                          "Skipped": 0
                        },
                        "StartedAt": "2026-06-26T09:15:05Z",
                        "CreatedAt": "2026-06-26T09:15:00Z",
                        "UpdatedAt": "2026-06-26T09:16:10Z"
                      }
                    }
                  },
                  "complete": {
                    "summary": "A finished run",
                    "value": {
                      "Data": {
                        "ID": "0192fb50-8bb2-7abc-8def-112233445566",
                        "Status": "complete",
                        "Progress": {
                          "Total": 5,
                          "Generated": 5,
                          "Failed": 0,
                          "Skipped": 0
                        },
                        "StartedAt": "2026-06-26T09:15:05Z",
                        "CompletedAt": "2026-06-26T09:18:42Z",
                        "CreatedAt": "2026-06-26T09:15:00Z",
                        "UpdatedAt": "2026-06-26T09:18:42Z"
                      }
                    }
                  },
                  "failed": {
                    "summary": "A failed run",
                    "value": {
                      "Data": {
                        "ID": "0192fb50-8bb2-7abc-8def-112233445566",
                        "Status": "failed",
                        "Progress": {
                          "Total": 5,
                          "Generated": 1,
                          "Failed": 4,
                          "Skipped": 0
                        },
                        "ErrorMessage": "Text generation failed for one or more hotels",
                        "StartedAt": "2026-06-26T09:15:05Z",
                        "CompletedAt": "2026-06-26T09:16:20Z",
                        "CreatedAt": "2026-06-26T09:15:00Z",
                        "UpdatedAt": "2026-06-26T09:16:20Z"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ErrorDetail": {
        "type": "object",
        "required": [
          "Code",
          "Message"
        ],
        "description": "Error detail containing a machine-readable code and human-readable message.",
        "properties": {
          "Code": {
            "type": "string",
            "description": "Machine-readable error code for programmatic handling.",
            "example": "VALIDATION_ERROR"
          },
          "Message": {
            "type": "string",
            "description": "Human-readable error message.",
            "example": "Request validation failed"
          },
          "Fields": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FieldError"
            },
            "description": "Field-level validation errors. Only present for VALIDATION_ERROR responses."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "Error"
        ],
        "description": "Standard v2 error response wrapper.",
        "properties": {
          "Error": {
            "$ref": "#/components/schemas/ErrorDetail"
          }
        }
      },
      "FieldError": {
        "type": "object",
        "required": [
          "Field",
          "Message"
        ],
        "description": "A single field-level validation error.",
        "properties": {
          "Field": {
            "type": "string",
            "description": "Name of the field that failed validation.",
            "example": "RunID"
          },
          "Message": {
            "type": "string",
            "description": "Human-readable validation error message for this field.",
            "example": "RunID is required"
          },
          "Code": {
            "type": "string",
            "enum": [
              "REQUIRED",
              "TOO_LONG",
              "TOO_SHORT",
              "OUT_OF_RANGE",
              "TOO_MANY",
              "INVALID_FORMAT",
              "NOT_ALLOWED",
              "CONFLICT",
              "INVALID_ENCODING",
              "INSECURE_SCHEME",
              "UNSAFE_CONTENT",
              "REQUIRED_WHEN_ENABLED"
            ],
            "description": "Machine-readable reason the field failed validation. Optional; clients should fall back to Message when it is absent or unrecognized.",
            "example": "TOO_LONG"
          },
          "Params": {
            "type": "object",
            "additionalProperties": true,
            "description": "Machine-readable values the message is built from, such as limits or allowed values. Keys are PascalCase; which keys are present depends on Code. Optional.",
            "example": {
              "Max": 100
            }
          }
        }
      },
      "GetTextGenerationStatusRequest": {
        "type": "object",
        "required": [
          "RunID"
        ],
        "description": "Request body for fetching the status of a single text-generation run.",
        "properties": {
          "RunID": {
            "type": "string",
            "format": "uuid",
            "description": "UUID of the text-generation run to retrieve, as returned by generateText. The run must belong to the calling project.",
            "example": "0192fb50-8bb2-7abc-8def-112233445566"
          }
        }
      },
      "GetTextGenerationStatusResponse": {
        "type": "object",
        "required": [
          "Data"
        ],
        "description": "Single-object response envelope wrapping the text-generation run status.",
        "properties": {
          "Data": {
            "$ref": "#/components/schemas/TextGenerationStatus"
          }
        }
      },
      "RunProgress": {
        "type": "object",
        "required": [
          "Total",
          "Generated",
          "Failed",
          "Skipped"
        ],
        "description": "Per-hotel progress counters for the run.",
        "properties": {
          "Total": {
            "type": "integer",
            "description": "Total number of hotels in the run.",
            "example": 5
          },
          "Generated": {
            "type": "integer",
            "description": "Number of hotels for which text has been generated so far.",
            "example": 2
          },
          "Failed": {
            "type": "integer",
            "description": "Number of hotels that failed processing.",
            "example": 0
          },
          "Skipped": {
            "type": "integer",
            "description": "Number of hotels skipped because they needed no work.",
            "example": 0
          }
        }
      },
      "TextGenerationStatus": {
        "type": "object",
        "required": [
          "ID",
          "Status",
          "Progress",
          "CreatedAt",
          "UpdatedAt"
        ],
        "description": "The status and progress of a text-generation run.",
        "properties": {
          "ID": {
            "type": "string",
            "format": "uuid",
            "description": "Unique run UUID.",
            "example": "0192fb50-8bb2-7abc-8def-112233445566"
          },
          "Status": {
            "type": "string",
            "enum": [
              "queued",
              "processing",
              "complete",
              "failed"
            ],
            "description": "Run lifecycle status. A freshly created run is 'queued'; it transitions to 'processing' while running, then to 'complete' or 'failed'.",
            "example": "processing"
          },
          "Progress": {
            "$ref": "#/components/schemas/RunProgress"
          },
          "ErrorMessage": {
            "type": "string",
            "description": "Human-readable error message when the run has failed. Empty or omitted otherwise.",
            "example": ""
          },
          "StartedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Timestamp when the run started processing (RFC3339). Omitted until the run has started.",
            "example": "2026-06-26T09:15:05Z"
          },
          "CompletedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Timestamp when the run finished (RFC3339). Omitted until the run has finished.",
            "example": "2026-06-26T09:18:42Z"
          },
          "CreatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Timestamp when the run record was created (RFC3339).",
            "example": "2026-06-26T09:15:00Z"
          },
          "UpdatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Timestamp when the run record was last updated (RFC3339).",
            "example": "2026-06-26T09:16:10Z"
          }
        }
      }
    },
    "parameters": {
      "X-Project-ID": {
        "name": "X-Project-ID",
        "in": "header",
        "required": true,
        "description": "Project UUID. Required for all project-scoped endpoints.",
        "example": "$YGO_PROJECT_ID",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    },
    "headers": {
      "Retry-After": {
        "description": "Number of seconds to wait before retrying the request. Present on 429 responses.",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "example": 30
        }
      },
      "X-Trace-ID": {
        "description": "Request trace ID for debugging (OpenTelemetry). Include this ID when contacting support about specific requests.",
        "schema": {
          "type": "string",
          "example": "abc123def456ghi789"
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Bad Request - Validation error or invalid request body.",
        "headers": {
          "X-Trace-ID": {
            "$ref": "#/components/headers/X-Trace-ID"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "missingRunID": {
                "summary": "RunID not provided",
                "value": {
                  "Error": {
                    "Code": "VALIDATION_ERROR",
                    "Message": "Request validation failed",
                    "Fields": [
                      {
                        "Field": "RunID",
                        "Message": "RunID is required"
                      }
                    ]
                  }
                }
              },
              "invalidRunID": {
                "summary": "RunID is not a valid UUID",
                "value": {
                  "Error": {
                    "Code": "VALIDATION_ERROR",
                    "Message": "Invalid RunID format"
                  }
                }
              },
              "invalidBody": {
                "summary": "Malformed request body",
                "value": {
                  "Error": {
                    "Code": "VALIDATION_ERROR",
                    "Message": "Invalid request body"
                  }
                }
              }
            }
          }
        }
      },
      "Forbidden": {
        "description": "Forbidden - Valid API key but insufficient permissions for this operation. Also returned with code INSUFFICIENT_SCOPE when the API key does not carry the content.authoring:read permission this endpoint requires.",
        "headers": {
          "X-Trace-ID": {
            "$ref": "#/components/headers/X-Trace-ID"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "insufficientScope": {
                "summary": "Missing required scope",
                "value": {
                  "Error": {
                    "Code": "INSUFFICIENT_SCOPE",
                    "Message": "token lacks scope content.authoring:read"
                  }
                }
              },
              "noProjectAccess": {
                "summary": "Project access required",
                "value": {
                  "Error": {
                    "Code": "FORBIDDEN",
                    "Message": "Project access required"
                  }
                }
              }
            }
          }
        }
      },
      "InternalServerError": {
        "description": "Internal Server Error - Unexpected server error. Include the X-Trace-ID header value when contacting support.",
        "headers": {
          "X-Trace-ID": {
            "$ref": "#/components/headers/X-Trace-ID"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "internalError": {
                "summary": "Internal server error",
                "value": {
                  "Error": {
                    "Code": "INTERNAL_ERROR",
                    "Message": "Failed to load text-generation run"
                  }
                }
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "Not Found - The run does not exist or is not owned by the calling project.",
        "headers": {
          "X-Trace-ID": {
            "$ref": "#/components/headers/X-Trace-ID"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "runNotFound": {
                "summary": "Text-generation run not found",
                "value": {
                  "Error": {
                    "Code": "NOT_FOUND",
                    "Message": "Text-generation run not found"
                  }
                }
              }
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "Too Many Requests. The response includes a `Retry-After` header with the number of seconds to wait before retrying.",
        "headers": {
          "X-Trace-ID": {
            "$ref": "#/components/headers/X-Trace-ID"
          },
          "Retry-After": {
            "$ref": "#/components/headers/Retry-After"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "rateLimited": {
                "summary": "Limit exceeded",
                "value": {
                  "Error": {
                    "Code": "RATE_LIMIT_EXCEEDED",
                    "Message": "Rate limit exceeded. Retry after the number of seconds in the Retry-After header."
                  }
                }
              }
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Unauthorized - Invalid or missing API key.",
        "headers": {
          "X-Trace-ID": {
            "$ref": "#/components/headers/X-Trace-ID"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "invalidKey": {
                "summary": "Invalid API key",
                "value": {
                  "Error": {
                    "Code": "UNAUTHORIZED",
                    "Message": "Invalid API key"
                  }
                }
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Project-scoped API key"
      }
    }
  }
}
