> ## Documentation Index
> Fetch the complete documentation index at: https://docs.critique-labs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Search



## OpenAPI

````yaml https://api.critique-labs.ai/openapi.json post /v1/search
openapi: 3.1.0
info:
  title: Critique Flow API
  summary: >-
    Gives you researched in-line cited search responses from Critique's in-built
    LLM powered agentic search engine
  description: >

    **URL**: `https://api.critique-labs.ai/v1/search`  

    **Method**: `POST`  

    **Content-Type**: `application/json`  


    #### Headers

    - **X-API-Key**: (Required) Your unique API key for authentication.

    - **Content-Type**: (Required) Should be set to `application/json`.


    #### Request Body Parameters

    | Parameter        | Type              |
    Description                                                                                                                                                                                                                        
    |

    |------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

    | **image**        | `string` (optional) | A base64-encoded string of the
    image or a URL to the image. Providing this parameter allows the API to
    incorporate visual data into the search. If both `image` and `prompt` are
    included, they are combined to refine the search. |

    | **prompt**       | `string`          | A natural language question or
    statement that specifies the information you are seeking. The prompt can
    include specific instructions about the expected answer type, timeframe, or
    content source.                                  |

    | **source_blacklist** | `array` of `string` (optional) | A list of URLs or
    domains (e.g., `"expedia.com"`) that should be excluded from the search
    results. Cannot be used together with
    source_whitelist.                              |

    | **source_whitelist** | `array` of `string` (optional) | A list of URLs or
    domains that should be exclusively used in the search results. Cannot be
    used together with source_blacklist.                              |

    | **output_format**   | `object` (optional) | A JSON object that specifies
    the expected structure of the response. This allows for control over the
    format and detail level of the results, making integration into structured
    applications seamless. See details below.      |


    #### `output_format` Parameter

    The `output_format` parameter is a JSON object that defines the desired
    structure of the API response. Each key in this object represents a field in
    the response, and the value defines its data type or structure.


    ##### Supported Data Types

    - **Primitive Types**: `"string"`, `"number"`, `"boolean"`

    - **Nested Objects**: An object can have other fields, each with types or
    nested structures.

    - **Arrays of Objects**: Arrays can contain objects with defined structures.


    ##### Example of `output_format`

    ```json

    {
      "flights": [
        {
          "destination": "string",
          "price": "number",
          "date": "string"
        }
      ],
      "summary": "string",
      "isAvailable": "boolean"
    }

    ```


    In this example:

    - `flights` is an array where each object has `destination` (a string),
    `price` (a number), and `date` (a string).

    - `summary` is a single string.

    - `isAvailable` is a boolean value.


    ##### Request Example

    Here's an example request using the parameters defined:


    ```json

    {
      "image": "https://cdn.britannica.com/95/94195-050-FCBF777E/Golden-Gate-Bridge-San-Francisco.jpg",
      "prompt": "What are the current flight prices to this location from Hong Kong?",
      "source_blacklist": ["expedia.com"],
      "output_format": {
        "flights": [
          {
            "destination": "string",
            "price": "number",
            "date": "string"
          }
        ],
        "response": "string"
      }
    }

    ```


    In this request:

    - `image` provides an image URL.

    - `prompt` specifies the information sought.

    - `source_blacklist` excludes results from `"expedia.com"`.

    - `output_format` requests a structured response with `flights` (each with
    `destination`, `price`, and `date`) and an additional `response` as a
    summary string.


    #### Response

    The API returns a JSON object formatted according to the `output_format`,
    providing flexibility in structuring the data based on application needs.
  termsOfService: https://api.critique-labs.ai/en/docs/terms-of-service
  contact:
    email: support@critique-labs.ai
  version: 1.5.0
  x-logo:
    url: >-
      https://critique-labs.ai/_next/image?url=%2Fimages%2Ficon_only.png&w=96&q=75
servers:
  - url: https://api.critique-labs.ai
  - url: http://localhost
security: []
paths:
  /v1/search:
    post:
      summary: Search
      operationId: search_v1_search_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CritiqueRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchOutput'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - api_key: []
      x-codeSamples:
        - lang: Python
          source: >-

            import requests

            import base64


            def image_url_to_base64(image_url):
                # Fetch the image from the URL
                response = requests.get(image_url)
                
                # Check if the request was successful
                if response.status_code != 200:
                    raise Exception(f"Failed to fetch image. Status code: {response.status_code}")
                
                # Convert the image content to base64
                base64_encoded_image = base64.b64encode(response.content).decode('utf-8')
                
                return f"data:image/jpeg;base64,{base64_encoded_image}"

            image_url =
            "https://cdn.britannica.com/95/94195-050-FCBF777E/Golden-Gate-Bridge-San-Francisco.jpg"

            base64_string_encoded_image = image_url_to_base64(image_url)


            url = 'https://api.critique-labs.ai/v1/search'

            headers = {
                'Content-Type': 'application/json',
                'X-API-Key': 'REPLACE_KEY_VALUE'
            }

            data = {
                'image': base64_string_encoded_image, ## optional, this is the preferred method of sending an image, though url is also accepted. 
                'prompt': 'how much are flights to this place from Hong Kong right now',
                'source_blacklist': ['expedia.com'], ## optional - specify either source_blacklist or source_whitelist, not both
                # 'source_whitelist': ['kayak.com'], ## optional - specify either source_blacklist or source_whitelist, not both
                'output_format': {'flights': [{"origin": "string", "airline": "string", "destination": "string","price": "number"}], "response": "string"} ## optional. If you want a structured response, you can specify the output format here 

            }


            # Sending a POST request

            response = requests.post(url, headers=headers, json=data)


            # Check for any errors

            if response.status_code != 200:
                raise Exception(f"Request failed with status code {response.status_code}: {response.text}")

            # Print the response body

            print(response.json())
          label: Python
        - lang: JS (fetch)
          source: |

            async function imageUrlToBase64(imageUrl) {
              try {
                // Fetch the image as a Blob
                const response = await fetch(imageUrl);
                
                if (!response.ok) {
                  throw new Error(`Failed to fetch image. Status code: ${response.status}`);
                }
                
                // Convert the response to a base64 encoded string
                const blob = await response.blob();
                const reader = new FileReader();

                return new Promise((resolve, reject) => {
                  reader.onloadend = () => resolve(`data:image/jpeg;base64,${reader.result.split(',')[1]}`);
                  reader.onerror = reject;
                  reader.readAsDataURL(blob);
                });
              } catch (error) {
                console.error("Error converting image to base64:", error);
              }
            }

            async function sendData() {
              const imageUrl = "https://cdn.britannica.com/95/94195-050-FCBF777E/Golden-Gate-Bridge-San-Francisco.jpg";
              const base64StringEncodedImage = await imageUrlToBase64(imageUrl);

              const url = 'https://api.critique-labs.ai/v1/search';
              const headers = {
                'Content-Type': 'application/json',
                'X-API-Key': 'REPLACE_KEY_VALUE'
              };
              const data = {
                image: base64StringEncodedImage, // Optional arg. Preferred method of sending image instead of url
                prompt: 'how much are flights to this place from Hong Kong right now',
                source_blacklist: ['expedia.com'], // Optional - specify either source_blacklist or source_whitelist, not both
                // source_whitelist: ['kayak.com'], // Optional - specify either source_blacklist or source_whitelist, not both
                output_format: {
                  flights: [{"origin": "string", "airline": "string","destination": "string", "price": "number"}],
                  response: "string"
                } // Optional arg. Structured response format
              };

              try {
                const response = await fetch(url, {
                  method: 'POST',
                  headers: headers,
                  body: JSON.stringify(data)
                });

                if (!response.ok) {
                  throw new Error(`Request failed with status code ${response.status}: ${await response.text()}`);
                }

                const responseData = await response.json();
                console.log(responseData);
              } catch (error) {
                console.error("Error sending data:", error);
              }
            }
          label: JS (fetch)
        - lang: curl
          source: |2-

                curl -X POST https://api.critique-labs.ai/v1/search   -H "Content-Type: application/json"   -H "X-API-Key: REPLACE_KEY_VALUE"   -d '{
                    "image": "https://cdn.britannica.com/95/94195-050-FCBF777E/Golden-Gate-Bridge-San-Francisco.jpg",
                    "prompt": "how much are flights to this place from Hong Kong right now",
                    "source_blacklist": ["expedia.com"],
                    "output_format": {
                      "flights": [{"origin": "string", "airline": "string","destination": "string", "price": "number"}],
                      "response": "string"
                    }
                  }'
                  
          label: curl
components:
  schemas:
    CritiqueRequest:
      properties:
        image:
          anyOf:
            - type: string
            - type: 'null'
          title: Image
          description: >-
            Optional, This string can be the url of the image you want to send.
            Alternatively, (and the preferred method) is providing a base64
            encoded string of the image. If providing a url, the link must start
            with https:// and ends with a common image file extension like .jpg,
            .jpeg, .png, .gif, etc.
        prompt:
          type: string
          title: Prompt
          description: The search query, can be as extended or succinct as you like
        output_format:
          anyOf:
            - type: object
            - type: 'null'
          title: Output Format
          description: >-
            Optional, a json schema for the response. This will be used to
            format the response of the agentic search. The types allowed can be
            any of: 

            string 

            number

            boolean

            integer

            array
          default: {}
        source_blacklist:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Source Blacklist
          description: >-
            Optional, a list of strings representing domains you want to exclude
            from the agentic search. ['cnn.com','foxnews.com'].  
          default: []
        source_whitelist:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Source Whitelist
          description: >-
            Optional, a list of strings representing domains you want to include
            in the agentic search. ['cnn.com','foxnews.com']. This is mutually
            exclusive with source_blacklist, if it is not empty,
            source_blacklist must be empty
          default: []
      type: object
      required:
        - prompt
      title: CritiqueRequest
    SearchOutput:
      properties:
        response:
          type: string
          title: Response
        context:
          items:
            $ref: '#/components/schemas/SearchContext'
          type: array
          title: Context
          default: []
        info:
          anyOf:
            - type: object
            - type: 'null'
          title: Info
          default: {}
      type: object
      required:
        - response
      title: SearchOutput
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    SearchContext:
      properties:
        id:
          type: integer
          title: Id
        metadata:
          $ref: '#/components/schemas/SearchMetadata'
      type: object
      required:
        - id
        - metadata
      title: SearchContext
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    SearchMetadata:
      properties:
        title:
          type: string
          title: Title
        url:
          type: string
          title: Url
        content:
          anyOf:
            - type: string
            - type: 'null'
          title: Content
          default: ''
      type: object
      required:
        - title
        - url
      title: SearchMetadata
  securitySchemes:
    api_key:
      type: apiKey
      description: >-
        Your API key for authentication. Get one at
        https://critique-labs.ai/en/dashboard
      in: header
      name: X-API-Key

````