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

> Creates a new API tool configuration for the application. Use this endpoint to define a custom API endpoint that agents can call during conversations.  **Uniqueness:** The slug must be unique per appl

# Create API Tool

For the complete error reference, see [Error Guide](/rest-api/ai-agents-apis/error-codes).


## OpenAPI

````yaml post /ai-agents/agent-builder/api-tools
openapi: 3.0.0
info:
  title: AI Agents APIs
  description: API reference for CometChat AI Agents service
  version: '1.0'
servers:
  - url: https://{appId}.api-{region}.cometchat.io/v3
    variables:
      appId:
        default: appId
        description: (Required) App ID
      region:
        enum:
          - us
          - eu
          - in
        default: us
        description: Select Region
security: []
tags:
  - name: ai-agent
    description: ''
paths:
  /ai-agents/agent-builder/api-tools:
    post:
      tags:
        - Agent Builder API Tools
      summary: Create API Tool
      description: >-
        Creates a new API tool configuration for the application. Use this
        endpoint to define a custom API endpoint that agents can call during
        conversations.


        **Uniqueness:** The slug must be unique per application.
      operationId: ApiToolsController_createApiTool
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateApiToolDto'
      responses:
        '201':
          description: API tool created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  _id:
                    type: string
                    example: myapp_my-api-tool
                  appId:
                    type: string
                    example: my-app-id
                  slug:
                    type: string
                    example: my-api-tool
                  name:
                    type: string
                    example: My API Tool
                  description:
                    type: string
                    example: Calls an external API
                  icon:
                    type: string
                    example: https://example.com/icon.png
                  endpoint:
                    type: string
                    example: https://api.example.com/search
                  method:
                    type: string
                    example: GET
                  enableBasicAuth:
                    type: boolean
                    example: false
                  headers:
                    type: string
                    nullable: true
                    example: '{"Content-Type":"application/json"}'
                  bodyTemplate:
                    type: string
                    nullable: true
                    example: '{"query":"{{query}}"}'
                  allowAdditionalProperties:
                    type: boolean
                    example: false
                  parameters:
                    type: array
                    items:
                      type: object
                      properties:
                        key:
                          type: string
                          example: query
                        type:
                          type: string
                          example: string
                        description:
                          type: string
                          example: The search query
                        required:
                          type: boolean
                          example: true
                  tool:
                    type: object
                    properties:
                      name:
                        type: string
                        example: my-api-tool
                      description:
                        type: string
                        example: Calls an external API
                      parameters:
                        type: object
                        example:
                          type: object
                          properties: {}
                          required: []
                  createdAt:
                    type: number
                    example: 1700000000000
                  updatedAt:
                    type: number
                    example: 1700000000000
      security:
        - apiKey: []
components:
  schemas:
    CreateApiToolDto:
      type: object
      properties:
        slug:
          type: string
          description: Slug for the API tool (unique)
          example: create_lead
        description:
          type: string
          description: Description of the API tool
          example: When to use, preconditions, what it returns
        endpoint:
          type: string
          description: API endpoint URL
          example: https://api.example.com/leads
        method:
          type: string
          description: HTTP method
          example: POST
          enum:
            - GET
            - POST
            - PUT
            - PATCH
            - DELETE
        enableBasicAuth:
          type: boolean
          description: Whether to enable basic authentication
          example: true
        basicAuthUsername:
          type: string
          description: Basic auth username (required if enableBasicAuth is true)
          example: username
        basicAuthPassword:
          type: string
          description: Basic auth password (required if enableBasicAuth is true)
          example: password
        headers:
          type: string
          description: >-
            HTTP headers as a JSON string (e.g., '{"Content-Type":
            "application/json", "Authorization": "Bearer token"}')
          example: >-
            {"Content-Type": "application/json", "Authorization": "Bearer
            token"}
        bodyTemplate:
          type: string
          description: Body template for the API request
          example: '{"name": "{{name}}", "email": "{{email}}"}'
        allowAdditionalProperties:
          type: boolean
          description: Whether to allow additional properties
          example: false
          default: false
        parameters:
          description: Array of parameters for the API tool
          type: array
          items:
            type: object
            properties:
              key:
                type: string
                description: Parameter key/name
                example: email
              type:
                type: string
                description: Parameter type
                example: string
              description:
                type: string
                description: Parameter description
                example: Email of the lead
              required:
                type: boolean
                description: Whether the parameter is required
                example: false
            required:
              - key
              - type
              - description
        icon:
          type: string
          description: Icon for the API Tool
          example: http://localhost:3001
        name:
          type: string
          description: Name of the API tool
          example: Create Lead
      required:
        - slug
        - description
        - endpoint
        - method
        - enableBasicAuth
        - name
  securitySchemes:
    apiKey:
      type: apiKey
      description: API Key (i.e. Rest API Key from the Dashboard).
      name: apikey
      in: header

````