{
  "openapi": "3.1.0",
  "info": {
    "title": "Mavenly Grant Data API",
    "version": "1.0.0",
    "description": "Normalized, enriched federal and state grant opportunities from Grants.gov, SAM.gov, NSF and the Federal Register.\n\nAuthenticate with a workspace API key: `Authorization: Bearer mav_live_...`. Sandbox keys (`mav_test_...`) use the same endpoints and schema, capped at 500 requests a month and 10 results a page.\n\nEvery request is validated against this document: unknown query parameters, unknown body fields and wrong types return `400 invalid_request` with a per-field `errors` array. Responses carry `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`; bursts over your per-second limit return `429` with `Retry-After`, an exhausted monthly quota returns `402 quota_exceeded`, and an endpoint outside your plan returns `403 plan_required`.",
    "contact": {
      "name": "Mavenly",
      "email": "api@mavenly.ai",
      "url": "https://mavenly.ai/api"
    }
  },
  "servers": [
    {
      "url": "http://uzclgwsoxozyvpiodhho.supabase.co/functions/v1/api-v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key"
      }
    },
    "schemas": {
      "Opportunity": {
        "type": "object",
        "properties": {
          "opportunity_id": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "examples": [
              "grants_gov",
              "sam_gov",
              "nsf",
              "federal_register"
            ]
          },
          "opportunity_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "POSTED",
              "CLOSED",
              "FORECASTED"
            ]
          },
          "agency": {
            "type": "object",
            "properties": {
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "code": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "dates": {
            "type": "object",
            "properties": {
              "posted_date": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "closing_date": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "last_synced_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "financials": {
            "type": "object",
            "properties": {
              "award_floor": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "award_ceiling": {
                "type": [
                  "number",
                  "null"
                ]
              }
            }
          },
          "eligibility": {
            "type": "object",
            "properties": {
              "parsed_summary": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "geographic_scope": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "enriched_metadata": {
            "type": "object",
            "properties": {
              "priority_tags": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "days_to_close": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          },
          "links": {
            "type": "object",
            "properties": {
              "source_url": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "mavenly_url": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "examples": [
              "invalid_request",
              "unauthorized",
              "quota_exceeded",
              "plan_required",
              "rate_limited"
            ]
          },
          "message": {
            "type": "string"
          },
          "request_id": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "description": "Present on 400 responses: one entry per field that failed validation.",
            "items": {
              "type": "object",
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/v1/opportunities/search": {
      "get": {
        "summary": "Search opportunities",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Keyword search across title, summary and agency."
          },
          {
            "name": "agency",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "opportunity_number",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "focus_area",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "min_award",
            "in": "query",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "max_award",
            "in": "query",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "closing_after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "closing_before",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "open_only",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "closing_date",
                "posted_date",
                "updated_at"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching opportunities",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Opportunity"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer"
                        },
                        "limit": {
                          "type": "integer"
                        },
                        "offset": {
                          "type": "integer"
                        },
                        "has_more": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Request failed OpenAPI validation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Monthly quota exhausted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Per-second rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/opportunities/{id}": {
      "get": {
        "summary": "Retrieve one opportunity",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Mavenly opportunity id, slug, or opportunity number."
          }
        ],
        "responses": {
          "200": {
            "description": "The opportunity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Opportunity"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/opportunities/{id}/dissection": {
      "get": {
        "summary": "AI-extracted NOFO breakdown (Professional and Enterprise)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Structured breakdown of scoring weights, statutory priorities, evidence tier and required attachments."
          },
          "403": {
            "description": "Plan does not include this endpoint",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/matches/recommend": {
      "post": {
        "summary": "Rank opportunities for an organization profile (Professional and Enterprise)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "mission": {
                    "type": "string"
                  },
                  "focus_areas": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "geography": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "budget_range": {
                    "type": "object",
                    "properties": {
                      "min": {
                        "type": "number"
                      },
                      "max": {
                        "type": "number"
                      }
                    }
                  },
                  "applicant_type": {
                    "type": "string"
                  },
                  "limit": {
                    "type": "integer",
                    "default": 20
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Score-weighted opportunities with reasons."
          }
        }
      }
    },
    "/v1/webhooks/subscriptions": {
      "get": {
        "summary": "List webhook subscriptions",
        "responses": {
          "200": {
            "description": "Subscriptions"
          }
        }
      },
      "post": {
        "summary": "Create a webhook subscription (Professional and Enterprise)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "secret": {
                    "type": "string",
                    "description": "Used to compute the HMAC-SHA256 X-Mavenly-Signature header."
                  },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "opportunity.created",
                        "opportunity.amended",
                        "deadline.extended"
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      }
    },
    "/v1/webhooks/subscriptions/{id}": {
      "delete": {
        "summary": "Delete a webhook subscription",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "summary": "Current plan, quota and usage for the calling key",
        "responses": {
          "200": {
            "description": "Usage snapshot"
          }
        }
      }
    }
  }
}