# POST /v1/convai/agents/{agent_id}/knowledge-base/rag-query (ElevenLabs API)
Base URL: https://api.elevenlabs.io
Auth: xi-api-key: <ELEVENLABS_API_KEY>
Last verified: 2026-09-03

> Query Agent Knowledge Base Rag

## 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}'

## Parameters
| Name | In | Type | Required | Description |
| :--- | :--- | :--- | :--- | :--- |
| agent_id | path | string | Yes | The id of an agent. This is returned... |
| query | body | string | Yes | Query to run against the agent's know... |
| branch_id | query | string | No | The ID of the branch to use |

## Response (200 OK)
{"chunks":[{}],"retrieval_query":"How do I reset my password?"}

---
Need an API key? Get one at https://elevenlabs.io/app/sign-up