{
  "openapi": "3.1.0",
  "info": {
    "title": "Outcome Prediction Market Data API",
    "version": "1.0.0",
    "description": "SQL access to Kalshi and Polymarket prediction market data. Inspect the free live schema before writing SQL. Data queries require a Bearer API key and use credits. This specification covers schema discovery and JSON query execution; the documentation also covers MCP, streaming, exports, and notebook management."
  },
  "servers": [
    {
      "url": "https://api.outcome.sh"
    }
  ],
  "externalDocs": {
    "description": "Complete Outcome API documentation",
    "url": "https://docs.outcome.sh/"
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/schema": {
      "get": {
        "operationId": "getPredictionMarketSchema",
        "summary": "Inspect available tables, columns, and ClickHouse types",
        "description": "Free and unauthenticated. Use the current response to discover available data before composing queries; do not infer coverage or freshness from the presence of a table.",
        "security": [],
        "responses": {
          "200": {
            "description": "Current public table schema",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TableSchema"
                }
              }
            }
          },
          "500": {
            "description": "Schema could not be loaded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/execute": {
      "post": {
        "operationId": "queryPredictionMarketData",
        "summary": "Run a read-only prediction market SQL query using credits",
        "description": "Executes one SELECT, WITH, EXPLAIN, or SHOW statement. Successful billable queries spend the team's credits. LIMIT caps returned rows, not scanned bytes: also constrain markets, columns, and time windows. Returns a JSON array of row objects. Output is capped at 10,000 rows, 8 MiB total, and 1 MiB per row. Execution is limited to 60 minutes and available credits. Writes, system access, external-data functions, and user SETTINGS/FORMAT/INTO clauses are rejected.",
        "x-openai-isConsequential": true,
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string",
                    "minLength": 1,
                    "description": "One read-only ClickHouse SQL statement using the live schema."
                  },
                  "final": {
                    "type": "boolean",
                    "default": false,
                    "description": "Apply FINAL deduplication to markets and trades. May scan more data and cost more credits."
                  }
                }
              },
              "example": {
                "query": "SELECT venue, ticker, title, yes_price, updated_time FROM markets WHERE is_deleted = 0 ORDER BY volume_24h DESC LIMIT 5"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rows selected by the query. An empty result is [].",
            "headers": {
              "X-Credits-Used": {
                "description": "Computed query credit cost; this header alone does not confirm a successful charge",
                "schema": {
                  "type": "integer"
                }
              },
              "X-Duration-Ms": {
                "description": "Execution duration in milliseconds",
                "schema": {
                  "type": "integer"
                }
              },
              "X-Bytes-Read": {
                "description": "Bytes scanned",
                "schema": {
                  "type": "integer"
                }
              },
              "X-Credits-Remaining": {
                "description": "Remaining team credits; present when the query charge succeeds",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "maxItems": 10000,
                  "items": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid body or unsupported SQL",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, or revoked API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient credits or query byte budget exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "413": {
            "description": "Result exceeds row/byte limits or query exceeds its memory limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "429": {
            "description": "Rate, API-key spend, or team spend limit exceeded. Inspect error and optional code; honor Retry-After when present.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "500": {
            "description": "Query execution or billing failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "503": {
            "description": "Query capacity or billing unavailable; back off before retrying",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "504": {
            "description": "Query execution timed out",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Outcome API key created at https://app.outcome.sh/keys"
      }
    },
    "schemas": {
      "TableSchema": {
        "type": "object",
        "required": [
          "tables"
        ],
        "properties": {
          "tables": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "columns"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "columns": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "name",
                      "type"
                    ],
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "type": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "ApiError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string"
          }
        }
      }
    }
  }
}
