https://retellai.com/?utm_source=discord&utm_medium=seo logo
why I'm having error 500 server error on creating ...
# ❓・ai-evy-support
m
@AI Evy why I'm having error 500 server error on creating a knowledgebase via API? https://docs.retellai.com/api-references/create-knowledge-base
a
Thanks for tagging me @marvin_17392. I'll look through relevant sources and get back to you shortly.
### Answer Based on the available information, there are a few common causes for 500 Internal Server Error when creating a knowledge base via API: [(1) ]() [(2) ]() Key Issue: Request Format The knowledge base API requires a
multipart/form-data
body, not
application/json
. [(2) ]() This is a common cause of the 500 error. Working Example:
Copy code
javascript
import Retell from 'retell-sdk';
import fs from 'fs';

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

async function main() {
    try {
        const formData = new FormData() ;

        const fileContent = fs.readFileSync('./test.txt') ;
        const fileBlob = new Blob([fileContent], { type: 'text/plain' }) ;

        formData.append('knowledge_base_name', 'KB_Name') ;
        formData.append('knowledge_base_files', fileBlob, 'FILE_NAME.txt') ;

        const response = await fetch('<https://api.retellai.com/create-knowledge-base',> {
            method: 'POST',
            headers: {
                'Authorization': `Bearer ${client.apiKey}`,
            },
            body: formData,
        }) ;

        if (!response.ok) {
            const errorText = await response.text() ;
            console.error('Error creating knowledge base:', errorText) ;
            return;
        }

        const result = await response.json() ;
        console.log('Knowledge base created successfully:', result) ;

    } catch (error) {
        console.error('Error:', error) ;
    }
}

main() ;
[(1) ]() Common Mistakes: 1. Using
application/json
instead of
multipart/form-data
[(2) ]() 2. Not properly formatting the
knowledge_base_name
as a string [(1) ]() 3. For URLs, ensure they're properly formatted as a JSON-serialized list of strings, for example: `"[' [(2) ]() If you're still experiencing issues after verifying your request format, the Retell team may be working on knowledge base infrastructure issues. [(1) ]() **
​ To learn more, see the sources I considered: [[1] internal server error on create knowledge base by API](https://discord.com/channels/1186424376300679209/1391417148215136376) [[2] KB api - 500 internal server error ⚠](https://discord.com/channels/1186424376300679209/1302061605667995650) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.