{
  "openapi": "3.1.0",
  "x-mintlify": {
    "auth": {
      "apiKey": {
        "header": "X-API-Key",
        "default": "5fa709a5-0634-44c3-a991-57166d3c376d"
      }
    },
    "playground": {
      "display": "interactive"
    }
  },
  "info": {
    "title": "PolyRouter Prediction Markets API",
    "description": "Comprehensive API for accessing prediction market data across multiple platforms including Polymarket, Kalshi, and Manifold Markets.\n\n## Features\n- **Unified Data Access**: Single API for multiple prediction market platforms\n- **Real-time Data**: Live market prices, volumes, and trending analysis\n- **Historical Data**: Price history and market analytics\n- **Advanced Filtering**: Category, platform, and status-based filtering\n- **Rate Limiting**: Tiered access with usage tracking\n- **Authentication**: API key-based authentication with Supabase integration\n\n## Supported Platforms\n- **Polymarket**: Decentralized prediction markets on Polygon\n- **Kalshi**: US-regulated prediction markets\n- **Manifold Markets**: Community prediction markets\n\n## Rate Limits\n- **Free Tier**: 100 requests/minute, 10,000 requests/month\n- **Starter Tier**: 500 requests/minute, 50,000 requests/month\n- **Pro Tier**: 2,000 requests/minute, 200,000 requests/month\n- **Enterprise**: Custom limits\n\n## Authentication\n\n**Both API Key and Bearer Token are required for all requests.**\n\n### Required Headers\n```bash\ncurl -H \"X-API-Key: 5fa709a5-0634-44c3-a991-57166d3c376d\" \\\n     -H \"Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InB0YWhyaWNvd2h6c3hmaHFudnFlIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTcwMzA3NTMsImV4cCI6MjA3MjYwNjc1M30.aDVTn1GrFatkivIa7Lr1tADc8ud1T3nF5DnyVweaUcE\" \\\n     https://ptahricowhzsxfhqnvqe.supabase.co/functions/v1/markets-v1\n```\n\n### Individual Components\n- **API Key**: `X-API-Key` header for API access control\n- **Bearer Token**: `Authorization: Bearer` header for Supabase authentication",
    "version": "1.0.0",
    "contact": {
      "name": "PolyRouter API Support",
      "url": "https://polyrouter.io/support",
      "email": "support@polyrouter.io"
    },
    "license": {
      "name": "MIT",
      "url": "https://opensource.org/licenses/MIT"
    }
  },
  "servers": [
    {
      "url": "https://api.polyrouter.io/functions/v1",
      "description": "Production server"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/series": {
      "get": {
        "tags": [
          "v2"
        ],
        "summary": "List series",
        "description": "Retrieve real-time series across all supported platforms without database dependency. This endpoint directly proxies external platform APIs and returns data immediately for maximum freshness.",
        "parameters": [
          {
            "name": "platform",
            "in": "query",
            "description": "Filter by platform (single value only, not comma-separated): polymarket, kalshi",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "polymarket",
                "kalshi"
              ]
            }
          },
          {
            "name": "include_raw",
            "in": "query",
            "description": "Include raw data from the platform API",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "query",
            "in": "query",
            "description": "Search markets by name or description",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of results per page (1-25)",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 25,
              "default": 10
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Cursor for pagination",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Series retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "series": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SeriesV2"
                      }
                    },
                    "pagination": {
                      "$ref": "#/components/schemas/Pagination"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/AuthenticationError"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "description": "Platform unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "$ref": "#/components/schemas/Error"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/series/{series_id}": {
      "get": {
        "tags": [
          "v2"
        ],
        "summary": "Get series details",
        "description": "Retrieve detailed information about a specific series using platform-native IDs",
        "parameters": [
          {
            "name": "series_id",
            "in": "path",
            "description": "Platform-native series identifier",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "include_raw",
            "in": "query",
            "description": "Include raw data from the platform API",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Series details retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "series": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SeriesV2"
                      }
                    },
                    "pagination": {
                      "$ref": "#/components/schemas/Pagination"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/AuthenticationError"
          },
          "404": {
            "$ref": "#/components/responses/NotFoundError"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "description": "Platform unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "$ref": "#/components/schemas/Error"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "API key for authentication"
      }
    },
    "schemas": {
      "Series": {
        "type": "object",
        "required": [
          "id",
          "platform",
          "platform_id",
          "title",
          "last_updated"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique series identifier"
          },
          "platform": {
            "type": "string",
            "enum": [
              "polymarket",
              "kalshi",
              "limitless",
              "manifold"
            ],
            "description": "Source platform"
          },
          "platform_id": {
            "type": "string",
            "description": "Original platform series ID"
          },
          "title": {
            "type": "string",
            "description": "Series title"
          },
          "slug": {
            "type": "string",
            "description": "URL-friendly series identifier"
          },
          "description": {
            "type": "string",
            "description": "Detailed series description"
          },
          "image_url": {
            "type": "string",
            "format": "uri",
            "description": "Series image URL"
          },
          "category": {
            "type": "string",
            "enum": [
              "politics",
              "sports",
              "crypto",
              "economics",
              "technology",
              "weather",
              "other"
            ],
            "description": "Series category"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Array of series tags"
          },
          "event_count": {
            "type": "number",
            "description": "Number of events in this series"
          },
          "market_count": {
            "type": "number",
            "description": "Total number of markets across all events"
          },
          "total_volume": {
            "type": "number",
            "description": "Total trading volume across all markets"
          },
          "last_updated": {
            "type": "string",
            "format": "date-time",
            "description": "Last data update timestamp"
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Event"
            },
            "description": "Array of associated events (only when with_events=true)"
          },
          "market_summary": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MarketSummary"
            },
            "description": "Market summary by event (only when with_market_summary=true)"
          }
        }
      },
      "Meta": {
        "type": "object",
        "required": [
          "request_time",
          "cache_hit",
          "data_freshness"
        ],
        "properties": {
          "request_time": {
            "type": "number",
            "description": "Request processing time (ms)"
          },
          "cache_hit": {
            "type": "boolean",
            "description": "Whether response was served from cache"
          },
          "data_freshness": {
            "type": "string",
            "format": "date-time",
            "description": "Data freshness timestamp"
          }
        }
      },
      "SeriesV2": {
        "type": "object",
        "required": [
          "id",
          "platform",
          "platform_id",
          "title",
          "last_synced_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Platform-native series identifier"
          },
          "platform": {
            "type": "string",
            "enum": [
              "polymarket",
              "kalshi",
              "limitless",
              "manifold"
            ],
            "description": "Source platform"
          },
          "platform_id": {
            "type": "string",
            "description": "Original platform series ID (same as id)"
          },
          "title": {
            "type": "string",
            "description": "Series title"
          },
          "series_slug": {
            "type": "string",
            "description": "URL-friendly series identifier"
          },
          "description": {
            "type": "string",
            "description": "Series description"
          },
          "image_url": {
            "type": "string",
            "format": "uri",
            "description": "Series image URL"
          },
          "category": {
            "type": "string",
            "description": "Series category"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Array of series tags"
          },
          "metadata": {
            "type": "object",
            "description": "Platform-specific metadata"
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EventV2"
            },
            "description": "Array of nested events (for individual series lookup)"
          },
          "markets": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MarketV2"
            },
            "description": "Array of nested markets (for individual series lookup)"
          },
          "last_synced_at": {
            "type": "string",
            "format": "date-time",
            "description": "Last data sync timestamp (ISO 8601)"
          },
          "raw_data": {
            "type": "object",
            "description": "Complete raw platform response"
          }
        }
      },
      "Pagination": {
        "type": "object",
        "required": [
          "total",
          "limit",
          "offset",
          "has_more",
          "next_offset"
        ],
        "properties": {
          "total": {
            "type": "number",
            "description": "Total number of results"
          },
          "limit": {
            "type": "number",
            "description": "Number of results per page"
          },
          "offset": {
            "type": "number",
            "description": "Current page offset"
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether more pages exist"
          },
          "next_offset": {
            "type": "number",
            "description": "Offset for next page"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "code",
          "message",
          "timestamp"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "Error code",
            "example": "VALIDATION_ERROR"
          },
          "message": {
            "type": "string",
            "description": "Error message"
          },
          "details": {
            "type": "object",
            "description": "Additional error details"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "description": "Error timestamp"
          }
        }
      }
    },
    "responses": {
      "ValidationError": {
        "description": "Validation error response",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "$ref": "#/components/schemas/Error"
                },
                "meta": {
                  "$ref": "#/components/schemas/Meta"
                }
              }
            }
          }
        }
      },
      "AuthenticationError": {
        "description": "Authentication error response",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "NotFoundError": {
        "description": "Resource not found error response",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "$ref": "#/components/schemas/Error"
                },
                "meta": {
                  "$ref": "#/components/schemas/Meta"
                }
              }
            }
          }
        }
      },
      "InternalError": {
        "description": "Internal server error response",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "$ref": "#/components/schemas/Error"
                },
                "meta": {
                  "$ref": "#/components/schemas/Meta"
                }
              }
            }
          }
        }
      }
    }
  }
}