API / delete-a-collection-via-api

API

Delete a collection via the Management API

Delete a collection via the Management API

Remove an entire collection with DELETE https://management-api.x.ai/v1/collections/{collection_id} and a Management API key that has Collections Endpoint delete permission. This drops the collection record and its index. To remove one file while keeping the collection, use Delete a document from a collection. Broader list/update/delete overview: List, update, and delete collections via API.

Delete

curl -X DELETE "https://management-api.x.ai/v1/collections/$COLLECTION_ID" \
  -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"

Optional query param: team_id when the key can see more than one team; otherwise the team comes from the credentials. A successful response body is an empty JSON object {}.

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.delete(
    collection_id="collection_dbc087b1-6c99-493d-86c6-b401fee34a9d"
)
const collectionId = "collection_dbc087b1-6c99-493d-86c6-b401fee34a9d";
await fetch(`https://management-api.x.ai/v1/collections/${collectionId}`, {
  method: "DELETE",
  headers: { Authorization: `Bearer ${process.env.XAI_MANAGEMENT_API_KEY}` },
});

Pitfalls

  • Delete is permanent for that collection id. Recreate if you still need the index; uploaded Files API objects may still exist under api.x.ai until you delete them separately.
  • Management key on management-api.x.ai only. Document search and chat file_search keep using XAI_API_KEY.
  • Mint the management key in Console → Management Keys and copy it once.
  • Console API credits are a separate bill from SuperGrok's weekly pool on grok.com.