
Delete a document from a Grok collection
Delete a document from a Grok collection
Removing one document from a collection uses the Management API (https://management-api.x.ai/v1) with a Management API key that has Collections permissions. The regular XAI_API_KEY is for search and chat, not for this delete. Create / upload path: Create a collection and upload documents via API.
Delete one document
You need the collection_id and the document file_id (returned on upload or from a document list / get).
curl https://management-api.x.ai/v1/collections/$COLLECTION_ID/documents/$FILE_ID \
-X DELETE \
-H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
import os
from xai_sdk import Client
client = Client(
api_key=os.getenv("XAI_API_KEY"),
management_api_key=os.getenv("XAI_MANAGEMENT_API_KEY"),
)
client.collections.remove_document(
collection_id="collection_dbc087b1-6c99-493d-86c6-b401fee34a9d",
file_id="file_55a709d4-8edc-4f83-84d9-9f04fe49f832",
)
const collectionId = "collection_dbc087b1-6c99-493d-86c6-b401fee34a9d";
const fileId = "file_55a709d4-8edc-4f83-84d9-9f04fe49f832";
await fetch(
`https://management-api.x.ai/v1/collections/${collectionId}/documents/${fileId}`,
{
method: "DELETE",
headers: { Authorization: `Bearer ${process.env.XAI_MANAGEMENT_API_KEY}` },
},
);
Deleting a document removes it from that collection’s index. Search with file_search / collections_search will stop returning chunks from that file after processing catches up.
Delete the whole collection
curl https://management-api.x.ai/v1/collections/$COLLECTION_ID \
-X DELETE \
-H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
That removes the collection itself. Prefer document delete when you only need to drop one file.
Pitfalls
- Using
XAI_API_KEYonmanagement-api.x.ai— management calls need the Management key. - Confusing Files API delete (global file object) with collection document remove (membership + index). Use the collections documents DELETE path above when the goal is “out of this collection.”