{
  "openapi": "3.1.0",
  "info": {
    "title": "SongVow Agent API",
    "version": "1.0.0",
    "summary": "Order a custom SongVow song on behalf of a buyer.",
    "description": "Three public JSON endpoints. Read the catalog, collect the buyer's story using the occasion's questions, create the order, then send the buyer to the returned Stripe Checkout URL to pay. No API key is needed. The agent never handles card details. Human guide: https://www.songvow.com/for-agents",
    "contact": { "name": "SongVow support", "email": "support@songvow.com", "url": "https://www.songvow.com/support" },
    "termsOfService": "https://www.songvow.com/terms"
  },
  "servers": [{ "url": "https://www.songvow.com" }],
  "paths": {
    "/api/v1/catalog": {
      "get": {
        "operationId": "getCatalog",
        "summary": "Plans, occasions with story questions, styles, example songs and order rules",
        "description": "Cached for one hour. Every value sent to createOrder must come from this catalog. Each occasion includes example_song, a real public gift page the buyer can listen to before ordering.",
        "responses": {
          "200": {
            "description": "The catalog",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Catalog" } } }
          }
        }
      }
    },
    "/api/v1/orders": {
      "post": {
        "operationId": "createOrder",
        "summary": "Validate and create an order; returns a Stripe Checkout URL",
        "description": "Strictly validated. Any invalid field returns 400 with a plain-English reason per field and nothing is created. Rate limited to a few orders per IP address per ten minutes.",
        "parameters": [
          {
            "name": "X-Agent-Name",
            "in": "header",
            "required": false,
            "description": "Name of the agent or product placing the order, so SongVow can see which agents bring buyers.",
            "schema": { "type": "string", "maxLength": 80 }
          }
        ],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NewOrder" } } }
        },
        "responses": {
          "201": {
            "description": "Order created; payment still required unless payment_required is false",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OrderCreated" } } }
          },
          "400": {
            "description": "Validation failed; nothing was created",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
          },
          "429": { "description": "Too many orders from this IP address; wait ten minutes" },
          "502": { "description": "Checkout could not be created; retry later" }
        }
      }
    },
    "/api/v1/orders/{orderNumber}": {
      "get": {
        "operationId": "getOrderStatus",
        "summary": "Order stage and, once delivered, the gift page URL",
        "description": "Never exposes the story, lyrics or audio. Polling is optional: the buyer is emailed the gift page when the song is ready.",
        "parameters": [
          {
            "name": "orderNumber",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "pattern": "^SV-[0-9]{5}$", "example": "SV-48213" }
          }
        ],
        "responses": {
          "200": {
            "description": "Current status",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OrderStatus" } } }
          },
          "400": { "description": "Invalid order number" },
          "404": { "description": "Order not found" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Catalog": {
        "type": "object",
        "properties": {
          "version": { "type": "integer" },
          "service": { "type": "string" },
          "docs": { "type": "string", "format": "uri" },
          "openapi": { "type": "string", "format": "uri" },
          "plans": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": { "type": "string", "enum": ["classic", "premium", "ultimate"] },
                "name": { "type": "string" },
                "price_cents": { "type": "integer" },
                "price_display": { "type": "string" },
                "currency": { "type": "string" },
                "revisions_included": { "type": "integer" },
                "delivery": { "type": "string" },
                "features": { "type": "array", "items": { "type": "string" } }
              }
            }
          },
          "addons": { "type": "array", "items": { "type": "object" } },
          "languages": { "type": "array", "items": { "type": "string" } },
          "styles": {
            "type": "object",
            "properties": {
              "genres": { "type": "array", "items": { "type": "string" } },
              "spanish_genres": { "type": "array", "items": { "type": "string" } },
              "moods": { "type": "array", "items": { "type": "string" } },
              "vocals": { "type": "array", "items": { "type": "string" } }
            }
          },
          "occasions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": { "type": "string" },
                "story_questions": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "field": { "type": "string", "enum": ["storyBeginning", "storySpecial", "storyMemory", "extra"] },
                      "question": { "type": "string" },
                      "example": { "type": "string" }
                    }
                  }
                },
                "avoid": { "type": "object" },
                "example_song": { "type": ["string", "null"], "format": "uri", "description": "A real public gift page for this occasion" }
              }
            }
          },
          "examples": {
            "type": "object",
            "properties": {
              "note": { "type": "string" },
              "songs": {
                "type": "array",
                "items": { "type": "object", "properties": { "occasion": { "type": "string" }, "gift_url": { "type": "string", "format": "uri" } } }
              }
            }
          },
          "order_rules": { "type": "object" }
        }
      },
      "NewOrder": {
        "type": "object",
        "required": ["occasion", "recipientName", "senderName", "email", "plan", "genre", "moods", "vocal"],
        "properties": {
          "occasion": { "type": "string", "description": "One of catalog.occasions[].name" },
          "recipientName": { "type": "string", "maxLength": 120, "description": "Who the song is for" },
          "senderName": { "type": "string", "maxLength": 120, "description": "Who it is from" },
          "email": { "type": "string", "format": "email", "description": "The buyer's email; the gift page is sent here" },
          "plan": { "type": "string", "enum": ["classic", "premium", "ultimate"] },
          "genre": { "type": "string", "description": "From catalog.styles.genres, or spanish_genres when songLanguage is Spanish" },
          "moods": { "type": "array", "minItems": 1, "maxItems": 3, "items": { "type": "string" }, "description": "From catalog.styles.moods" },
          "vocal": { "type": "string", "enum": ["Male", "Female", "No preference"] },
          "songLanguage": { "type": "string", "enum": ["English", "Spanish"], "default": "English" },
          "storyBeginning": { "type": "string", "maxLength": 3000, "description": "Answer to the occasion's first story question" },
          "storySpecial": { "type": "string", "maxLength": 3000, "description": "Answer to the second story question" },
          "storyMemory": { "type": "string", "maxLength": 3000, "description": "Answer to the third story question" },
          "extra": { "type": "string", "maxLength": 3000, "description": "Answer to the fourth story question. At least two of the four story fields must have real content." },
          "pronunciation": { "type": "string", "maxLength": 120, "description": "How to say the recipient's name" },
          "avoid": { "type": "string", "maxLength": 3000, "description": "Anything the song should not mention" },
          "giftMessage": { "type": "string", "maxLength": 3000, "description": "Shown on the gift page" },
          "coupon_code": { "type": "string", "maxLength": 40 },
          "compareEnabled": { "type": "boolean", "description": "Add a second version of the same lyrics in another style (see catalog.addons)" },
          "genreB": { "type": "string" },
          "moodsB": { "type": "array", "items": { "type": "string" } },
          "vocalB": { "type": "string" },
          "marketingOptIn": { "type": "boolean" }
        }
      },
      "OrderCreated": {
        "type": "object",
        "properties": {
          "order_number": { "type": "string", "example": "SV-48213" },
          "checkout_url": { "type": "string", "format": "uri", "description": "Send the buyer here to pay on Stripe" },
          "payment_required": { "type": "boolean" },
          "list_price_cents": { "type": "integer" },
          "currency": { "type": "string" },
          "coupon_applied_at_checkout": { "type": "boolean" },
          "status_url": { "type": "string", "format": "uri" },
          "status_page": { "type": "string", "format": "uri" },
          "next_step": { "type": "string" }
        }
      },
      "OrderStatus": {
        "type": "object",
        "properties": {
          "order_number": { "type": "string" },
          "stage": { "type": "string", "enum": ["awaiting_payment", "generating", "delivered"] },
          "status": { "type": "string" },
          "plan": { "type": "string" },
          "occasion": { "type": "string" },
          "paid": { "type": "boolean" },
          "delivered": { "type": "boolean" },
          "song_ready": { "type": "boolean" },
          "video_status": { "type": ["string", "null"] },
          "compare_enabled": { "type": "boolean" },
          "created_at": { "type": ["string", "null"], "format": "date-time" },
          "paid_at": { "type": ["string", "null"], "format": "date-time" },
          "delivered_at": { "type": ["string", "null"], "format": "date-time" },
          "status_page": { "type": "string", "format": "uri" },
          "gift_url": { "type": ["string", "null"], "format": "uri", "description": "Set once the song is delivered" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string", "description": "Plain-English reasons, one per failing field" },
          "fields": { "type": "array", "items": { "type": "string" } }
        }
      }
    }
  }
}
