POST
/v1/convai/agents/{agent_id}/knowledge-base/rag-query
ElevenLabs APIQuery Agent Knowledge Base Rag
- Base URL
- https://api.elevenlabs.io
- Auth
- xi-api-key: <ELEVENLABS_API_KEY>
- Last verified
- 2026-09-03 · upstream hash matched
Actions
Agents: curl -H "Accept: text/markdown" this URL
→ 225 tokens · Vary: Accept
→ 225 tokens · Vary: Accept
Critical gotchas
Authentication uses the non-standard xi-api-key header, not Authorization: Bearer. Sending a Bearer token returns HTTP 401.
Text-to-speech responses are raw binary audio, not JSON. Write the body to a file (--output speech.mp3) rather than parsing it.
cURL
curl -X POST 'https://api.elevenlabs.io/v1/convai/agents/agent-id/knowledge-base/rag-query?branch_id=branch-id' \ -H "xi-api-key: $ELEVENLABS_API_KEY" \ -H 'Content-Type: application/json' \ -d '{ "query": "string", "use_agent_defaults": true}'Get a free ElevenLabs API key → sponsored
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| agent_id | path | string | Yes | The id of an agent. This is returned on agent creation. |
| branch_id | query | string | No | The ID of the branch to use |
| query | body | string | Yes | Query to run against the agent's knowledge base RAG index. |
| use_agent_defaults | body | boolean | No | When true (the default), retrieval uses the agent's own RAG settings, reproducing exactly what the agent would retrieve. Set to false to retrieve with neutral default RAG settings instead (the agent's embedding model is always kept, since it determines which vector index exists). Useful for auditing the knowledge base independently of how a particular agent is tuned. |
Response 200 OK
{
"chunks": [
{
"chunk_id": "chunk_498cjVigY5qzO86Huf0OWal",
"content_format": "html",
"document_id": "doc_J3Pbu5gP6NNKBscdCdwB",
"document_name": "Account FAQ",
"document_type": "file",
"text": "To reset your password, open Settings and choose Security...",
"vector_distance": 0.21
}
],
"retrieval_query": "How do I reset my password?"
}