https://retellai.com/?utm_source=discord&utm_medium=seo logo
create a KB using the API
# ❓・ai-evy-support
s
@AI Evy create a KB using the API
a
Thanks for tagging me @Sanjay. I'll look through relevant sources and get back to you shortly.
​ To learn more, see the sources I considered: [[1] Create Knowledge Base](https://docs.retellai.com/api-references/create-knowledge-base) [[2] API/Backend Integration for Knowledge Base Management](https://discord.com/channels/1186424376300679209/1438153573287334000) ​
### Answer To create a Knowledge Base using the API, use the following JavaScript code: [(1) ]()
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
 apiKey: 'YOUR_RETELL_API_KEY',
}) ;
async function main() {
 const knowledgeBaseResponse = await client.knowledgeBase.create({
 knowledge_base_name: "Sample KB",
 knowledge_base_texts: [
 {
 text: "Hello, how are you?",
 title: "Sample Question",
 },
 ],
 knowledge_base_urls: [
 "<https://www.retellai.com%22,>
 "<https://docs.retellai.com%22,>
 ],
 knowledge_base_files: [
 fs.createReadStream("../sample.txt") ,
 ],
 }) ;
 console.log(knowledgeBaseResponse.knowledge_base_id) ;
}
main() ;
The endpoint is
POST /create-knowledge-base
. You can include texts, URLs, or files as sources. The Knowledge Base name must be less than 40 characters. You can enable auto-refresh for URLs to retrieve data every 12 hours by setting
enable_auto_refresh: true
. Important note: Based on community reports, if you encounter HTTP 500 errors when creating a KB via API, you may need to use the SDK rather than direct HTTP requests. [(2) ]()
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.