{
  "openapi": "3.1.0",
  "info": {
    "title": "Best Car Subscription API",
    "version": "1.0.0",
    "summary": "UK car subscription listings and provider prices, refreshed hourly.",
    "description": "Public read API behind bestcarsubscription.com. No authentication for GET endpoints; CORS open. Please cache for 10 minutes and link back to https://bestcarsubscription.com when you show results. Prices are each provider's 'from' figure; check `basis` (mo = per month, 28d = per 28 days) and `vat` (inc|ex).",
    "contact": { "email": "hello@bestcarsubscription.com", "url": "https://bestcarsubscription.com/#contact" },
    "x-llms-txt": "https://bestcarsubscription.com/llms.txt"
  },
  "servers": [{ "url": "https://api.bestcarsubscription.com" }],
  "paths": {
    "/vehicles": {
      "get": {
        "operationId": "searchVehicles",
        "summary": "Search car subscription listings by make, model, text, EV, provider.",
        "parameters": [
          { "name": "make", "in": "query", "schema": { "type": "string" }, "example": "Volkswagen" },
          { "name": "model", "in": "query", "schema": { "type": "string" }, "description": "Prefix match on model", "example": "Golf" },
          { "name": "q", "in": "query", "schema": { "type": "string" }, "description": "Free text across make, model, variant and provider", "example": "range rover" },
          { "name": "ev", "in": "query", "schema": { "type": "string", "enum": ["1"] }, "description": "Electric only" },
          { "name": "provider", "in": "query", "schema": { "type": "string" }, "description": "Provider id, e.g. cocoon, flexed, mycardirect, pivotal, voltric" },
          { "name": "sort", "in": "query", "schema": { "type": "string", "enum": ["price_asc", "price_desc"], "default": "price_asc" } }
        ],
        "responses": {
          "200": {
            "description": "Listings plus facets",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VehicleSearch" } } }
          }
        }
      }
    },
    "/prices": {
      "get": {
        "operationId": "providerPrices",
        "summary": "Each provider's headline 'from' monthly price (GBP) keyed by provider id, with `_updated` timestamp.",
        "responses": { "200": { "description": "Map of provider id → price", "content": { "application/json": { "schema": { "type": "object", "additionalProperties": { "type": ["number", "string"] } } } } } }
      }
    },
    "/go/{provider}": {
      "get": {
        "operationId": "goToProvider",
        "summary": "Redirect to a provider (or a specific vehicle page via `to`). Use the `url` from a listing with this for attribution; or link to `provider_url` directly.",
        "parameters": [
          { "name": "provider", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "to", "in": "query", "schema": { "type": "string", "format": "uri" }, "description": "Must be on the provider's own domain" }
        ],
        "responses": { "302": { "description": "Redirect" }, "404": { "description": "Unknown provider" } }
      }
    },
    "/lead": {
      "post": {
        "operationId": "submitEnquiry",
        "summary": "Submit a quote enquiry on behalf of a user who has given consent to be contacted by matching providers.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Lead" } } } },
        "responses": { "200": { "description": "Accepted; `matches` lists provider ids the enquiry was routed to" }, "400": { "description": "Missing consent, email or postcode" } }
      }
    }
  },
  "components": {
    "schemas": {
      "Listing": {
        "type": "object",
        "properties": {
          "p": { "type": "string", "description": "Provider id" },
          "mk": { "type": "string", "description": "Make" },
          "md": { "type": "string", "description": "Model" },
          "v": { "type": "string", "description": "Variant / trim" },
          "pr": { "type": "number", "description": "Price in GBP" },
          "basis": { "type": "string", "enum": ["mo", "28d"], "description": "Per month or per 28 days" },
          "vat": { "type": "string", "enum": ["inc", "ex"] },
          "term": { "type": "string", "description": "Minimum term" },
          "ev": { "type": "boolean" },
          "url": { "type": "string", "format": "uri", "description": "The provider's own page for this car" }
        }
      },
      "VehicleSearch": {
        "type": "object",
        "properties": {
          "updated": { "type": "string", "format": "date-time" },
          "total": { "type": "integer" },
          "count": { "type": "integer" },
          "makes": { "type": "array", "items": { "type": "string" } },
          "models": { "type": "array", "items": { "type": "string" } },
          "providers": { "type": "object", "additionalProperties": { "type": "object", "properties": { "name": { "type": "string" }, "logo": { "type": "string" }, "url": { "type": "string" } } } },
          "rows": { "type": "array", "items": { "$ref": "#/components/schemas/Listing" }, "maxItems": 200 }
        }
      },
      "Lead": {
        "type": "object",
        "required": ["email", "postcode", "consent"],
        "properties": {
          "email": { "type": "string", "format": "email" },
          "postcode": { "type": "string", "description": "Outward code is enough, e.g. B15" },
          "term": { "type": "string", "enum": ["1", "3", "12"] },
          "fuel": { "type": "string", "enum": ["ev", "any"] },
          "who": { "type": "string", "enum": ["personal", "business"] },
          "budget": { "type": "string", "enum": ["400", "700", "9999"] },
          "consent": { "type": "string", "enum": ["yes"], "description": "The user agreed providers may contact them" }
        }
      }
    }
  }
}
