{
  "openapi": "3.1.0",
  "info": {
    "title": "Script Unlock — Agentic Intelligence API",
    "version": "2026.06.16",
    "summary": "Verified-pharmacy prescription comparison marketplace. Five intelligence endpoints for agents.",
    "description": "Public read-only endpoints for AI agents (ChatGPT, Claude, Gemini, others) to query prescription drug pricing, drug clinical facts, veterinary medication data, pharmacy directory, and live pharmacy bidding. Returns: summary-first JSON per Google MCP Design Principles. HIPAA-compliant; no PII handled. Editorial review by anonymous ScriptUnlock Pharmacy Verification Team.",
    "contact": {
      "name": "Script Unlock — Agent Integrations",
      "email": "agents@scriptunlock.com",
      "url": "https://www.scriptunlock.com/.well-known/agent.json"
    },
    "license": {
      "name": "Proprietary — Free Read Access for AI Agents",
      "url": "https://www.scriptunlock.com/terms"
    }
  },
  "servers": [
    { "url": "https://www.scriptunlock.com", "description": "Production" }
  ],
  "tags": [
    { "name": "Drug Intelligence", "description": "Human prescription drug data" },
    { "name": "Pet Intelligence", "description": "Veterinary medication data" },
    { "name": "Pharmacy Directory", "description": "Verified pharmacy lookup" },
    { "name": "Price Comparison", "description": "Live pharmacy bidding" }
  ],
  "paths": {
    "/api/v2/intelligence/drug-search": {
      "get": {
        "tags": ["Drug Intelligence"],
        "summary": "Search for a drug by generic or brand name",
        "operationId": "search_drug",
        "parameters": [
          { "name": "q", "in": "query", "required": true, "schema": { "type": "string" }, "description": "Drug name (generic or brand)" }
        ],
        "responses": {
          "200": { "description": "Drug found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/McpSuccess" } } } },
          "400": { "description": "Missing parameter" },
          "404": { "description": "Not found with suggested alternatives" }
        }
      }
    },
    "/api/v2/intelligence/drug-facts": {
      "get": {
        "tags": ["Drug Intelligence"],
        "summary": "Get canonical drug facts (indications, doses, schedule, side effects)",
        "operationId": "drug_facts",
        "parameters": [
          { "name": "drug", "in": "query", "required": true, "schema": { "type": "string" }, "description": "Drug slug, name, or brand" }
        ],
        "responses": {
          "200": { "description": "Drug facts payload" },
          "400": { "description": "Missing parameter" },
          "404": { "description": "Drug not found with fuzzy suggestions" }
        }
      }
    },
    "/api/v2/intelligence/pet-facts": {
      "get": {
        "tags": ["Pet Intelligence"],
        "summary": "Veterinary medication, compounded formulation, or pet condition lookup (3 modes)",
        "operationId": "pet_facts",
        "description": "Three modes via params:\n1. `?drug=X&species=Y` → clinical notes + 4-tile pricing\n2. `?compounded=X` → 503A formulation reference\n3. `?condition=X&species=Y` → condition overview + treatment options\n\nReturns scriptUnlockMoat field highlighting where Script Unlock beats Chewy (compounded transdermal forms, xylitol-free liquids, flavored suspensions, etc.).",
        "parameters": [
          { "name": "drug", "in": "query", "schema": { "type": "string" }, "description": "Drug slug for Mode 1 (paired with species)" },
          { "name": "species", "in": "query", "schema": { "type": "string", "enum": ["dog", "cat", "horse", "rabbit", "bird"] }, "description": "Species token (Modes 1 & 3)" },
          { "name": "compounded", "in": "query", "schema": { "type": "string" }, "description": "Drug slug for 503A compounded lookup (Mode 2)" },
          { "name": "condition", "in": "query", "schema": { "type": "string" }, "description": "Condition slug for Mode 3 (paired with species)" }
        ],
        "responses": {
          "200": { "description": "Pet data found" },
          "400": { "description": "Missing or incompatible params" },
          "404": { "description": "Not in pet catalog" }
        }
      }
    },
    "/api/v2/intelligence/compare": {
      "get": {
        "tags": ["Price Comparison"],
        "summary": "Compare live cash-pay pharmacy bids for a drug + dose + ZIP",
        "operationId": "compare_prescription_prices",
        "parameters": [
          { "name": "drug", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "dose", "in": "query", "schema": { "type": "string" } },
          { "name": "qty", "in": "query", "schema": { "type": "string" } },
          { "name": "zip", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Live bids returned" },
          "400": { "description": "Missing required parameter" }
        }
      }
    },
    "/api/v2/intelligence/pharmacies": {
      "get": {
        "tags": ["Pharmacy Directory"],
        "summary": "Find verified pharmacies near a location",
        "operationId": "find_pharmacy_near_me",
        "parameters": [
          { "name": "zip", "in": "query", "schema": { "type": "string" } },
          { "name": "lat", "in": "query", "schema": { "type": "number" } },
          { "name": "lng", "in": "query", "schema": { "type": "number" } },
          { "name": "radius_mi", "in": "query", "schema": { "type": "number", "default": 10 } },
          { "name": "type", "in": "query", "schema": { "type": "string", "enum": ["chain", "independent", "compounding", "vet"] } }
        ],
        "responses": {
          "200": { "description": "Pharmacies returned" },
          "400": { "description": "Missing location parameter" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "McpSuccess": {
        "type": "object",
        "required": ["ok", "summary", "data", "meta"],
        "properties": {
          "ok": { "type": "boolean", "enum": [true] },
          "summary": { "type": "string", "description": "Single-sentence English summary (Google MCP Principle #2)" },
          "data": { "type": "object", "description": "Payload" },
          "meta": {
            "type": "object",
            "properties": {
              "summary_token_count": { "type": "integer" },
              "data_token_estimate": { "type": "integer" },
              "timestamp": { "type": "string", "format": "date-time" },
              "cache_seconds": { "type": "integer" },
              "markdown_resource": { "type": "string", "format": "uri", "description": "Per-Principle #7: URI to fuller markdown content" }
            }
          }
        }
      },
      "McpError": {
        "type": "object",
        "required": ["ok", "error", "human_message", "suggested_actions", "meta"],
        "properties": {
          "ok": { "type": "boolean", "enum": [false] },
          "error": { "type": "string", "description": "Machine-parseable error code" },
          "human_message": { "type": "string" },
          "suggested_actions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "action": { "type": "string" },
                "description": { "type": "string" },
                "endpoint": { "type": "string", "format": "uri" },
                "params": { "type": "object" }
              }
            }
          },
          "meta": { "type": "object" }
        }
      }
    }
  }
}
