openapi: 3.0.0
info:
  title: Polymarket Events API
  description: |
    The Polymarket Events API returns Polymarket prediction market events, with their dates, volume, liquidity, tags and markets. Each market lists its outcomes with their current prices, which Polymarket documents as implied probabilities.

    With `q` it returns the events that match a keyword. Without `q` it lists events, ranked by `sort_by`. Both can be narrowed by `event_status` and `tag`.

    To get the next page, pass `pagination.next_page_token`. The token carries the query, filters, sort and page size of the request that returned it.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Polymarket Events Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Engine to use for the search
          schema:
            type: string
            enum: ["polymarket_events"]
            default: "polymarket_events"
        - name: q
          in: query
          required: false
          description: Keyword to search events for, up to 512 characters. Without it, the API lists events instead.
          schema:
            type: string
        - name: event_status
          in: query
          required: false
          description: Status of the events to return. active returns open events, closed returns events that have ended, and all returns both.
          schema:
            type: string
            enum: ["active", "closed", "all"]
            default: "active"
        - name: tag
          in: query
          required: false
          description: Polymarket tag slug to filter events by, such as crypto or politics
          schema:
            type: string
            pattern: '^[A-Za-z0-9]+(-[A-Za-z0-9]+)*$'
            maxLength: 100
        - name: sort_by
          in: query
          required: false
          description: Order of the events. trending ranks by volume over the last 24 hours, volume by all-time volume, liquidity by liquidity, newest by start date and competitive by Polymarket's competitiveness score.
          schema:
            type: string
            enum: ["trending", "volume", "liquidity", "newest", "competitive"]
            default: "trending"
        - name: num
          in: query
          required: false
          description: Number of events per page
          schema:
            type: integer
            minimum: 1
            maximum: 50
            default: 20
        - name: next_page_token
          in: query
          required: false
          description: Token for the next page, from pagination.next_page_token of the previous response. It carries that request's query, filters, sort and page size.
          schema:
            type: string
            maxLength: 4096
        - name: zero_retention
          in: query
          required: false
          description: Set to true to disable logging and persistent storage for this request. Enterprise plans only.
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '400':
          description: Validation Error. There is an issue with query parameters, such as invalid values.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication Error. The API key is missing or invalid.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Account cannot use the requested feature.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate Limit Exceeded. The number of allowed requests has been exceeded. Consider upgrading your plan or waiting for the limit to reset.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Server Error. Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: Timeout. We could not retrieve results in 90 seconds.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: 'Use Bearer authentication. Format: "Bearer YOUR_API_KEY"'
    ApiKeyQuery:
      type: apiKey
      in: query
      name: api_key
      description: Pass API key as query parameter
  schemas:
    SearchResponse:
      type: object
      required: [search_metadata, search_parameters]
      properties:
        search_metadata:
          $ref: '#/components/schemas/SearchMetadata'
        search_parameters:
          $ref: '#/components/schemas/SearchParameters'
        search_information:
          $ref: '#/components/schemas/SearchInformation'
        events:
          type: array
          description: The events on the current page
          items:
            $ref: '#/components/schemas/Event'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Message explaining why the response has no events
    SearchMetadata:
      type: object
      required: [status, created_at]
      properties:
        id:
          type: string
          description: Unique identifier for the search request
        status:
          type: string
          description: Status of the search request
        created_at:
          type: string
          format: date-time
          description: Timestamp when the search was created
        request_time_taken:
          type: number
          description: Time taken to make the request in seconds
        parsing_time_taken:
          type: number
          description: Time taken to parse the results in seconds
        total_time_taken:
          type: number
          description: Total time taken for the search in seconds
        request_url:
          type: string
          description: Polymarket page that shows the same events
        html_url:
          type: string
          description: URL to view HTML results
        json_url:
          type: string
          description: URL to view JSON results
    SearchParameters:
      type: object
      properties:
        engine:
          type: string
          description: Engine used for the search
        q:
          type: string
          description: Keyword searched for
        event_status:
          type: string
          description: Event status filter applied
        tag:
          type: string
          description: Tag filter applied
        sort_by:
          type: string
          description: Sort order applied
        num:
          type: string
          description: Number of events per page requested
        next_page_token:
          type: string
          description: Token of the page requested
    SearchInformation:
      type: object
      description: Search information, sent with q only
      properties:
        total_results:
          type: integer
          description: Number of events Polymarket counts for the keyword and filters
    Event:
      type: object
      required: [position, event_id, slug, title, link, tags, markets]
      properties:
        position:
          type: integer
          description: Position of the event, numbered on from earlier pages
        event_id:
          type: string
          description: Polymarket event ID
        slug:
          type: string
          description: Polymarket event slug
        title:
          type: string
          description: Title of the event
        link:
          type: string
          description: Polymarket page of the event
        image:
          type: string
          description: Image of the event
        tags:
          type: array
          description: Tags Polymarket files the event under
          items:
            $ref: '#/components/schemas/Tag'
        start_date:
          type: string
          format: date-time
          description: Time the event opened, in UTC
        end_date:
          type: string
          format: date-time
          description: Time the event is scheduled to end, in UTC
        closed_date:
          type: string
          format: date-time
          description: Time the event closed, in UTC
        is_closed:
          type: boolean
          description: Whether the event has closed
        volume:
          type: number
          description: All-time trading volume in USD
        volume_24h:
          type: number
          description: Trading volume over the last 24 hours in USD
        liquidity:
          type: number
          description: Liquidity in USD
        open_interest:
          type: number
          description: Value of the open positions in USD
        comment_count:
          type: integer
          description: Number of comments on the event
        markets:
          type: array
          description: The markets of the event
          items:
            $ref: '#/components/schemas/Market'
    Tag:
      type: object
      required: [slug]
      properties:
        name:
          type: string
          description: Name of the tag
        slug:
          type: string
          description: Slug of the tag, to pass as tag
    Market:
      type: object
      required: [market_id, outcomes]
      properties:
        market_id:
          type: string
          description: Polymarket market ID
        question:
          type: string
          description: Question the market resolves
        slug:
          type: string
          description: Polymarket market slug
        name:
          type: string
          description: Short name of the market within its event, such as a candidate or a price level
        outcomes:
          type: array
          description: The outcomes of the market
          items:
            $ref: '#/components/schemas/Outcome'
        best_bid:
          type: number
          description: Highest bid for the first outcome in USD
        best_ask:
          type: number
          description: Lowest ask for the first outcome in USD
        last_trade_price:
          type: number
          description: Price of the last trade of the first outcome in USD
        price_change_24h:
          type: number
          description: Change of the first outcome's price over the last 24 hours in USD
        volume:
          type: number
          description: All-time trading volume in USD
        liquidity:
          type: number
          description: Liquidity in USD
        is_closed:
          type: boolean
          description: Whether the market has closed
        is_accepting_orders:
          type: boolean
          description: Whether the market takes new orders
        resolution_status:
          type: string
          description: Status of the market's resolution, such as proposed, disputed or resolved
        winning_outcome:
          type: string
          description: Name of the outcome a closed market priced at 1
    Outcome:
      type: object
      required: [name]
      properties:
        name:
          type: string
          description: Name of the outcome, such as Yes, No or a team
        price:
          type: number
          description: Price of one share in USD, from 0 to 1, which Polymarket documents as the outcome's implied probability
        token_id:
          type: string
          description: Polymarket token ID of the outcome
    Pagination:
      type: object
      required: [next_page_token]
      properties:
        next_page_token:
          type: string
          description: Token for the next page of events, to pass as next_page_token
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
