API / list-collections-via-api

API

List collections via the Management API

List collections via the Management API

Inventory every collection on the team with GET https://management-api.x.ai/v1/collections and a Management API key that has Collections permissions. Creating and uploading: Create a collection and upload documents via API.

List

curl "https://management-api.x.ai/v1/collections?limit=100" \
  -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"

Optional query params:

Param Notes
limit Max 100 per page (default 100)
order ORDERING_ASCENDING or ORDERING_DESCENDING (default descending)
sort_by COLLECTIONS_SORT_BY_NAME or COLLECTIONS_SORT_BY_AGE
pagination_token From the previous page
filter AIP-160 string on collection_id, collection_name, created_at, documents_count

Filter examples: collection_name:"SEC" AND documents_count:>10, created_at:>2025-01-01T00:00:00Z.

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"),
)
for collection in client.collections.list():
    print(collection.collection_id, collection.collection_name, collection.documents_count)
const response = await fetch("https://management-api.x.ai/v1/collections?limit=100", {
  headers: { Authorization: `Bearer ${process.env.XAI_MANAGEMENT_API_KEY}` },
});
const data = await response.json();
for (const c of data.collections ?? []) {
  console.log(c.collection_id, c.collection_name, c.documents_count);
}

Each row includes collection_id, collection_name, created_at, documents_count, plus index/chunk config when present. Page with pagination_token until it is absent.

Get one collection

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

Pitfalls

  • List/get/update/delete need the management key. Document search and chat file_search use the regular XAI_API_KEY.
  • limit caps at 100; always follow pagination_token on large teams.
  • Console API credits are a separate bill from SuperGrok's weekly pool on grok.com.