openapi: 3.0.0
info:
  title: Brave Search API
  description: |
    Get the results page of Brave Search in structured JSON. This API returns organic results, ads, the knowledge
    graph, videos, news, frequently asked questions, forum discussions, local results and related searches.

    **Cross-linking**: the Brave AI Mode API (`engine=brave_ai_mode`) returns Brave's AI answer for the same query.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Brave Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: Search engine to use
          schema:
            type: string
            enum: ["brave"]
            default: "brave"
        - name: q
          in: query
          required: true
          description: The search query, up to 400 characters and 50 words. The character limit counts UTF-16 code units, so a supplementary character such as an emoji counts as two. A query that starts or ends with a bang such as `!w` returns an error, since Brave Search sends it to the page the bang names.
          schema:
            type: string
            maxLength: 400
        - name: country
          in: query
          required: false
          description: Two-letter country code that sets the region Brave Search returns results for. Set it to `all` for all regions.
          schema:
            type: string
            default: "us"
            enum: ["all", "ar", "au", "at", "be", "br", "ca", "cl", "cn", "dk", "fi", "fr", "de", "gr", "hk", "in", "id", "it", "jp", "kr", "my", "mx", "nl", "nz", "no", "ph", "pl", "pt", "ru", "sa", "sg", "za", "es", "se", "ch", "tw", "tr", "gb", "us"]
        - name: language
          in: query
          required: false
          description: Two-letter language code that sets the language Brave Search prefers for results.
          schema:
            type: string
            default: "en"
            enum: ["az", "bg", "br", "ca", "cs", "cy", "da", "de", "el", "en", "es", "et", "eu", "fi", "fr", "gl", "hr", "hu", "id", "it", "ja", "ka", "ko", "lt", "lv", "ms", "nb", "nl", "pl", "pt", "ro", "ru", "sk", "sl", "sq", "sr", "sv", "sw", "th", "tr", "uk", "vi", "zh"]
        - name: time_period
          in: query
          required: false
          description: Restricts results to pages from a recent period. Cannot be combined with time_period_min or time_period_max.
          schema:
            type: string
            enum: ["last_day", "last_week", "last_month", "last_year"]
        - name: time_period_min
          in: query
          required: false
          description: Start of a custom period in YYYY-MM-DD or MM/DD/YYYY format. Without time_period_max, the period ends today.
          schema:
            type: string
        - name: time_period_max
          in: query
          required: false
          description: End of a custom period in YYYY-MM-DD or MM/DD/YYYY format. Without time_period_min, the period has no start.
          schema:
            type: string
        - name: safe_search
          in: query
          required: false
          description: Filters adult content. Brave Search applies `moderate` when it is not set.
          schema:
            type: string
            enum: ["off", "moderate", "strict"]
        - name: page
          in: query
          required: false
          description: The results page. Each page holds up to 20 results.
          schema:
            type: integer
            minimum: 1
            maximum: 6
            default: 1
      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 missing required parameters or 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'
        '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'
        ads:
          type: array
          description: Sponsored results shown above the organic results.
          items:
            $ref: '#/components/schemas/Ad'
        knowledge_graph:
          $ref: '#/components/schemas/KnowledgeGraph'
        organic_results:
          type: array
          description: The organic web results.
          items:
            $ref: '#/components/schemas/OrganicResult'
        inline_videos:
          type: array
          description: Videos shown among the results.
          items:
            $ref: '#/components/schemas/InlineVideo'
        top_stories:
          type: array
          description: News stories shown among the results.
          items:
            $ref: '#/components/schemas/TopStory'
        related_questions:
          type: array
          description: Frequently asked questions and their answers from the results.
          items:
            $ref: '#/components/schemas/RelatedQuestion'
        discussions_and_forums:
          type: array
          description: Forum threads shown among the results.
          items:
            $ref: '#/components/schemas/Discussion'
        local_results:
          type: array
          description: Places shown for queries with local intent.
          items:
            $ref: '#/components/schemas/LocalResult'
        related_searches:
          type: array
          description: Searches related to the query.
          items:
            $ref: '#/components/schemas/RelatedSearch'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Message returned when Brave Search has no results for the query or sends a query with a bang to another page.
    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: Brave Search URL for this search
        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: Search engine used
        q:
          type: string
          description: The search query
        country:
          type: string
          description: Two-letter country code of the request
        language:
          type: string
          description: Two-letter language code of the request
        page:
          type: integer
          description: The results page requested
        time_period:
          type: string
          description: The recent period requested
        time_period_min:
          type: string
          description: Start of the custom period requested
        time_period_max:
          type: string
          description: End of the custom period requested
        safe_search:
          type: string
          description: The adult content filter requested
    SearchInformation:
      type: object
      properties:
        query_displayed:
          type: string
          description: The query as Brave Search displays it.
    Ad:
      type: object
      required: [position]
      properties:
        position:
          type: integer
          description: Position of the ad, starting at 1.
        title:
          type: string
          description: Title of the ad.
        link:
          type: string
          description: The page the ad leads to.
        tracking_link:
          type: string
          description: Brave Search's click link for the ad.
        source:
          type: string
          description: Name of the advertiser.
        snippet:
          type: string
          description: Text of the ad.
        favicon:
          type: string
          description: Icon of the advertiser's site.
    KnowledgeGraph:
      type: object
      properties:
        title:
          type: string
          description: Name of the entity.
        description:
          type: string
          description: Summary of the entity.
        link:
          type: string
          description: Page the summary comes from.
        website:
          type: string
          description: The entity's official website.
        thumbnail:
          type: string
          description: Image of the entity.
        profiles:
          type: array
          description: The entity's profiles on other sites.
          items:
            type: object
            properties:
              name:
                type: string
                description: Name of the site.
              link:
                type: string
                description: Link to the profile.
    OrganicResult:
      type: object
      required: [position, link]
      properties:
        position:
          type: integer
          description: Position of the result on the page, starting at 1.
        title:
          type: string
          description: Title of the result.
        link:
          type: string
          description: Link to the result as Brave Search gives it.
        link_token:
          type: string
          description: Send this to the Brave Resolve API to get the destination URL of an encrypted `link`.
        source:
          type: string
          description: Name of the result's site.
        domain:
          type: string
          description: Host name of the result's site.
        displayed_link:
          type: string
          description: The site and path Brave Search shows for the result.
        snippet:
          type: string
          description: Text Brave Search shows under the title.
        snippet_highlighted_words:
          type: array
          description: Words of the snippet that match the query.
          items:
            type: string
        date:
          type: string
          description: Age or date of the page as Brave Search shows it.
        favicon:
          type: string
          description: Icon of the result's site.
        thumbnail:
          type: string
          description: Image shown beside the result.
        sitelinks:
          type: array
          description: Links to sections of the result's page.
          items:
            type: object
            properties:
              title:
                type: string
                description: Title of the section.
              link:
                type: string
                description: Link to the section.
    InlineVideo:
      type: object
      required: [position, link]
      properties:
        position:
          type: integer
          description: Position of the video, starting at 1.
        title:
          type: string
          description: Title of the video.
        link:
          type: string
          description: Link to the video.
        source:
          type: string
          description: Platform that hosts the video.
        channel:
          type: string
          description: Creator of the video.
        length:
          type: string
          description: Length of the video.
        date:
          type: string
          description: Age or date of the video as Brave Search shows it.
        thumbnail:
          type: string
          description: Thumbnail of the video.
    TopStory:
      type: object
      required: [position, link]
      properties:
        position:
          type: integer
          description: Position of the story, starting at 1.
        title:
          type: string
          description: Title of the story.
        link:
          type: string
          description: Link to the story.
        domain:
          type: string
          description: Host name of the publisher's site.
        snippet:
          type: string
          description: Summary of the story.
        date:
          type: string
          description: Age or date of the story as Brave Search shows it.
        thumbnail:
          type: string
          description: Image of the story.
    RelatedQuestion:
      type: object
      required: [question]
      properties:
        question:
          type: string
          description: The question.
        answer:
          type: string
          description: The answer from the source page.
        source:
          type: object
          description: The page the answer comes from.
          properties:
            title:
              type: string
              description: Title of the source page.
            link:
              type: string
              description: Link to the source page.
            domain:
              type: string
              description: Host name of the source page's site.
    Discussion:
      type: object
      required: [link]
      properties:
        title:
          type: string
          description: Title of the thread.
        link:
          type: string
          description: Link to the thread.
        source:
          type: string
          description: Name of the forum.
        snippet:
          type: string
          description: Text from the thread.
        date:
          type: string
          description: Age or date of the thread as Brave Search shows it.
    LocalResult:
      type: object
      required: [position, title]
      properties:
        position:
          type: integer
          description: Position of the place, starting at 1.
        title:
          type: string
          description: Name of the place.
        address:
          type: string
          description: Street address of the place.
        phone:
          type: string
          description: Phone number of the place.
        link:
          type: string
          description: Website of the place.
        gps_coordinates:
          type: object
          properties:
            latitude:
              type: number
              description: Latitude of the place.
            longitude:
              type: number
              description: Longitude of the place.
    RelatedSearch:
      type: object
      required: [query, link]
      properties:
        query:
          type: string
          description: The related query.
        link:
          type: string
          description: Brave Search link for the related query.
    Pagination:
      type: object
      required: [current]
      properties:
        current:
          type: integer
          description: The current page.
        next:
          type: string
          description: Brave Search link to the next page.
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
