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

# Query website data using AI

> Use AI to extract specific data points from a brand's website. The AI will crawl the website and extract the requested information based on the provided data points.

<Badge color="orange">10 Credits</Badge>


## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/context.dev/openapi.documented.yml post /brand/ai/query
openapi: 3.0.0
info:
  title: Context API
  description: API for retrieving context data from any website
  version: 1.0.0
servers:
  - url: https://api.context.dev/v1
security: []
paths:
  /brand/ai/query:
    post:
      tags:
        - Web Extraction
      summary: Query website data using AI
      description: >-
        Use AI to extract specific data points from a brand's website. The AI
        will crawl the website and extract the requested information based on
        the provided data points.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - domain
                - data_to_extract
              properties:
                domain:
                  type: string
                  description: The domain name to analyze
                specific_pages:
                  type: object
                  description: Optional object specifying which pages to analyze
                  properties:
                    home_page:
                      type: boolean
                      description: Whether to analyze the home page
                    blog:
                      type: boolean
                      description: Whether to analyze the blog
                    terms_and_conditions:
                      type: boolean
                      description: Whether to analyze the terms and conditions page
                    privacy_policy:
                      type: boolean
                      description: Whether to analyze the privacy policy page
                    about_us:
                      type: boolean
                      description: Whether to analyze the about us page
                    contact_us:
                      type: boolean
                      description: Whether to analyze the contact us page
                    careers:
                      type: boolean
                      description: Whether to analyze the careers page
                    faq:
                      type: boolean
                      description: Whether to analyze the FAQ page
                    pricing:
                      type: boolean
                      description: Whether to analyze the pricing page
                data_to_extract:
                  type: array
                  description: Array of data points to extract from the website
                  items:
                    type: object
                    required:
                      - datapoint_name
                      - datapoint_type
                      - datapoint_description
                      - datapoint_example
                    properties:
                      datapoint_name:
                        type: string
                        description: Name of the data point to extract
                      datapoint_type:
                        type: string
                        enum:
                          - text
                          - number
                          - date
                          - boolean
                          - list
                          - url
                        description: Type of the data point
                      datapoint_list_type:
                        type: string
                        enum:
                          - string
                          - text
                          - number
                          - date
                          - boolean
                          - list
                          - url
                          - object
                        default: string
                        description: >-
                          Type of items in the list when datapoint_type is
                          'list'. Defaults to 'string'. Use 'object' to extract
                          an array of objects matching a schema.
                      datapoint_object_schema:
                        type: object
                        description: >-
                          Schema definition for objects when datapoint_list_type
                          is 'object'. Provide a map of field names to their
                          scalar types.
                        additionalProperties:
                          type: string
                          enum:
                            - string
                            - number
                            - date
                            - boolean
                        minProperties: 1
                        example:
                          testimonial_text: string
                          testimonial_author: string
                      datapoint_description:
                        type: string
                        description: Description of what to extract
                      datapoint_example:
                        type: string
                        description: Example of the expected value
                timeoutMS:
                  $ref: '#/components/schemas/TimeoutMS'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    description: Status of the response, e.g., 'ok'
                  domain:
                    type: string
                    description: The domain that was analyzed
                  urls_analyzed:
                    type: array
                    description: List of URLs that were analyzed
                    items:
                      type: string
                  data_extracted:
                    type: array
                    description: Array of extracted data points
                    items:
                      type: object
                      properties:
                        datapoint_name:
                          type: string
                          description: Name of the extracted data point
                        datapoint_value:
                          oneOf:
                            - type: string
                            - type: number
                            - type: boolean
                            - type: array
                              items:
                                type: string
                            - type: array
                              items:
                                type: number
                            - type: array
                              items:
                                type: object
                          description: >-
                            Value of the extracted data point. Can be a
                            primitive type, an array of primitives, or an array
                            of objects when datapoint_list_type is 'object'.
        '400':
          description: Bad Request - validation error
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  error_code:
                    type: string
                    enum:
                      - INTERNAL_ERROR
                      - VALID
                      - NOT_FOUND
                      - FORBIDDEN
                      - USAGE_EXCEEDED
                      - RATE_LIMITED
                      - UNAUTHORIZED
                      - DISABLED
                      - INSUFFICIENT_PERMISSIONS
                      - TIMEOUT_EXCEEDS_MAXIMUM
                      - WEBSITE_ACCESS_ERROR
                      - INPUT_VALIDATION_ERROR
                    description: Error code indicating the type of error
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  error_code:
                    type: string
                    enum:
                      - INTERNAL_ERROR
                      - VALID
                      - NOT_FOUND
                      - FORBIDDEN
                      - USAGE_EXCEEDED
                      - RATE_LIMITED
                      - UNAUTHORIZED
                      - DISABLED
                      - INSUFFICIENT_PERMISSIONS
                      - TIMEOUT_EXCEEDS_MAXIMUM
                      - WEBSITE_ACCESS_ERROR
                      - INPUT_VALIDATION_ERROR
                    description: Error code indicating the type of error
        '408':
          description: Request Timeout
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Timeout error message
                  error_code:
                    type: string
                    enum:
                      - REQUEST_TIMEOUT
                    description: Error code indicating request timeout
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  error_code:
                    type: string
                    enum:
                      - INTERNAL_ERROR
                    description: Error code indicating internal server error
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import ContextDev from 'context.dev';

            const client = new ContextDev({
              apiKey: process.env['CONTEXT_DEV_API_KEY'], // This is the default and can be omitted
            });

            const response = await client.ai.aiQuery({
              data_to_extract: [
                {
                  datapoint_description: 'datapoint_description',
                  datapoint_example: 'datapoint_example',
                  datapoint_name: 'datapoint_name',
                  datapoint_type: 'text',
                },
              ],
              domain: 'domain',
            });

            console.log(response.data_extracted);
        - lang: Python
          source: |-
            import os
            from context.dev import ContextDev

            client = ContextDev(
                api_key=os.environ.get("CONTEXT_DEV_API_KEY"),  # This is the default and can be omitted
            )
            response = client.ai.ai_query(
                data_to_extract=[{
                    "datapoint_description": "datapoint_description",
                    "datapoint_example": "datapoint_example",
                    "datapoint_name": "datapoint_name",
                    "datapoint_type": "text",
                }],
                domain="domain",
            )
            print(response.data_extracted)
        - lang: Ruby
          source: |-
            require "context_dev"

            context_dev = ContextDev::Client.new(api_key: "My API Key")

            response = context_dev.ai.ai_query(
              data_to_extract: [
                {
                  datapoint_description: "datapoint_description",
                  datapoint_example: "datapoint_example",
                  datapoint_name: "datapoint_name",
                  datapoint_type: :text
                }
              ],
              domain: "domain"
            )

            puts(response)
components:
  schemas:
    TimeoutMS:
      type: integer
      minimum: 1000
      maximum: 300000
      description: >-
        Optional timeout in milliseconds for the request. If the request takes
        longer than this value, it will be aborted with a 408 status code.
        Maximum allowed value is 300000ms (5 minutes).
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````