{
  "openapi": "3.1.0",
  "info": {
    "title": "Ranklify API",
    "version": "1.0.0",
    "description": "Generate platform-optimized product listings for Amazon, Shopify, and WooCommerce. API access requires an Agency plan. Full docs: https://www.getranklify.com/developers",
    "contact": { "name": "Ranklify Support", "url": "https://www.getranklify.com/contact" }
  },
  "servers": [
    { "url": "https://www.getranklify.com/api/v1", "description": "Production (always use the www host)" }
  ],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/generate": {
      "post": {
        "summary": "Generate a listing",
        "description": "Generates a single optimized product listing and files it under the account (optionally a specific brand workspace). Rate limited to 10 requests/min per key. Each success counts against the plan's monthly quota.",
        "operationId": "generateListing",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/GenerateRequest" },
              "example": {
                "product_name": "Stainless Steel Pour-Over Kettle",
                "features": "Gooseneck spout, 1L, food-grade steel, keeps heat",
                "platform": "amazon",
                "tone": "Professional"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Listing generated",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GenerateResponse" } } }
          },
          "400": { "description": "invalid_json or validation_error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "401": { "description": "missing_authorization or invalid_api_key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "403": { "description": "plan_required, brand_forbidden, or usage_limit_reached", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "410": { "description": "brand_archived", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "rate_limited", "headers": { "Retry-After": { "schema": { "type": "integer" }, "description": "Seconds to wait" } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "500": { "description": "internal_error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key from /api-keys, sent as `Authorization: Bearer lfy_...`. Agency plan required."
      }
    },
    "schemas": {
      "GenerateRequest": {
        "type": "object",
        "required": ["product_name", "features"],
        "properties": {
          "product_name": { "type": "string", "maxLength": 200 },
          "features": { "type": "string", "maxLength": 600, "description": "Key features / selling points." },
          "platform": { "type": "string", "enum": ["amazon", "shopify", "woocommerce"], "default": "amazon" },
          "tone": { "type": "string", "enum": ["Professional", "Energetic", "Friendly", "Luxury", "Technical", "Playful", "Bold", "Minimalist"], "default": "Professional" },
          "category": { "type": "string", "maxLength": 100 },
          "price": { "type": "string", "maxLength": 100, "description": "Free-text price context, not a number." },
          "customer": { "type": "string", "maxLength": 500, "description": "Target customer & use cases." },
          "competitors": { "type": "string", "maxLength": 300, "description": "Competitor URLs or market context." },
          "brand_id": { "type": "string", "description": "Workspace/brand to file the listing under. Defaults to the active brand." }
        }
      },
      "GenerateResponse": {
        "type": "object",
        "properties": {
          "api_version": { "type": "string", "example": "v1" },
          "listing": { "$ref": "#/components/schemas/Listing" },
          "listing_id": { "type": "string" },
          "platform": { "type": "string", "enum": ["amazon", "shopify", "woocommerce"] },
          "tone": { "type": "string" },
          "brand_id": { "type": ["string", "null"] },
          "usage": {
            "type": "object",
            "properties": {
              "used": { "type": "integer" },
              "limit": { "type": "integer" },
              "plan": { "type": "string" }
            }
          }
        }
      },
      "Listing": {
        "type": "object",
        "description": "Stable superset. Every key is always present; fields not applicable to the chosen platform are empty (\"\" or []).",
        "properties": {
          "title": { "type": "string" },
          "bullets": { "type": "array", "items": { "type": "string" }, "description": "Up to 5. Amazon + WooCommerce." },
          "description": { "type": "string" },
          "keywords": { "type": "array", "items": { "type": "string" }, "description": "Up to 10." },
          "backend_terms": { "type": "string", "description": "Amazon only." },
          "focus_keyphrase": { "type": "string", "description": "WooCommerce only." },
          "meta_description": { "type": "string", "description": "Shopify + WooCommerce." },
          "product_tags": { "type": "array", "items": { "type": "string" }, "description": "Up to 8. WooCommerce only." },
          "seo_scores": {
            "type": "object",
            "properties": {
              "keyword_density": { "type": "integer", "minimum": 0, "maximum": 100 },
              "readability": { "type": "integer", "minimum": 0, "maximum": 100 },
              "conversion_potential": { "type": "integer", "minimum": 0, "maximum": 100 },
              "platform_compliance": { "type": "integer", "minimum": 0, "maximum": 100 }
            }
          },
          "pro_tip": { "type": "string" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": ["missing_authorization", "invalid_api_key", "plan_required", "brand_forbidden", "brand_archived", "invalid_json", "validation_error", "usage_limit_reached", "rate_limited", "internal_error"]
              },
              "message": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
