---
updatedAt: 2025-12-16T09:34:40.000Z
agentTools:
  projectIndex: https://developers.kommo.com/llms.txt
---

# Add a source of the type text

## Request parameters

The `code` field defines what a source can be used for in the **AI agent**.\
The field helps the system understand how to use the data. For example, if a source contains a return policy, it should only be used in responses related to product returns.

* If a source has a specific code, the AI ​​agent will not be able to use it in other contexts. For example, a document with code: `'privacy_policy'` won't be used to answer questions about shipping.
* However, the `suggested_reply` feature doesn't take code into account, so all sources can be used to generate answers in the chat.

### AI agent example

```json
{
  "name": "Source 13.02.2025 16:12",
  "lang": "en",
  "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec est neque, iaculis eu viverra id, sollicitudin non orci. Aenean fringilla est sed neque egestas, ac mattis nibh venenatis. Etiam sit amet ornare nisi, eget volutpat mauris. Praesent eget sollicitudin nibh, eu ullamcorper felis. Aliquam vestibulum libero vel neque tristique sagittis. Vivamus ornare, quam id dictum sollicitudin, nisi ex fringilla mi, vitae varius turpis turpis eu arcu. Suspendisse vulputate rhoncus nulla, vehicula scelerisque metus porttitor et. In laoreet erat ut libero consequat convallis. Curabitur eget risus gravida, fringilla massa at, aliquet nunc.",
  "available_functions": ["agent"],
  "code": "privacy_policy"
}
```

You added a source with `available_functions: ["agent"]` and `code: "privacy_policy"`. This means that the AI ​​agent will only use it for responses about privacy policy and will not use it in other topics. The `suggested_reply` functionality will not index this source when searching for an answer.

### AI Suggested Reply example

```json
{
  "name": "Source 27.02.2025 16:35",
  "lang": "es",
  "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec est neque, iaculis eu viverra id, sollicitudin non orci. Aenean fringilla est sed neque egestas, ac mattis nibh venenatis. Etiam sit amet ornare nisi, eget volutpat mauris. Praesent eget sollicitudin nibh, eu ullamcorper felis. Aliquam vestibulum libero vel neque tristique sagittis. Vivamus ornare, quam id dictum sollicitudin, nisi ex fringilla mi, vitae varius turpis turpis eu arcu. Suspendisse vulputate rhoncus nulla, vehicula scelerisque metus porttitor et. In laoreet erat ut libero consequat convallis. Curabitur eget risus gravida, fringilla massa at, aliquet nunc.",
  "available_functions": ["suggested_reply"],
  "code": "shipping_policy"
}
```

You have added a source with `available_functions: ["suggested_reply"]`. When generating responses, this functionality does not check the value of the code field at all, but simply uses any sources available to it with the available functions field.

There are 5 unique policies in total:

* contact information (`contact_information`)
* personal data processing (`privacy_policy`)
* return policy (`return_and_refund_policy`)
* delivery policy (`shipping_policy`)
* terms of service (`terms_of_service`)

**Response parameters**

<Table align={["left","left","left"]}>
  <thead>
    <tr>
      <th>
        Parameter
      </th>

      <th>
        Data type
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        id
      </td>

      <td>
        int
      </td>

      <td>
        ID of the added source
      </td>
    </tr>

    <tr>
      <td>
        name
      </td>

      <td>
        string
      </td>

      <td>
        The name of the added source.
      </td>
    </tr>

    <tr>
      <td>
        updated_at
      </td>

      <td>
        int
      </td>

      <td>
        Time of the last source update. Time format is Unix Timestmp.
      </td>
    </tr>

    <tr>
      <td>
        updated_by
      </td>

      <td>
        int
      </td>

      <td>
        ID of the last user to perform an update on the source.
      </td>
    </tr>

    <tr>
      <td>
        code
      </td>

      <td>
        string
      </td>

      <td>
        Available values:

        1. contact_information
        2. privacy_policy
        3. return_and_refund_policy
        4. shipping_policy
        5. terms_of_service  
           If the source does not have the code, this field does not come in the response.
      </td>
    </tr>
  </tbody>
</Table>

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "kommo-ai-api",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://airewriter.kommo.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "oauth2",
        "flows": {}
      }
    }
  },
  "security": [
    {
      "sec0": []
    }
  ],
  "paths": {
    "/api/v2/sources/text": {
      "post": {
        "summary": "Add a source of the type text",
        "description": "",
        "operationId": "ai-add-source-text",
        "parameters": [
          {
            "name": "X-Language",
            "in": "header",
            "description": "Defines the language of the answer. Might be {en|es|pt|ru}. The default value is English.",
            "schema": {
              "type": "string",
              "enum": [
                "en",
                "es",
                "pt",
                "ru"
              ]
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "RAW_BODY": {
                    "type": "object",
                    "required": [
                      "name",
                      "text",
                      "lang",
                      "available_functions"
                    ],
                    "properties": {
                      "name": {
                        "type": "string",
                        "description": "Source name"
                      },
                      "text": {
                        "type": "string",
                        "description": "From 10 characters to: 5000 for 'agent'; 2000 for 'suggested_reply'"
                      },
                      "lang": {
                        "type": "string",
                        "description": "Possible values: en/es/pt/ru. The language of the content in the file. May differ from the request language."
                      },
                      "available_functions": {
                        "type": "array",
                        "description": "Defines what functionality will use the source. Currently they are separated and cannot be used simultaneously. An array of valid values. Valid values ​​are: suggested_reply/agent. The array must contain only 1 element. Otherwise, a validation error will occur.",
                        "items": {
                          "type": "string"
                        }
                      },
                      "code": {
                        "type": "string",
                        "description": "Optional. If not passed - null will be passed. If value is passed - must be a string. Allowed values: contact_information/privacy_policy/return_and_refund_policy/shipping_policy/terms_of_service.",
                        "enum": [
                          "contact_information",
                          "privacy_policy",
                          "return_and_refund_policy",
                          "shipping_policy",
                          "terms_of_service"
                        ]
                      }
                    }
                  }
                }
              },
              "examples": {
                "AI agent": {
                  "value": {
                    "name": "Source 13.02.2025 16:12",
                    "lang": "en",
                    "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec est neque, iaculis eu viverra id, sollicitudin non orci. Aenean fringilla est sed neque egestas, ac mattis nibh venenatis. Etiam sit amet ornare nisi, eget volutpat mauris. Praesent eget sollicitudin nibh, eu ullamcorper felis. Aliquam vestibulum libero vel neque tristique sagittis. Vivamus ornare, quam id dictum sollicitudin, nisi ex fringilla mi, vitae varius turpis turpis eu arcu. Suspendisse vulputate rhoncus nulla, vehicula scelerisque metus porttitor et. In laoreet erat ut libero consequat convallis. Curabitur eget risus gravida, fringilla massa at, aliquet nunc.",
                    "available_functions": [
                      "agent"
                    ],
                    "code": "privacy_policy"
                  }
                },
                "AI Suggested Reply": {
                  "value": {
                    "name": "Source 27.02.2025 16:35",
                    "lang": "es",
                    "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec est neque, iaculis eu viverra id, sollicitudin non orci. Aenean fringilla est sed neque egestas, ac mattis nibh venenatis. Etiam sit amet ornare nisi, eget volutpat mauris. Praesent eget sollicitudin nibh, eu ullamcorper felis. Aliquam vestibulum libero vel neque tristique sagittis. Vivamus ornare, quam id dictum sollicitudin, nisi ex fringilla mi, vitae varius turpis turpis eu arcu. Suspendisse vulputate rhoncus nulla, vehicula scelerisque metus porttitor et. In laoreet erat ut libero consequat convallis. Curabitur eget risus gravida, fringilla massa at, aliquet nunc.",
                    "available_functions": [
                      "suggested_reply"
                    ],
                    "code": "shipping_policy"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Source is added": {
                    "value": "{\n    \"id\": 27633,\n    \"name\": \"Source 13.02.2025 16:12\",\n    \"updated_at\": 1739451881,\n    \"updated_by\": 8796025,\n    \"code\":\"privacy_policy\"\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer",
                      "example": 27633,
                      "default": 0
                    },
                    "name": {
                      "type": "string",
                      "example": "Source 13.02.2025 16:12"
                    },
                    "updated_at": {
                      "type": "integer",
                      "example": 1739451881,
                      "default": 0
                    },
                    "updated_by": {
                      "type": "integer",
                      "example": 8796025,
                      "default": 0
                    },
                    "code": {
                      "type": "string",
                      "example": "privacy_policy"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "400",
            "content": {
              "application/json": {
                "examples": {
                  "Source already exists": {
                    "value": "{\n   \"code\": 400,\n   \"status\": \"error\",\n   \"detail\": \"This source has already been added. Please select a different source.\",\n   \"error_reason\": \"Source with this name already exists\"\n}\n\n// The error occurs if a source with the same name has already been added. \n// The check is based on the presence of a source with the same file name and file extension. \n// Means that File.doc and File.pdf can be added. \n// !IMPORTANT! It is worth considering that the name of the text source and the file source overlap."
                  },
                  "Exceeding source limits": {
                    "value": "{\n   \"code\": 400,\n   \"status\": \"error\",\n   \"detail\": \"You have reached your source limit. Please delete a source before adding a new one.\",\n   \"error_reason\": \"Source limit reached\"\n}\n\n// Occurs when the limit on sources per account is exceeded.\n// These limits are tied to the type `available_functions`.\n// For `agent` - 100 for paid accounts, 10 - for trial account.\n// For `suggested_reply` - 100 for paid accounts and 10 for trial accounts.\n// Limits do not overlap for different types of functionality."
                  },
                  "Validation errors": {
                    "value": "{\n  \"validation-errors\": [\n    {\n      \"request_id\": \"0\",\n      \"errors\": [\n        {\n          \"code\": \"TooShort\",\n          \"path\": \"text\",\n          \"detail\": \"This value is too short. It should have 10 characters or more.\"\n        },\n        {\n          \"code\": \"FieldMissing\",\n          \"path\": \"available_functions\",\n          \"detail\": \"This field is missing.\"\n        }\n      ]\n    }\n  ],\n  \"title\": \"Bad Request\",\n  \"type\": \"https://httpstatus.es/400\",\n  \"status\": 400,\n  \"detail\": \"Request validation failed\"\n}"
                  }
                },
                "schema": {
                  "oneOf": [
                    {
                      "title": "Source already exists",
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "integer",
                          "example": 400,
                          "default": 0
                        },
                        "status": {
                          "type": "string",
                          "example": "error"
                        },
                        "detail": {
                          "type": "string",
                          "example": "This source has already been added. Please select a different source."
                        },
                        "error_reason": {
                          "type": "string",
                          "example": "Source with this name already exists"
                        }
                      }
                    },
                    {
                      "title": "Exceeding source limits",
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "integer",
                          "example": 400,
                          "default": 0
                        },
                        "status": {
                          "type": "string",
                          "example": "error"
                        },
                        "detail": {
                          "type": "string",
                          "example": "You have reached your source limit. Please delete a source before adding a new one."
                        },
                        "error_reason": {
                          "type": "string",
                          "example": "Source limit reached"
                        }
                      }
                    },
                    {
                      "title": "Validation errors",
                      "type": "object",
                      "properties": {
                        "validation-errors": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "request_id": {
                                "type": "string",
                                "example": "0"
                              },
                              "errors": {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "code": {
                                      "type": "string",
                                      "example": "TooShort"
                                    },
                                    "path": {
                                      "type": "string",
                                      "example": "text"
                                    },
                                    "detail": {
                                      "type": "string",
                                      "example": "This value is too short. It should have 10 characters or more."
                                    }
                                  }
                                }
                              }
                            }
                          }
                        },
                        "title": {
                          "type": "string",
                          "example": "Bad Request"
                        },
                        "type": {
                          "type": "string",
                          "example": "https://httpstatus.es/400"
                        },
                        "status": {
                          "type": "integer",
                          "example": 400,
                          "default": 0
                        },
                        "detail": {
                          "type": "string",
                          "example": "Request validation failed"
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "deprecated": false
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "x-readme-fauxas": true
}
```