{
  "openapi": "3.1.0",
  "info": {
    "title": "PredictionMarket API",
    "version": "1.0.0",
    "description": "Unified Prediction Market & Event-Contract Consensus Probability REST & Remote MCP API. Aggregates and normalizes live Polymarket (Gamma & CLOB) and Kalshi (CFTC-regulated Trade API v2) event contracts, implied probabilities, live bid/ask orderbook depth, 24h probability movers, and hourly historical snapshots for quantitative research and AI decision grounding. Credits: $1.00 = 10,000 Credits (3,000 Free Credits on sign-up, no card required; or keyless x402 Base Mainnet USDC at $0.001/call).",
    "contact": {
      "name": "PredictionMarket API Engineering",
      "url": "https://predictionmarketapi.dev",
      "email": "support@predictionmarketapi.dev"
    }
  },
  "servers": [
    {
      "url": "https://api.predictionmarketapi.dev",
      "description": "Production Gateway (REST + Streamable HTTP MCP + x402)"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    },
    {
      "BearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "API key prefixed with pm_live_ (3,000 Free Credits on sign-up at https://predictionmarketapi.dev/signup)."
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer pm_live_... API key or OAuth 2.1 mcp_at_... token."
      }
    },
    "schemas": {
      "MarketOutcome": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "example": "Yes"
          },
          "probability": {
            "type": "number",
            "example": 0.115
          },
          "token_id": {
            "type": [
              "string",
              "null"
            ],
            "example": "32338220190071351435772801779725302244575775216413325951443816017994629993401"
          }
        }
      },
      "NormalizedMarket": {
        "type": "object",
        "required": [
          "market_id",
          "venue",
          "title",
          "category",
          "yes_probability",
          "no_probability",
          "volume_usd",
          "liquidity_usd"
        ],
        "properties": {
          "market_id": {
            "type": "string",
            "example": "KXELONMARS-99"
          },
          "venue": {
            "type": "string",
            "enum": [
              "polymarket",
              "kalshi"
            ],
            "example": "kalshi"
          },
          "venue_market_id": {
            "type": "string",
            "example": "KXELONMARS-99"
          },
          "slug": {
            "type": "string",
            "example": "kxelonmars-99"
          },
          "ticker": {
            "type": [
              "string",
              "null"
            ],
            "example": "KXELONMARS-99"
          },
          "event_id": {
            "type": [
              "string",
              "null"
            ],
            "example": "KXELONMARS-99"
          },
          "title": {
            "type": "string",
            "example": "Will Elon Musk visit Mars in his lifetime?"
          },
          "question": {
            "type": "string",
            "example": "Will Elon Musk visit Mars before Aug 1, 2099?"
          },
          "category": {
            "type": "string",
            "example": "tech"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "closed",
              "settled"
            ],
            "example": "open"
          },
          "yes_probability": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "example": 0.115
          },
          "no_probability": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "example": 0.885
          },
          "yes_bid": {
            "type": [
              "number",
              "null"
            ],
            "example": 0.1
          },
          "yes_ask": {
            "type": [
              "number",
              "null"
            ],
            "example": 0.13
          },
          "spread_bps": {
            "type": [
              "integer",
              "null"
            ],
            "example": 300
          },
          "price_change_24h": {
            "type": [
              "number",
              "null"
            ],
            "example": 0.03
          },
          "volume_usd": {
            "type": "number",
            "example": 127914.55
          },
          "volume_24h_usd": {
            "type": "number",
            "example": 72.5
          },
          "liquidity_usd": {
            "type": "number",
            "example": 40099.4
          },
          "open_interest_usd": {
            "type": [
              "number",
              "null"
            ],
            "example": 40099.4
          },
          "close_time": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "example": "2099-08-01T04:59:00Z"
          },
          "resolution_source": {
            "type": "string",
            "example": "Kalshi CFTC-Regulated Exchange Rules"
          },
          "clob_token_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "outcomes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MarketOutcome"
            }
          },
          "rules": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "OrderbookLevel": {
        "type": "object",
        "properties": {
          "price": {
            "type": "number",
            "example": 0.1
          },
          "size": {
            "type": "number",
            "example": 1344.47
          },
          "notional_usd": {
            "type": "number",
            "example": 134.45
          }
        }
      },
      "NormalizedOrderbook": {
        "type": "object",
        "properties": {
          "venue": {
            "type": "string",
            "enum": [
              "polymarket",
              "kalshi"
            ]
          },
          "market_id": {
            "type": "string"
          },
          "token_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "ticker": {
            "type": [
              "string",
              "null"
            ]
          },
          "best_bid": {
            "type": [
              "number",
              "null"
            ],
            "example": 0.1
          },
          "best_ask": {
            "type": [
              "number",
              "null"
            ],
            "example": 0.13
          },
          "mid_price": {
            "type": [
              "number",
              "null"
            ],
            "example": 0.115
          },
          "implied_probability": {
            "type": [
              "number",
              "null"
            ],
            "example": 0.115
          },
          "spread": {
            "type": [
              "number",
              "null"
            ],
            "example": 0.03
          },
          "spread_bps": {
            "type": [
              "integer",
              "null"
            ],
            "example": 300
          },
          "total_bid_depth_usd": {
            "type": "number",
            "example": 1450.25
          },
          "total_ask_depth_usd": {
            "type": "number",
            "example": 2910.4
          },
          "bids": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderbookLevel"
            }
          },
          "asks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderbookLevel"
            }
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  },
  "paths": {
    "/v1/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "Gateway health check",
        "security": [],
        "responses": {
          "200": {
            "description": "Gateway is operational",
            "content": {
              "application/json": {
                "example": {
                  "code": 0,
                  "provider": "https://predictionmarketapi.dev",
                  "status": "ok",
                  "msg": "success",
                  "data": {
                    "service": "predictionmarketapi-gateway",
                    "status": "healthy",
                    "venues": [
                      "polymarket",
                      "kalshi"
                    ],
                    "endpoints_count": 4
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/markets/search": {
      "get": {
        "operationId": "searchMarkets",
        "summary": "Search unified Polymarket & Kalshi event contracts",
        "description": "Aggregates and normalizes live event contracts from Polymarket Gamma API and Kalshi Public Trade API v2 into one deterministic schema. Cost: 2 Credits / market returned (0 Credits if empty).",
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Keyword filter across titles, questions, and slugs (e.g. fed, inflation, bitcoin, mars)."
          },
          {
            "name": "venue",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "polymarket",
                "kalshi"
              ],
              "default": "all"
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "macro",
                "tech",
                "politics",
                "crypto",
                "finance",
                "climate",
                "culture"
              ],
              "default": "all"
            }
          },
          {
            "name": "active",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Normalized list of event contracts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "example": 0
                    },
                    "provider": {
                      "type": "string",
                      "example": "https://predictionmarketapi.dev"
                    },
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "count": {
                          "type": "integer"
                        },
                        "total_matched": {
                          "type": "integer"
                        },
                        "has_more": {
                          "type": "boolean"
                        },
                        "markets": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/NormalizedMarket"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/markets/detail": {
      "get": {
        "operationId": "getMarketDetail",
        "summary": "Get full event contract metadata, rules, outcomes & snapshot history",
        "description": "Fetch full metadata, resolution rules, outcome probabilities, 24h delta, CLOB token IDs, and PostgreSQL hourly probability snapshots. Cost: 10 Credits / call (0 Credits on 404).",
        "parameters": [
          {
            "name": "market_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Polymarket numeric ID/slug (e.g. 559651 or pm_559651) or Kalshi ticker (e.g. KXELONMARS-99)."
          },
          {
            "name": "venue",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "polymarket",
                "kalshi"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Full event contract detail",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "example": 0
                    },
                    "provider": {
                      "type": "string",
                      "example": "https://predictionmarketapi.dev"
                    },
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "data": {
                      "$ref": "#/components/schemas/NormalizedMarket"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/markets/orderbook": {
      "get": {
        "operationId": "getMarketOrderbook",
        "summary": "Get live Polymarket CLOB or Kalshi bid/ask orderbook depth & spread",
        "description": "Returns normalized YES bids, YES asks, best_bid, best_ask, mid_price implied probability, spread_bps, and total USD depth. Cost: 5 Credits / call (0 Credits on 404).",
        "parameters": [
          {
            "name": "token_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Polymarket CLOB asset token_id."
          },
          {
            "name": "ticker",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Kalshi contract ticker (e.g. KXELONMARS-99)."
          },
          {
            "name": "market_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Unified market_id (auto-resolves CLOB token_id or Kalshi ticker)."
          }
        ],
        "responses": {
          "200": {
            "description": "Normalized live orderbook",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "example": 0
                    },
                    "provider": {
                      "type": "string",
                      "example": "https://predictionmarketapi.dev"
                    },
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "data": {
                      "$ref": "#/components/schemas/NormalizedOrderbook"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/markets/movers": {
      "get": {
        "operationId": "getMarketMovers",
        "summary": "Get top 24h implied-probability movers & high-volume event contracts",
        "description": "Ranks open contracts across Polymarket and Kalshi by 24-hour implied-probability movement and liquidity while recording hourly probability snapshots. Cost: 2 Credits / mover returned.",
        "parameters": [
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "macro",
                "tech",
                "politics",
                "crypto",
                "finance",
                "climate",
                "culture"
              ],
              "default": "all"
            }
          },
          {
            "name": "venue",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "polymarket",
                "kalshi"
              ],
              "default": "all"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Top 24h probability movers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "example": 0
                    },
                    "provider": {
                      "type": "string",
                      "example": "https://predictionmarketapi.dev"
                    },
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "count": {
                          "type": "integer"
                        },
                        "movers": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/NormalizedMarket"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}