{
  "openapi": "3.0.3",
  "info": {
    "title": "ModelPriceLab Data API",
    "description": "Programmatic access to model prices, API changes, and webhook subscriptions.",
    "version": "1.0.0",
    "contact": {
      "name": "ModelPriceLab Support",
      "email": "support@modelpricelab.com"
    }
  },
  "servers": [
    {
      "url": "https://api.modelpricelab.com",
      "description": "Production"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/v1/prices": {
      "get": {
        "summary": "List current prices",
        "description": "Returns current model prices across vendors and platforms.",
        "operationId": "listPrices",
        "parameters": [
          {
            "name": "vendor",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Filter by vendor slug"
          },
          {
            "name": "modality",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Filter by modality (llm, image, audio, etc.)"
          },
          {
            "name": "platform",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Filter by platform (direct, azure, bedrock, etc.)"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "default": 100 },
            "description": "Maximum number of results"
          },
          {
            "name": "offset",
            "in": "query",
            "schema": { "type": "integer", "default": 0 },
            "description": "Pagination offset"
          }
        ],
        "responses": {
          "200": {
            "description": "List of prices",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Price" }
                    }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/v1/changes": {
      "get": {
        "summary": "List changes",
        "description": "Returns recent price and API changes with severity and impact.",
        "operationId": "listChanges",
        "parameters": [
          {
            "name": "vendor",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Filter by vendor slug"
          },
          {
            "name": "category",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Filter by change category"
          },
          {
            "name": "severity",
            "in": "query",
            "schema": { "type": "integer" },
            "description": "Minimum severity (1-5)"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "default": 50 },
            "description": "Maximum number of results"
          },
          {
            "name": "offset",
            "in": "query",
            "schema": { "type": "integer", "default": 0 },
            "description": "Pagination offset"
          }
        ],
        "responses": {
          "200": {
            "description": "List of changes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Change" }
                    }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/v1/webhooks": {
      "get": {
        "summary": "List webhooks",
        "description": "List configured webhook endpoints.",
        "operationId": "listWebhooks",
        "responses": {
          "200": {
            "description": "List of webhooks",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Webhook" }
                    }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" },
          "429": { "description": "Rate limit exceeded" }
        }
      },
      "post": {
        "summary": "Create webhook",
        "description": "Subscribe a URL to price and change events.",
        "operationId": "createWebhook",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/WebhookInput" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": { "$ref": "#/components/schemas/Webhook" }
                  }
                }
              }
            }
          },
          "401": { "description": "Unauthorized" },
          "422": { "description": "Validation error" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/v1/webhooks/{id}": {
      "delete": {
        "summary": "Delete webhook",
        "description": "Remove a webhook subscription.",
        "operationId": "deleteWebhook",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": { "description": "Webhook deleted" },
          "401": { "description": "Unauthorized" },
          "404": { "description": "Webhook not found" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "Use `Bearer mpl_your_api_key`"
      }
    },
    "schemas": {
      "Price": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "vendor": { "type": "string" },
          "product_id": { "type": "string" },
          "product_name": { "type": "string" },
          "modality": { "type": "string" },
          "platform": { "type": "string" },
          "region": { "type": "string" },
          "input_per_1m": { "type": "number", "nullable": true },
          "output_per_1m": { "type": "number", "nullable": true },
          "cached_input_per_1m": { "type": "number", "nullable": true },
          "context_window": { "type": "integer", "nullable": true },
          "max_output_tokens": { "type": "integer", "nullable": true },
          "effective_date": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "Change": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "title": { "type": "string" },
          "summary": { "type": "string" },
          "vendor": { "type": "string" },
          "product_id": { "type": "string", "nullable": true },
          "category": { "type": "string" },
          "severity": { "type": "integer" },
          "effective_date": { "type": "string", "format": "date-time", "nullable": true },
          "published_at": { "type": "string", "format": "date-time" }
        }
      },
      "Webhook": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "url": { "type": "string", "format": "uri" },
          "events": {
            "type": "array",
            "items": { "type": "string" }
          },
          "secret": { "type": "string" },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "WebhookInput": {
        "type": "object",
        "required": ["url", "events"],
        "properties": {
          "url": { "type": "string", "format": "uri" },
          "events": {
            "type": "array",
            "items": { "type": "string" },
            "example": ["price.updated", "change.created"]
          }
        }
      }
    }
  }
}
