> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nalhajery.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Collection

> Create a new API collection (admin only)

## Authentication

<ParamField header="Authorization" type="string" required>
  Bearer token: `Bearer <admin_token>`
</ParamField>

<Note>
  This endpoint requires admin privileges.
</Note>

## Request Body

<ParamField body="name" type="string" required>
  Collection display name
</ParamField>

<ParamField body="description" type="string" required>
  Collection description (used for semantic search)
</ParamField>

<ParamField body="openapi_spec" type="object" required>
  Full OpenAPI 3.0 specification including servers, paths, and authentication
</ParamField>

### Example Request

```bash theme={null}
curl -X POST https://api.sari-platform.com/api/collections/ \
  -H "Authorization: Bearer <admin_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My API",
    "description": "API description for semantic search",
    "openapi_spec": {
      "openapi": "3.0.0",
      "info": {
        "title": "My API",
        "version": "1.0"
      },
      "servers": [
        {"url": "https://api.example.com"}
      ],
      "paths": {
        "/users": {
          "get": {
            "summary": "List users",
            "responses": {
              "200": {
                "description": "Success"
              }
            }
          }
        }
      }
    }
  }'
```

## Response

```json theme={null}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "My API",
  "description": "API description for semantic search",
  "created_at": "2024-01-15T10:00:00Z"
}
```

## What Happens

1. **Collection Created** - Stored in database
2. **Vector Generated** - Embedding created from name + description
3. **Cache Invalidated** - Collection lists refreshed

## Errors

| Status | Description                    |
| ------ | ------------------------------ |
| 400    | Invalid OpenAPI spec           |
| 401    | Invalid or expired token       |
| 403    | Admin access required          |
| 409    | Collection name already exists |
