{
  "openapi": "3.0.3",
  "info": {
    "title": "ModelPriceLab Data API",
    "version": "1.0.0",
    "description": "API-key access to stored model-price records, published vendor changes, and change.alert webhooks. Price rows are source-linked when source_url is present; effective_at and updated_at describe the stored record and do not assert an independent live-price verification. All /v1 responses are account-specific and use Cache-Control: private, no-store with Vary: Authorization. Daily quotas reset at UTC midnight; when the daily plan quota is exhausted, purchased top-up packs (50,000 requests, 30 days, stackable, FIFO consumption) keep the same key serving and responses carry X-RateLimit-Topup: true, otherwise 429 responses include topup_url. Every data response includes X-RateLimit-Limit and X-RateLimit-Remaining headers.",
    "contact": {
      "name": "ModelPriceLab Support",
      "email": "support@modelpricelab.com"
    }
  },
  "servers": [
    {
      "url": "https://api.modelpricelab.com",
      "description": "Production"
    }
  ],
  "security": [
    {
      "BearerApiKey": []
    }
  ],
  "paths": {
    "/v1/prices": {
      "get": {
        "summary": "List stored price records",
        "description": "Returns stored, source-linked price records where available. No fixed freshness or real-time delivery is promised. product is matched directly against the canonical products.id value and is never inferred from a resource id.",
        "operationId": "listPrices",
        "parameters": [
          {
            "name": "vendor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact vendor id"
          },
          {
            "name": "product",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact canonical products.id value"
          },
          {
            "name": "platform",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact platform id, for example direct or openrouter"
          },
          {
            "name": "modality",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact modality, for example llm, image, audio, or video"
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Return rows whose record updated_at is at or after this date-time"
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque base64url cursor returned as pagination.next_cursor. Do not construct or modify it."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            },
            "description": "Maximum rows returned"
          }
        ],
        "responses": {
          "200": {
            "description": "Stored price records in descending (updated_at, resource_id) order",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PriceList"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/changes": {
      "get": {
        "summary": "List published changes",
        "description": "Returns published vendor changes. Operational incidents are excluded unless category=incident is explicit or include_incidents=true. This endpoint requires a current Developer, Scale, Team, or Enterprise entitlement.",
        "operationId": "listChanges",
        "parameters": [
          {
            "name": "vendor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact vendor id"
          },
          {
            "name": "product",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact canonical products.id value"
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact change category; category=incident explicitly includes incidents"
          },
          {
            "name": "include_incidents",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Include operational incidents when category is not set"
          },
          {
            "name": "min_severity",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 5
            },
            "description": "Minimum severity"
          },
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Return rows whose updated_at is at or after this date-time"
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque base64url cursor returned as pagination.next_cursor. Do not construct or modify it."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            },
            "description": "Maximum rows returned"
          }
        ],
        "responses": {
          "200": {
            "description": "Published changes in descending (updated_at, id) order",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChangeList"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/webhooks": {
      "get": {
        "summary": "List webhook subscriptions",
        "description": "Lists the caller's webhook subscriptions. Signing secrets are write-only and are never returned.",
        "operationId": "listWebhooks",
        "responses": {
          "200": {
            "description": "Webhook subscriptions without signing secrets",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "post": {
        "summary": "Create a change-alert webhook",
        "description": "Registers an HTTPS endpoint. A current Developer/Scale api_subscriptions record or current Team/Enterprise subscriptions record is required; an account plan label alone is not delivery entitlement. Deliveries use event=change.alert. x-mpl-signature contains sha256=<hex HMAC-SHA256> over the exact raw UTF-8 request body. Developer allows two active webhooks; Scale is unlimited.",
        "operationId": "createWebhook",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook created; the signing secret is not echoed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookItem"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "description": "Active webhook limit reached",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/webhooks/{id}": {
      "delete": {
        "summary": "Delete a webhook subscription",
        "operationId": "deleteWebhook",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "Webhook not found for this owner",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "summary": "Quota and top-up introspection for the current key",
        "description": "Reports the caller's plan, daily quota (limit, used, remaining, UTC-midnight reset), per-endpoint metering for the UTC day, and the live balance of purchased top-up packs. Introspection is unmetered on every plan: calling /v1/usage never consumes quota.",
        "operationId": "getUsage",
        "security": [
          {
            "BearerApiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Usage snapshot",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "ModelPriceLab API key",
        "description": "Authorization: Bearer mpl_your_api_key"
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid query or request body",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, invalid, or revoked API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Endpoint is not included in the current entitlement",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Daily API-key quota exceeded",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unavailable": {
        "description": "Authorization or data store unavailable",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error",
          "message",
          "status"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "upgrade_url": {
            "type": "string"
          }
        }
      },
      "Pagination": {
        "type": "object",
        "required": [
          "next_cursor"
        ],
        "properties": {
          "next_cursor": {
            "type": "string",
            "description": "Opaque canonical base64url(JSON [updated_at, id]) tuple. Pass it back unchanged."
          }
        }
      },
      "PriceList": {
        "type": "object",
        "required": [
          "schema_version",
          "data"
        ],
        "properties": {
          "schema_version": {
            "type": "integer",
            "enum": [
              1
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Price"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/Pagination"
          }
        }
      },
      "Price": {
        "type": "object",
        "required": [
          "resource_id",
          "product_id",
          "vendor",
          "platform",
          "modality",
          "region",
          "unit",
          "input_per_mtok",
          "output_per_mtok",
          "cached_input_per_mtok",
          "image_per_unit",
          "audio_per_min",
          "video_per_sec",
          "currency",
          "source_url",
          "effective_at",
          "updated_at"
        ],
        "properties": {
          "resource_id": {
            "type": "string",
            "description": "Stable resources.id row identifier"
          },
          "product_id": {
            "type": "string",
            "nullable": true,
            "description": "Canonical products.id when linked"
          },
          "vendor": {
            "type": "string"
          },
          "platform": {
            "type": "string",
            "nullable": true
          },
          "modality": {
            "type": "string",
            "nullable": true
          },
          "region": {
            "type": "string",
            "nullable": true
          },
          "unit": {
            "type": "string",
            "nullable": true
          },
          "input_per_mtok": {
            "type": "number",
            "nullable": true
          },
          "output_per_mtok": {
            "type": "number",
            "nullable": true
          },
          "cached_input_per_mtok": {
            "type": "number",
            "nullable": true
          },
          "image_per_unit": {
            "type": "number",
            "nullable": true
          },
          "audio_per_min": {
            "type": "number",
            "nullable": true
          },
          "video_per_sec": {
            "type": "number",
            "nullable": true
          },
          "currency": {
            "type": "string",
            "nullable": true
          },
          "source_url": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "effective_at": {
            "type": "string",
            "description": "Source effective date when present, otherwise record updated_at"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "Stored record update time, not independent source verification"
          }
        }
      },
      "ChangeList": {
        "type": "object",
        "required": [
          "schema_version",
          "data"
        ],
        "properties": {
          "schema_version": {
            "type": "integer",
            "enum": [
              1
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Change"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/Pagination"
          }
        }
      },
      "Change": {
        "type": "object",
        "required": [
          "id",
          "vendor",
          "product",
          "modality",
          "category",
          "severity",
          "title",
          "summary",
          "impact_score",
          "first_seen",
          "last_seen",
          "created_at",
          "updated_at",
          "alternatives",
          "access"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "vendor": {
            "type": "string"
          },
          "product": {
            "type": "string",
            "description": "Canonical products.id value"
          },
          "modality": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "severity": {
            "type": "integer"
          },
          "title": {
            "type": "string"
          },
          "summary": {
            "type": "string"
          },
          "diff_before": {
            "type": "string",
            "nullable": true
          },
          "diff_after": {
            "type": "string",
            "nullable": true
          },
          "diff_keys": {
            "type": "string",
            "nullable": true
          },
          "impact_score": {
            "type": "integer"
          },
          "impact_cost": {
            "type": "integer",
            "nullable": true
          },
          "impact_reliability": {
            "type": "integer",
            "nullable": true
          },
          "impact_migration": {
            "type": "integer",
            "nullable": true
          },
          "impact_quality": {
            "type": "integer",
            "nullable": true
          },
          "impact_compliance": {
            "type": "integer",
            "nullable": true
          },
          "impact_notes": {
            "type": "string",
            "nullable": true
          },
          "migration_deadline": {
            "type": "string",
            "nullable": true
          },
          "effective_time": {
            "type": "string",
            "nullable": true
          },
          "first_seen": {
            "type": "string"
          },
          "last_seen": {
            "type": "string"
          },
          "verified": {
            "type": "boolean",
            "nullable": true
          },
          "verified_at": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "nullable": true
          },
          "view_count": {
            "type": "integer",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "alternatives": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ChangeAlternative"
            }
          },
          "access": {
            "type": "string",
            "enum": [
              "summary",
              "full"
            ]
          }
        }
      },
      "ChangeAlternative": {
        "type": "object",
        "required": [
          "id",
          "change_id",
          "product_id",
          "product_name",
          "vendor",
          "migration_effort",
          "rank",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "change_id": {
            "type": "string"
          },
          "product_id": {
            "type": "string"
          },
          "product_name": {
            "type": "string"
          },
          "vendor": {
            "type": "string"
          },
          "migration_effort": {
            "type": "string"
          },
          "cost_diff_pct": {
            "type": "number",
            "nullable": true
          },
          "quality_comparison": {
            "type": "string",
            "nullable": true
          },
          "notes": {
            "type": "string",
            "nullable": true
          },
          "rank": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookList": {
        "type": "object",
        "required": [
          "data"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Webhook"
            }
          }
        }
      },
      "WebhookItem": {
        "type": "object",
        "required": [
          "data"
        ],
        "properties": {
          "data": {
            "$ref": "#/components/schemas/Webhook"
          }
        }
      },
      "Webhook": {
        "type": "object",
        "required": [
          "id",
          "url",
          "events",
          "active",
          "has_secret",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "change.alert",
                "*"
              ]
            }
          },
          "active": {
            "type": "boolean"
          },
          "has_secret": {
            "type": "boolean"
          },
          "last_status": {
            "type": "integer",
            "nullable": true
          },
          "last_error": {
            "type": "string",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookInput": {
        "type": "object",
        "required": [
          "url",
          "secret"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://"
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "default": [
              "change.alert"
            ],
            "items": {
              "type": "string",
              "enum": [
                "change.alert",
                "*"
              ]
            }
          },
          "secret": {
            "type": "string",
            "minLength": 16,
            "maxLength": 512,
            "writeOnly": true,
            "description": "HMAC signing secret. It is stored for delivery signing and is never returned by the API."
          }
        }
      },
      "WebhookDelivery": {
        "type": "object",
        "required": [
          "event",
          "timestamp",
          "changes"
        ],
        "properties": {
          "event": {
            "type": "string",
            "enum": [
              "change.alert"
            ]
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "changes": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "vendor",
                "product",
                "severity",
                "title",
                "summary",
                "category",
                "url"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "vendor": {
                  "type": "string"
                },
                "product": {
                  "type": "string"
                },
                "severity": {
                  "type": "integer"
                },
                "title": {
                  "type": "string"
                },
                "summary": {
                  "type": "string"
                },
                "category": {
                  "type": "string"
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          }
        }
      },
      "Usage": {
        "type": "object",
        "required": [
          "plan",
          "day",
          "daily_quota",
          "endpoints",
          "topup"
        ],
        "properties": {
          "schema_version": {
            "type": "integer",
            "example": 1
          },
          "plan": {
            "type": "string",
            "enum": [
              "api_free",
              "developer"
            ]
          },
          "day": {
            "type": "string",
            "format": "date",
            "description": "UTC day the snapshot covers"
          },
          "daily_quota": {
            "type": "object",
            "properties": {
              "limit": {
                "type": "integer"
              },
              "used": {
                "type": "integer",
                "description": "Reserved requests against the daily plan quota"
              },
              "remaining": {
                "type": "integer"
              },
              "reset_at": {
                "type": "string",
                "format": "date-time",
                "description": "Next UTC midnight, when the daily quota resets"
              }
            }
          },
          "endpoints": {
            "type": "object",
            "additionalProperties": {
              "type": "integer"
            },
            "description": "Metered request count per endpoint (prices, changes, webhooks) for the UTC day"
          },
          "metered_total": {
            "type": "integer"
          },
          "topup": {
            "type": "object",
            "properties": {
              "remaining": {
                "type": "integer",
                "description": "Unconsumed top-up requests across all active packs"
              },
              "packs": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "remaining": {
                      "type": "integer"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              },
              "purchase_url": {
                "type": "string",
                "description": "Where to buy additional packs (/pricing#api-topup)"
              }
            }
          }
        }
      }
    }
  }
}
