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

# Search

> Execute a search query.



## OpenAPI

````yaml POST /v1/search
openapi: 3.1.0
info:
  title: AI Search API
  description: >-
    Power your LLM and AI agents with live web data through our cost-effective
    search API
  version: 1.0.0
servers:
  - url: https://api.aisearchapi.io
security:
  - bearerAuth: []
paths:
  /v1/search:
    post:
      description: Execute a search query.
      requestBody:
        description: Search request
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchRequest'
            example:
              prompt: What are some security risks I should be aware of?
              context:
                - role: user
                  content: I am developing a web app using Node.js and Express.
                - role: user
                  content: The app stores personal data, including names and emails.
                - role: user
                  content: We plan to deploy it on AWS.
              response_type: markdown
        required: true
      responses:
        '200':
          description: Search response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
              example:
                answer: >-
                  ### Node.js Security Risks and Mitigation Strategies


                  When developing Node.js applications that handle personal data
                  and deploy to AWS, you should be aware of several critical
                  security risks:


                  **Authentication and Authorization**

                  - Implement secure session management

                  - Use strong password policies and multi-factor authentication

                  - Avoid hardcoded credentials in your code


                  **Data Protection**

                  - Encrypt sensitive data both in transit and at rest

                  - Implement proper input validation and sanitization

                  - Use HTTPS for all data transmission


                  **Infrastructure Security**

                  - Keep Node.js and dependencies up to date

                  - Configure AWS security groups properly

                  - Use AWS IAM roles with least privilege principle


                  **Application Security**

                  - Protect against common vulnerabilities like XSS, CSRF, and
                  SQL injection

                  - Implement rate limiting and request throttling

                  - Use security headers like HSTS, CSP, and X-Frame-Options
                response_type: markdown
                sources:
                  - https://owasp.org/www-project-nodejs-goat/
                  - https://nodejs.org/en/docs/guides/security/
                  - https://aws.amazon.com/security/security-learning/
                response_time: 2847
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  description: Invalid or expired API key
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  description: Too Many Requests
        '433':
          description: Account is at / over message quota
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  description: Account is at / over message quota
        '500':
          description: Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  description: Server Error
      x-codeSamples:
        - lang: javascript
          label: Node.js SDK
          source: |-
            import { AISearchAPIClient } from 'aisearchapi-client';

            const client = new AISearchAPIClient({ 
              apiKey: 'YOUR_API_KEY' 
            });

            const response = await client.search({
              prompt: 'What are some security risks I should be aware of?',
              context: [{
                role: 'user', 
                content: 'I am developing a web app using Node.js and Express.'
              }],
              response_type: 'markdown'
            });

            console.log(response);
        - lang: python
          label: Python SDK
          source: |-
            from aisearchapi_client import AISearchAPIClient, ChatMessage

            client = AISearchAPIClient(api_key="YOUR_API_KEY")
            response = client.search(
                prompt="What are some security risks I should be aware of?",
                context=[
                    ChatMessage(role="user", content="user conversation context for the LLM")
                ],
                response_type="markdown"
            )

            print(response)
components:
  schemas:
    SearchRequest:
      required:
        - prompt
      type: object
      properties:
        prompt:
          description: The search query.
          type: string
        context:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessage'
          description: >-
            An ordered list of message objects that define the conversation
            context for the LLM. Each message contains a role and content.
            Currently, only the "user" role is supported.
        response_type:
          type: string
          enum:
            - text
            - markdown
          default: markdown
          description: >-
            The optional format parameter can be "text" or "markdown" (default).
            "text" returns plain text without formatting, useful for logs or
            custom-styled outputs. "markdown" includes rich formatting (bold,
            italics, lists, code, links) for apps that can render Markdown. If
            omitted, the API defaults to "markdown".
    SearchResponse:
      required:
        - answer
        - response_type
        - sources
        - response_time
      type: object
      properties:
        answer:
          description: >-
            The main response generated by the API based on the provided prompt
            and context.
          type: string
        response_type:
          description: The format of the response, as specified by the user.
          type: string
        sources:
          description: The list of sources used to generate the response.
          type: array
          items:
            type: string
        response_time:
          description: The total time taken to generate the response, in milliseconds.
          type: number
    Error:
      required:
        - error
      type: object
      properties:
        error:
          type: object
          properties:
            description:
              type: string
    ChatMessage:
      required:
        - role
        - content
      type: object
      properties:
        role:
          description: >-
            Currently, only messages with the role "user" are considered when
            generating the context for the LLM. No other roles are supported at
            this time.
          type: string
        content:
          description: >-
            The contents of the message. Previous messages can be included here
            to enhance the model's context, which will influence the final
            response generated.
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````