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

# Search the web



## OpenAPI

````yaml /openapi.json post /search
openapi: 3.1.0
info:
  title: NinjaChat API
  version: 1.0.0
  description: >-
    Clean-break NinjaChat v1. Chat and Responses bill actual token usage; images
    and videos use catalog unit pricing.
servers:
  - url: https://www.ninjachat.ai/api/v1
security: []
paths:
  /search:
    post:
      summary: Search the web
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchRequest'
      responses:
        '200':
          description: Search results and optional answer.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '400':
          description: Invalid or unsupported request parameter.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '402':
          description: Insufficient balance or project spend limit reached.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate limit exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Gateway error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: javascript
          label: TypeScript SDK
          source: >-
            import { NinjaChat } from "@ninjachat/sdk";


            const client = new NinjaChat({ apiKey:
            process.env.NINJACHAT_API_KEY! });

            const results = await client.search.query({ query: "Latest battery
            storage research" });


            console.log(results);
        - lang: python
          label: Python SDK
          source: >-
            import os

            from ninjachat import NinjaChat


            client = NinjaChat(api_key=os.environ["NINJACHAT_API_KEY"])

            results = client.search.query(query="Latest battery storage
            research")


            print(results)
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
        minLength: 1
        maxLength: 255
      description: >-
        Safely retry the same logical write without duplicate billing or
        execution.
  schemas:
    SearchRequest:
      type: object
      properties:
        query:
          type: string
          minLength: 1
          maxLength: 2000
        group:
          type: string
          enum:
            - web
            - news
          default: web
        max_results:
          type: integer
          minimum: 1
          maximum: 20
          default: 10
        search_depth:
          type: string
          enum:
            - basic
            - advanced
          default: basic
        topic:
          type: string
          enum:
            - general
            - news
            - finance
          default: general
        include_answer:
          type: boolean
          default: true
        include_images:
          type: boolean
          default: false
      required:
        - query
      additionalProperties: false
    SearchResponse:
      type: object
      properties:
        cost:
          type: object
          properties:
            this_request:
              type: string
            per_image:
              type: string
            per_video:
              type: string
            images:
              type: integer
              minimum: 0
          required:
            - this_request
          additionalProperties: false
        balance:
          type: string
        metadata:
          type: object
          properties:
            latency_ms:
              type: number
              minimum: 0
            group:
              type: string
            search_depth:
              type: string
            results_count:
              type: integer
              minimum: 0
          required:
            - latency_ms
          additionalProperties: false
        object:
          type: string
          enum:
            - search.results
        query:
          type: string
        answer:
          type:
            - string
            - 'null'
        sources:
          type: array
          items:
            type: object
            properties:
              url:
                type: string
              title:
                type: string
              content:
                type: string
              published_date:
                type:
                  - string
                  - 'null'
            required:
              - url
              - title
              - content
              - published_date
            additionalProperties: false
        images:
          type: array
          items:
            type: object
            properties:
              url:
                type: string
              description:
                type:
                  - string
                  - 'null'
            required:
              - url
              - description
            additionalProperties: false
        follow_up_questions:
          type: array
          items:
            type: string
        provider:
          type: string
        cost_usd:
          type: number
          minimum: 0
        request_id:
          type: string
      required:
        - object
        - query
        - answer
        - sources
        - follow_up_questions
        - provider
        - cost_usd
        - request_id
      additionalProperties: false
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            code:
              type: string
            param:
              type:
                - string
                - 'null'
          required:
            - message
            - type
            - code
          additionalProperties: false
      required:
        - error
      additionalProperties: false
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: NinjaChat API key
      description: Use an API key created in the NinjaChat developer console.

````