Skip to main content
POST
/
add-knowledge-base-sources
/
{knowledge_base_id}
import Retell from 'retell-sdk';
import fs from 'fs';

const client = new Retell({
  apiKey: 'YOUR_RETELL_API_KEY',
});

async function main() {
  const knowledgeBaseResponse = await client.knowledgeBase.addSources(
    "knowledge_base_xxxxxxxxxxxx",
    {
      knowledge_base_texts: [
        {
          title: "Sample Question",
          text: "Hello, how are you?",
        },
      ],
      knowledge_base_urls: [
        "https://www.retellai.com",
        "https://docs.retellai.com",
      ],
      knowledge_base_files: [
        fs.createReadStream("./sample.txt"),
      ],
    }
  );

  console.log(knowledgeBaseResponse.knowledge_base_id);
}

main();
from retell import Retell

client = Retell(
    api_key="YOUR_RETELL_API_KEY",
)

file = open("./sample.txt", "rb")
knowledge_base_response = client.knowledge_base.add_sources(
    knowledge_base_id="knowledge_base_xxxxxxxxxxxx",
    knowledge_base_texts=[
        {
            "title": "Sample Question",
            "text": "Hello, how are you?",
        },
    ],
    knowledge_base_urls=[
        "https://www.retellai.com",
        "https://docs.retellai.com",
    ],
    knowledge_base_files=[file],
)
print(knowledge_base_response.knowledge_base_id)
file.close()
curl --request POST \
  --url https://api.retellai.com/add-knowledge-base-sources/knowledge_base_xxxxxxxxxxxx \
  --header 'Authorization: Bearer YOUR_RETELL_API_KEY' \
  --form 'knowledge_base_texts=[{"title": "Sample Question", "text": "Hello, how are you?"}]' \
  --form 'knowledge_base_urls=["https://www.retellai.com", "https://docs.retellai.com"]' \
  --form 'knowledge_base_files=@./sample.txt'
{
  "knowledge_base_id": "knowledge_base_a456426614174000",
  "knowledge_base_name": "Sample KB",
  "status": "in_progress",
  "max_chunk_size": 2000,
  "min_chunk_size": 400,
  "knowledge_base_sources": [
    {
      "type": "document",
      "source_id": "<string>",
      "filename": "<string>",
      "file_url": "<string>",
      "file_size": 123
    }
  ],
  "enable_auto_refresh": true,
  "last_refreshed_timestamp": 1703413636133
}
{
"status": "error",
"message": "Invalid request format, please check API reference."
}
{
"status": "error",
"message": "API key is missing or invalid."
}
{
"status": "error",
"message": "Trial has ended, please add payment method."
}
{
"status": "error",
"message": "Account rate limited, please throttle your requests."
}
{
"status": "error",
"message": "An unexpected server error occurred."
}
import Retell from 'retell-sdk';
import fs from 'fs';

const client = new Retell({
  apiKey: 'YOUR_RETELL_API_KEY',
});

async function main() {
  const knowledgeBaseResponse = await client.knowledgeBase.addSources(
    "knowledge_base_xxxxxxxxxxxx",
    {
      knowledge_base_texts: [
        {
          title: "Sample Question",
          text: "Hello, how are you?",
        },
      ],
      knowledge_base_urls: [
        "https://www.retellai.com",
        "https://docs.retellai.com",
      ],
      knowledge_base_files: [
        fs.createReadStream("./sample.txt"),
      ],
    }
  );

  console.log(knowledgeBaseResponse.knowledge_base_id);
}

main();
from retell import Retell

client = Retell(
    api_key="YOUR_RETELL_API_KEY",
)

file = open("./sample.txt", "rb")
knowledge_base_response = client.knowledge_base.add_sources(
    knowledge_base_id="knowledge_base_xxxxxxxxxxxx",
    knowledge_base_texts=[
        {
            "title": "Sample Question",
            "text": "Hello, how are you?",
        },
    ],
    knowledge_base_urls=[
        "https://www.retellai.com",
        "https://docs.retellai.com",
    ],
    knowledge_base_files=[file],
)
print(knowledge_base_response.knowledge_base_id)
file.close()
curl --request POST \
  --url https://api.retellai.com/add-knowledge-base-sources/knowledge_base_xxxxxxxxxxxx \
  --header 'Authorization: Bearer YOUR_RETELL_API_KEY' \
  --form 'knowledge_base_texts=[{"title": "Sample Question", "text": "Hello, how are you?"}]' \
  --form 'knowledge_base_urls=["https://www.retellai.com", "https://docs.retellai.com"]' \
  --form 'knowledge_base_files=@./sample.txt'

Authorizations

Authorization
string
header
required

Authentication header containing API key (find it in dashboard). The format is "Bearer YOUR_API_KEY"

Path Parameters

knowledge_base_id
string
required

The knowledge base id to delete source from.

Example:

"kb_1234567890"

Body

multipart/form-data
knowledge_base_texts
object[]

Texts to add to the knowledge base.

knowledge_base_files
file[]

Files to add to the knowledge base. Limit to 25 files, where each file is limited to 50MB.

knowledge_base_urls
string[]

URLs to be scraped and added to the knowledge base. Must be valid urls.

Example:
[
"https://www.example.com",
"https://www.retellai.com"
]

Response

Successfully created a new knowledge base.

knowledge_base_id
string
required

Unique id of the knowledge base.

Example:

"knowledge_base_a456426614174000"

knowledge_base_name
string
required

Name of the knowledge base. Must be less than 40 characters.

Example:

"Sample KB"

status
enum<string>
required

Status of the knowledge base. When it's created and being processed, it's "in_progress". When the processing is done, it's "complete". When there's an error in processing, it's "error". When it is during kb updating, it's "refreshing_in_progress".

Available options:
in_progress,
complete,
error,
refreshing_in_progress
Example:

"in_progress"

max_chunk_size
integer

Maximum number of characters per chunk when splitting knowledge base content.

Example:

2000

min_chunk_size
integer

Minimum number of characters per chunk. Chunks smaller than this are merged with adjacent chunks.

Example:

400

knowledge_base_sources
object[]

Sources of the knowledge base. Will be populated after the processing is done (when status is "complete").

enable_auto_refresh
boolean

Whether to enable auto refresh for the knowledge base urls. If set to true, will retrieve the data from the specified url every 12 hours.

Example:

true

last_refreshed_timestamp
integer

Last refreshed timestamp (milliseconds since epoch). Only applicable when enable_auto_refresh is true.

Example:

1703413636133