{
  "openapi": "3.1.0",
  "info": {
    "title": "Agent Rails Shopping",
    "description": "Find the best products at the best price. Search, compare, and return ready-to-buy purchase links for AI hosts (ChatGPT GPT, Gemini Gem, Copilot, etc.). Prefer search; after web ASINs use buy-link. Always show buy URLs to the user. Never show go as the purchase link.",
    "version": "0.2.1"
  },
  "servers": [
    {
      "url": "https://agent-rails.onrender.com"
    }
  ],
  "paths": {
    "/v1/agents/register": {
      "post": {
        "operationId": "registerAgent",
        "summary": "Register an agent (optional; anonymous quota also works)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": { "type": "string", "example": "shopping-agent" },
                  "ownerEmail": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Registered",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "agentId": { "type": "string" },
                    "apiKey": { "type": "string" },
                    "plan": { "type": "string" },
                    "dailyQuota": { "type": "integer" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/search": {
      "get": {
        "operationId": "searchProducts",
        "summary": "Search catalog — PRIMARY shopping tool",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": { "type": "string" },
            "description": "Product query"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": { "type": "integer", "default": 5 }
          },
          {
            "name": "max_price",
            "in": "query",
            "required": false,
            "schema": { "type": "number" }
          }
        ],
        "responses": {
          "200": {
            "description": "Search results with items[].buy ready-to-buy purchase URLs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": { "type": "string" },
                          "t": { "type": "string", "description": "Title" },
                          "p": { "type": "number", "description": "Price" },
                          "c": { "type": "string", "description": "Currency" },
                          "buy": { "type": "string", "description": "Ready-to-buy purchase URL" },
                          "go": { "type": "string", "description": "Tracker only — do not show as purchase link" },
                          "aff": { "type": "boolean" },
                          "brand": { "type": "string" },
                          "score": { "type": "number" }
                        }
                      }
                    },
                    "disclosure": { "type": "string" },
                    "quota": {
                      "type": "object",
                      "properties": {
                        "left": { "type": "integer" },
                        "limit": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/buy-link": {
      "get": {
        "operationId": "makeBuyLinkGet",
        "summary": "Convert Amazon ASIN or URL to purchase link (REQUIRED after web search)",
        "parameters": [
          {
            "name": "url_or_asin",
            "in": "query",
            "required": true,
            "schema": { "type": "string" },
            "description": "ASIN or amazon.com/dp URL"
          }
        ],
        "responses": {
          "200": {
            "description": "items[].buy to show the human",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "asin": { "type": "string" },
                          "buy": { "type": "string" },
                          "go": { "type": "string" }
                        }
                      }
                    },
                    "disclosure": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "makeBuyLinkPost",
        "summary": "Convert Amazon ASIN or URL to purchase link",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "urlOrAsin": { "type": "string" },
                  "url": { "type": "string" },
                  "asin": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "items[].buy to show the human",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "asin": { "type": "string" },
                          "buy": { "type": "string" },
                          "go": { "type": "string" }
                        }
                      }
                    },
                    "disclosure": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/products/{id}": {
      "get": {
        "operationId": "getProduct",
        "summary": "Get one product by id/ASIN",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Product with buy link",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": { "type": "string" },
                    "t": { "type": "string" },
                    "p": { "type": "number" },
                    "c": { "type": "string" },
                    "buy": { "type": "string" },
                    "go": { "type": "string" },
                    "aff": { "type": "boolean" },
                    "brand": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/compare": {
      "get": {
        "operationId": "compareProducts",
        "summary": "Compare 2+ product ids",
        "parameters": [
          {
            "name": "ids",
            "in": "query",
            "required": true,
            "schema": { "type": "string" },
            "description": "Comma-separated product ids"
          }
        ],
        "responses": {
          "200": {
            "description": "Comparison with winner",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "winner": { "type": "string" },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": { "type": "string" },
                          "t": { "type": "string" },
                          "p": { "type": "number" },
                          "buy": { "type": "string" }
                        }
                      }
                    },
                    "reason": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
