Skip to contentSkip to navigationSkip to topbar
On this page

Knowledge Resource


Knowledge provides your Assistant with access to unstructured data sources. This API allows you to programatically upload Knowledge for your Assistant to consume.


Knowledge Properties

knowledge-properties page anchor
Property nameTypeRequiredDescriptionChild properties
descriptionstring

Optional

Not PII

The type of knowledge source.


idstringrequired

The description of knowledge.

Pattern: ^aia_know_*$

account_sidSID<AC>

Optional

The SID of the Account that created the Knowledge resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

knowledge_source_detailsobject

Optional

The details of the knowledge source based on the type.


namestringrequired

The name of the knowledge source.


statusstring

Optional

The status of processing the knowledge source ('QUEUED', 'PROCESSING', 'COMPLETED', 'FAILED')


typestringrequired

The type of knowledge source ('Web', 'Database', 'Text', 'File')


urlstring

Optional

The url of the knowledge resource.


embedding_modelstring

Optional

The embedding model to be used for the knowledge source.


date_updatedstring<date-time>required

The date and time in GMT when the Knowledge was last updated specified in ISO 8601(link takes you to an external page) format.


Create new Knowledge sources

create-new-knowledge-sources page anchor
POST https://assistants.twilio.com/v1/Knowledge

Request body parameters

request-body-parameters page anchor
Encoding type:application/json
Schema
Property nameTypeRequiredDescriptionChild properties
assistant_idstring

Optional

The Assistant ID.

Pattern: ^aia_asst_*$

descriptionstring

Optional

The description of the knowledge source.


knowledge_source_detailsobject

Optional

The details of the knowledge source based on the type.


namestringrequired

The name of the tool.


policyobject

Optional

The policy associated with the knowledge source.


typestringrequired

The type of the knowledge source.


embedding_modelstring

Optional

The embedding model to be used for the knowledge source. It's required for 'Database' type but disallowed for other types.

You can configure Knowledge sources of type: Web, Text, and File from the API.

Give your Assistant a publicly-accessible URL to index information from. See additional details about web crawling limits.

Crawl a websiteLink to code sample: Crawl a website
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createKnowledge() {
11
const knowledge = await client.assistants.v1.knowledge.create({
12
name: "Info about Twilio Alpha",
13
type: "Web",
14
description: "Use this for information about Twilio Alpha or AI Assistants",
15
knowledge_source_details: {
16
source: "https://twilioalpha.com",
17
},
18
});
19
20
console.log(knowledge.description);
21
}
22
23
createKnowledge();

Provide plain text for your Assistant.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createKnowledge() {
11
const knowledge = await client.assistants.v1.knowledge.create({
12
name: "Star Wars Quotes",
13
type: "Text",
14
description: "Use this for famous Star Wars quotes",
15
knowledge_source_details: {
16
content: "This is the ship that made the Kessel Run in fourteen parsecs?",
17
},
18
});
19
20
console.log(knowledge.description);
21
}
22
23
createKnowledge();

Upload a file for your Assistant to reference. See supported file types.

1
const fs = require('fs');
2
// Before running this code, install "form-data" and "axios" using `npm install form-data axios`
3
const FormData = require('form-data');
4
const axios = require('axios');
5
6
// Provision API Keys at twilio.com/console/runtime/api-keys
7
// and set the environment variables. See http://twil.io/secure
8
const apiKey = process.env.TWILIO_API_KEY;
9
const apiSecret = process.env.TWILIO_API_SECRET;
10
11
const uploadUrl = `https://assistants-upload.twilio.com/v1/Knowledge/Upload`;
12
13
const form = new FormData();
14
form.append('name', 'File Demo');
15
form.append('description', 'A description of this file')
16
form.append('type', 'File');
17
form.append('assistant_id', 'aia_asst_xxxxxxxxxxxxxxxx');
18
form.append('file_0', fs.createReadStream('README.md'), {
19
contentType: 'text/markdown',
20
});
21
22
// Create a new Function Version
23
axios
24
.post(uploadUrl, form, {
25
auth: {
26
username: apiKey,
27
password: apiSecret,
28
},
29
headers: form.getHeaders(),
30
})
31
.then((response) => {
32
const newKnowledgeId = response.data.id;
33
console.log(newKnowledgeId);
34
});

GET https://assistants.twilio.com/v1/Knowledge/{id}

Property nameTypeRequiredPIIDescription
idstringrequired

Fetch details about a single Knowledge source

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchKnowledge() {
11
const knowledge = await client.assistants.v1.knowledge("aia_know").fetch();
12
13
console.log(knowledge.description);
14
}
15
16
fetchKnowledge();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"date_created": "2009-07-06T20:30:00Z",
4
"date_updated": "2009-07-06T20:30:00Z",
5
"description": "description",
6
"embedding_model": "embedding_model",
7
"id": "aia_know",
8
"knowledge_source_details": {},
9
"name": "name",
10
"status": "status",
11
"type": "type",
12
"url": "url"
13
}

Fetch status of a Knowledge source

fetch-status-of-a-knowledge-source page anchor

GET https://assistants.twilio.com/v1/Knowledge/{id}/Status

When you create a Knowledge source, Twilio AI Assistants processes the Knowledge so it's accessible to your Assistant. You can fetch the status of processing for a given Knowledge Source.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchKnowledgeStatus() {
11
const knowledgeStatus = await client.assistants.v1
12
.knowledge("aia_know")
13
.knowledgeStatus()
14
.fetch();
15
16
console.log(knowledgeStatus.accountSid);
17
}
18
19
fetchKnowledgeStatus();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"date_updated": "2009-07-06T20:30:00Z",
4
"last_status": "last_status",
5
"status": "status"
6
}

GET https://assistants.twilio.com/v1/Knowledge

Property nameTypeRequiredPIIDescription
AssistantIdstring

Optional


Pageinteger

Optional

The page index. This value is simply for client state.

Minimum: 0

PageSizeinteger

Optional

How many resources to return in each list page. The default is 50, and the maximum is 1000.

Minimum: 1Maximum: 1000

PageTokenstring

Optional

The page token. This is provided by the API.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function listKnowledge() {
11
const knowledge = await client.assistants.v1.knowledge.list({ limit: 20 });
12
13
knowledge.forEach((k) => console.log(k.description));
14
}
15
16
listKnowledge();

Output

1
{
2
"knowledge": [
3
{
4
"description": "description",
5
"id": "aia_know",
6
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
7
"knowledge_source_details": {},
8
"name": "name",
9
"status": "status",
10
"type": "type",
11
"url": "url",
12
"embedding_model": "embedding_model",
13
"date_created": "2009-07-06T20:30:00Z",
14
"date_updated": "2009-07-06T20:30:00Z"
15
}
16
],
17
"meta": {
18
"first_page_url": "https://www.example.com",
19
"key": "key",
20
"next_page_url": "https://www.example.com",
21
"page": 42,
22
"page_size": 42,
23
"previous_page_url": "https://www.example.com",
24
"url": "https://www.example.com"
25
}
26
}

Delete a Knowledge source

delete-a-knowledge-source page anchor
DELETE https://assistants.twilio.com/v1/Knowledge/{id}

Property nameTypeRequiredPIIDescription
idstringrequired

the Knowledge ID.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function deleteKnowledge() {
11
await client.assistants.v1.knowledge("aia_know").remove();
12
}
13
14
deleteKnowledge();

Need some help?

Terms of service

Copyright © 2025 Twilio Inc.