Using Collections via API

This guide covers how to use xAI Collections programmatically through the API.

Overview

Collections allow you to organize and search through documents using the xAI API. You can:

  • Create and manage collections
  • Upload documents to collections
  • Search documents using semantic search
  • Use collections in chat completions

API Endpoints

All Collections API endpoints use the Management API base URL:

Base URL: https://management-api.x.ai/v1/collections

Authentication

Use your Management API key:

Authorization: Bearer YOUR_MANAGEMENT_API_KEY

Creating a Collection

POST /v1/collections

Listing Collections

GET /v1/collections

Adding Documents

POST /v1/collections/COLLECTION_ID/documents/FILE_ID

Searching Documents

Use the main API endpoint for search:

POST https://api.x.ai/v1/documents/search

For complete API reference, see the Collections API documentation.