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

# Turn the AI agent on or off for a chat, or switch it

> Sets the AI agent of the chat to ACTIVE or DISABLED. With `agentId`, switches the chat to that agent of the project (404 when there is none, or it is archived; 422 TEST_CHAT on a test chat): it takes the `status` given, else the one the chat had, else ACTIVE, and what the previous agent had queued for the chat (follow-ups, a reply being sent) is dropped. The agent the chat already has only changes the status. Answers 204 with no body.



## OpenAPI

````yaml /api-reference/openapi.json patch /v1/chats/{id}/agent
openapi: 3.0.3
info:
  title: Leadstaker API
  version: 1.0.0
  description: Public REST API for Leadstaker projects.
servers:
  - url: https://n-api.leadstaker.com
    description: Production
security: []
tags:
  - name: Calls
    description: >-
      Phone calls made through the telephony app, with their recording,
      transcript and AI summary.
  - name: Chats
    description: Conversations with a contact over a connected channel.
  - name: Contacts
    description: >-
      People inside a project, holding the custom field values collected about
      them.
  - name: Deals
    description: Opportunities moving through a pipeline, each tied to a contact.
  - name: Field groups
    description: Sections that organize custom fields in the interface.
  - name: Fields
    description: >-
      Custom field definitions, both the built-in ones and the ones a project
      creates.
  - name: Leads
    description: >-
      Chatbot conversations captured in a project, with the answers given and
      where the visitor came from.
  - name: Loss reasons
    description: The catalog of reasons a deal can be marked as lost.
  - name: Messages
    description: Individual messages inside a chat, inbound and outbound.
  - name: Notes
    description: >-
      Free text attached to a contact or a deal, written by a user, an agent, or
      the system.
  - name: Pipelines
    description: Ordered sets of stages a deal travels through.
  - name: Stages
    description: Steps inside a pipeline, including the built-in open and closed ones.
  - name: Tags
    description: Free-form labels attached to deals.
  - name: Tasks
    description: >-
      Follow-up activities with a due date, attached to a deal and assigned to a
      user.
paths:
  /v1/chats/{id}/agent:
    patch:
      tags:
        - Chats
      summary: Turn the AI agent on or off for a chat, or switch it
      description: >-
        Sets the AI agent of the chat to ACTIVE or DISABLED. With `agentId`,
        switches the chat to that agent of the project (404 when there is none,
        or it is archived; 422 TEST_CHAT on a test chat): it takes the `status`
        given, else the one the chat had, else ACTIVE, and what the previous
        agent had queued for the chat (follow-ups, a reply being sent) is
        dropped. The agent the chat already has only changes the status. Answers
        204 with no body.
      operationId: patchChatsByIdAgent
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            minLength: 1
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                  enum:
                    - ACTIVE
                    - DISABLED
                  description: >-
                    ACTIVE or DISABLED. Required without `agentId`; with it, the
                    chat keeps its status when absent (ACTIVE for a chat that
                    had no agent).
                agentId:
                  type: string
                  minLength: 1
                  description: >-
                    Switches the chat to this agent of the project. The chat's
                    current agent only changes the status.
              additionalProperties: false
      responses:
        '204':
          description: No content
        '401':
          description: Missing or invalid credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: The payload failed validation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - apiKey: []
components:
  schemas:
    Error:
      type: object
      required:
        - errorCode
        - message
        - status
      properties:
        errorCode:
          type: string
        message:
          type: string
        status:
          type: integer
        errors:
          type: array
          items:
            type: object
            required:
              - field
              - code
              - message
            properties:
              field:
                type: string
              code:
                type: string
              message:
                type: string
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.