openapi: 3.0.0
info:
  title: Brave Resolve API
  description: Turn the encrypted Brave links in your Brave Search API responses into destination URLs. Requests use no credits.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    post:
      summary: Brave Resolve
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - engine
                - results
              properties:
                engine:
                  type: string
                  enum: ["brave_resolve"]
                  description: Must be set to brave_resolve.
                results:
                  type: array
                  minItems: 1
                  maxItems: 25
                  description: The links to resolve. An item can carry fields of your own, such as an id for your records, and they come back on its row, except `error`. The whole array can be at most 1 MB as JSON. Results come back in the order they were sent.
                  items:
                    type: object
                    required:
                      - link_token
                    additionalProperties: true
                    properties:
                      link_token:
                        type: string
                        description: The token returned beside an encrypted Brave link in a Brave Search API response.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BraveResolveResponse'
        '400':
          description: A results item is not an object with a link_token, a link_token did not come from a Brave Search API response, results is over its limits, or an item contains a null character.
          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: Too many requests. The limit is 500 per minute and 20 at a time, or 10 at a time for accounts without a subscription.
          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 time.
          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:
    BraveResolveResponse:
      type: object
      required:
        - search_metadata
        - search_parameters
        - results
      properties:
        search_metadata:
          $ref: '#/components/schemas/SearchMetadata'
        search_parameters:
          $ref: '#/components/schemas/SearchParameters'
        results:
          type: array
          items:
            $ref: '#/components/schemas/BraveResolveResult'
        retry_after:
          type: integer
          description: The seconds to wait before sending again the rows that have a link_token and no error.
    BraveResolveResult:
      type: object
      description: One row per item sent, in the same order, with the fields sent on that item.
      additionalProperties: true
      properties:
        link:
          description: The destination URL on a resolved row, or the link you sent, unchanged, on any other row.
        link_token:
          type: string
          description: The token of a link that did not resolve, absent from a resolved row.
        error:
          type: string
          description: The reason this link will not resolve, on a row that should not be sent again.
    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 resolve the links in seconds
        parsing_time_taken:
          type: number
          description: Time taken to parse the response in seconds
        total_time_taken:
          type: number
          description: Total request and parsing time in seconds
        request_url:
          type: string
          format: uri
          description: Brave Search URL used for this search
        json_url:
          type: string
          format: uri
          description: URL to retrieve the cached JSON response
    SearchParameters:
      type: object
      required: [engine]
      properties:
        engine:
          type: string
          enum: ["brave_resolve"]
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
