{
  "openapi": "3.0.0",
  "info": {
    "title": "YGO API: Generate text",
    "version": "2.0.0"
  },
  "servers": [
    {
      "url": "https://api.ygo.ai",
      "description": "Production and Sandbox (determined by API key)"
    }
  ],
  "paths": {
    "/v2/project/content/generateText": {
      "post": {
        "summary": "Generate text",
        "description": "Queue an asynchronous text-generation run for a selection of the project's hotels and return the created run object.\n\nThe run starts in the `queued` state and is processed in the background. Use the returned run `ID` with `getTextGenerationStatus` to poll its status and progress until it reaches `complete` or `failed`.\n\nHotels are selected by `HotelIDs` and/or `TagIDs` (combined and deduplicated, capped at 100), and every selected hotel must belong to the calling project. If a selected hotel already has a run in progress, the request is rejected with 409.",
        "operationId": "generateText",
        "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/GenerateTextRequest"
              },
              "examples": {
                "byHotelIDs": {
                  "summary": "Regenerate all active templates for two hotels in all template locales",
                  "value": {
                    "HotelIDs": [
                      "0192fb17-5dc6-7abc-8def-123456789abc",
                      "0192fb18-6ed7-7abc-8def-223456789abc"
                    ]
                  }
                },
                "scopedRun": {
                  "summary": "Regenerate only the Summary template, two locales, full regeneration",
                  "value": {
                    "HotelIDs": [
                      "0192fb17-5dc6-7abc-8def-123456789abc"
                    ],
                    "TemplateKeys": [
                      "Summary"
                    ],
                    "Locales": [
                      "en-US",
                      "de-DE"
                    ],
                    "RegenMode": "full"
                  }
                },
                "byTag": {
                  "summary": "Fill missing texts for every project hotel carrying a tag",
                  "value": {
                    "TagIDs": [
                      "0192fb40-7aa1-7abc-8def-aabbccddeeff"
                    ],
                    "RegenMode": "fill_missing"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Text-generation run queued successfully. The run is processed asynchronously; poll getTextGenerationStatus with the returned run ID.",
            "headers": {
              "X-Trace-ID": {
                "$ref": "#/components/headers/X-Trace-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerateTextResponse"
                },
                "examples": {
                  "byHotelIDs": {
                    "summary": "A freshly queued run for two hotels",
                    "value": {
                      "Data": {
                        "ID": "0192fb50-8bb2-7abc-8def-112233445566",
                        "Status": "queued",
                        "Progress": {
                          "Total": 2,
                          "Generated": 0,
                          "Failed": 0,
                          "Skipped": 0
                        },
                        "CreatedAt": "2026-06-26T09:15:00Z",
                        "UpdatedAt": "2026-06-26T09:15:00Z"
                      }
                    }
                  },
                  "scopedRun": {
                    "summary": "A freshly queued scoped run for one hotel",
                    "value": {
                      "Data": {
                        "ID": "0192fb51-9cc3-7abc-8def-2233445566aa",
                        "Status": "queued",
                        "Progress": {
                          "Total": 1,
                          "Generated": 0,
                          "Failed": 0,
                          "Skipped": 0
                        },
                        "CreatedAt": "2026-06-26T09:20:00Z",
                        "UpdatedAt": "2026-06-26T09:20:00Z"
                      }
                    }
                  },
                  "byTag": {
                    "summary": "A freshly queued run resolved from a tag",
                    "value": {
                      "Data": {
                        "ID": "0192fb52-add4-7abc-8def-3344556677bb",
                        "Status": "queued",
                        "Progress": {
                          "Total": 5,
                          "Generated": 0,
                          "Failed": 0,
                          "Skipped": 0
                        },
                        "CreatedAt": "2026-06-26T09:25:00Z",
                        "UpdatedAt": "2026-06-26T09:25:00Z"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "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": "HotelIDs"
          },
          "Message": {
            "type": "string",
            "description": "Human-readable validation error message for this field.",
            "example": "HotelIDs or TagIDs 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
            }
          }
        }
      },
      "GenerateTextRequest": {
        "type": "object",
        "description": "Request body for queuing a text-generation run. At least one of HotelIDs or TagIDs must be provided. HotelIDs and the hotels resolved from TagIDs are combined and deduplicated; the result is capped at 100 hotels.",
        "properties": {
          "HotelIDs": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Explicit hotel UUIDs to generate text for. Each hotel must belong to the calling project; a hotel outside the project's scope returns 404. Required if TagIDs is empty.",
            "example": [
              "0192fb17-5dc6-7abc-8def-123456789abc",
              "0192fb18-6ed7-7abc-8def-223456789abc"
            ]
          },
          "TagIDs": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Tag UUIDs. Hotels carrying ALL of the given tags (intersection) and belonging to the project are added to the selection. Required if HotelIDs is empty.",
            "example": [
              "0192fb40-7aa1-7abc-8def-aabbccddeeff"
            ]
          },
          "TemplateKeys": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Optional subset of active template keys to (re)generate. Each key must be an active template of the project. Empty means all active templates. Maximum 100 keys.",
            "example": [
              "Summary",
              "HouseRules"
            ]
          },
          "Locales": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Optional subset of BCP 47 language tags to generate. Empty means the locales configured on the matched templates (always including en-US).",
            "example": [
              "en-US",
              "de-DE"
            ]
          },
          "RegenMode": {
            "type": "string",
            "enum": [
              "fill_missing",
              "full"
            ],
            "default": "fill_missing",
            "description": "Controls which texts are (re)generated. 'fill_missing' (the default) generates only missing or stale texts; 'full' regenerates every selected text.",
            "example": "fill_missing"
          }
        }
      },
      "GenerateTextResponse": {
        "type": "object",
        "required": [
          "Data"
        ],
        "description": "Single-object response envelope wrapping the queued text-generation run.",
        "properties": {
          "Data": {
            "$ref": "#/components/schemas/TextGenerationRun"
          }
        }
      },
      "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": 2
          },
          "Generated": {
            "type": "integer",
            "description": "Number of hotels for which text has been generated so far.",
            "example": 0
          },
          "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
          }
        }
      },
      "TextGenerationRun": {
        "type": "object",
        "required": [
          "ID",
          "Status",
          "Progress",
          "CreatedAt",
          "UpdatedAt"
        ],
        "description": "A text-generation run with its own status and progress.",
        "properties": {
          "ID": {
            "type": "string",
            "format": "uuid",
            "description": "Unique run UUID. Pass this to getTextGenerationStatus to poll the run.",
            "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": "queued"
          },
          "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:17:30Z"
          },
          "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:15:00Z"
          }
        }
      }
    },
    "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": {
              "missingSelection": {
                "summary": "Neither HotelIDs nor TagIDs provided",
                "value": {
                  "Error": {
                    "Code": "VALIDATION_ERROR",
                    "Message": "Request validation failed",
                    "Fields": [
                      {
                        "Field": "HotelIDs",
                        "Message": "HotelIDs or TagIDs is required"
                      }
                    ]
                  }
                }
              },
              "invalidRegenMode": {
                "summary": "RegenMode not in the allowed set",
                "value": {
                  "Error": {
                    "Code": "VALIDATION_ERROR",
                    "Message": "RegenMode must be 'fill_missing' or 'full'"
                  }
                }
              },
              "unknownTemplateKeys": {
                "summary": "One or more template keys are not active templates of the project",
                "value": {
                  "Error": {
                    "Code": "VALIDATION_ERROR",
                    "Message": "unknown or inactive template keys: Headline"
                  }
                }
              },
              "tooManyHotels": {
                "summary": "Selection exceeds the per-run cap",
                "value": {
                  "Error": {
                    "Code": "VALIDATION_ERROR",
                    "Message": "selection must not exceed 100 hotels"
                  }
                }
              }
            }
          }
        }
      },
      "Conflict": {
        "description": "Conflict - One or more selected hotels already have a text-generation run in progress.",
        "headers": {
          "X-Trace-ID": {
            "$ref": "#/components/headers/X-Trace-ID"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "activeRunExists": {
                "summary": "A hotel already has a run in progress",
                "value": {
                  "Error": {
                    "Code": "ALREADY_EXISTS",
                    "Message": "one or more hotels already have a text-generation run in progress"
                  }
                }
              }
            }
          }
        }
      },
      "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.generation:write 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.generation:write"
                  }
                }
              },
              "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 create text-generation run"
                  }
                }
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "Not Found - One of the selected hotels does not exist or is not in the calling project's scope.",
        "headers": {
          "X-Trace-ID": {
            "$ref": "#/components/headers/X-Trace-ID"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "hotelNotFound": {
                "summary": "A selected hotel is not in the project",
                "value": {
                  "Error": {
                    "Code": "NOT_FOUND",
                    "Message": "hotel 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"
      }
    }
  }
}
