# collections.create

Create a new collection with a caller-selected stable ID. Identical retries return the same resource.

Capability: op_sys_collections_create
Protocol: op-sys.capabilities.v1
Runtime: 0.3.0
Availability: Local store or configured service
Optional integration: false
Canonical page: /docs/reference/op_sys_collections_create

## Authority

Collection administration checks credentials and resource permissions. Queries and feeds recheck access to each selected ledger. Collection access never overrides individual ledger grants.

## Invocation

CLI, SDK and MCP use the same operation and arguments; where a hosted HTTP binding exists, its route carries the same domain contract. Host paths and environment references refer to the runtime host. Illustrative example. Use your own resource identifiers and inputs while preserving the operation’s schema.

### CLI

```sh
op-sys --output json tools call op_sys_collections_create \
  --arguments '{"collection_id":"collection_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","name":"Example","admins":["your-principal"],"read":["your-principal"],"ledger_ids":["ledger_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"]}'
```

### Python SDK

```python
import json
from op_sys import OpSys

client = OpSys()
arguments = json.loads("{\"collection_id\":\"collection_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"name\":\"Example\",\"admins\":[\"your-principal\"],\"read\":[\"your-principal\"],\"ledger_ids\":[\"ledger_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"]}")
result = client.capabilities.call(
    "op_sys_collections_create", arguments
)
print(result)
```

### MCP (initialized connection)

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "op_sys_collections_create",
    "arguments": {
      "collection_id": "collection_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "name": "Example",
      "admins": [
        "your-principal"
      ],
      "read": [
        "your-principal"
      ],
      "ledger_ids": [
        "ledger_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
      ]
    }
  }
}
```

### HTTP

```sh
curl --fail-with-body --request POST "$VEYLAR_ENDPOINT/v1/collections/collection_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "X-Veylar-Tenant: $TENANT_ID" \
  -H 'Content-Type: application/json' \
  --data '{"name":"Example","admins":["your-principal"],"read":["your-principal"],"ledger_ids":["ledger_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"]}'
```

Named CLI command: op-sys collections create (use --help for flags).

SDK convenience: client.collections.create(…). The capability adapter may wrap the result.

## Parameters

### name

Required; string. 

minLength: 1; maxLength: 128

### admins

Required; array. Administrative hosted principal IDs. Group and collection rules apply.

minItems: 1; maxItems: 256
```json
{
  "type": "array",
  "maxItems": 256,
  "uniqueItems": true,
  "items": {
    "type": "string",
    "minLength": 1,
    "maxLength": 128
  },
  "minItems": 1
}
```


### ledger_ids

Required; array. Stable ledger IDs to save in a collection or use directly as a record retrieval scope.

maxItems: 4096
```json
{
  "type": "array",
  "maxItems": 4096,
  "uniqueItems": true,
  "items": {
    "type": "string",
    "pattern": "^ledger_[a-f0-9]{32}$"
  }
}
```


### read

Required; array. Hosted principals or groups allowed to use this collection. Individual ledger grants still apply.

maxItems: 256
```json
{
  "type": "array",
  "maxItems": 256,
  "uniqueItems": true,
  "items": {
    "type": "string",
    "minLength": 1,
    "maxLength": 128
  }
}
```


### collection_id

Required; string. Saved collection to use as the retrieval scope. Supply collection_id or ledger_ids, never both.

pattern: ^collection_[a-f0-9]{32}$

### Complete input schema

```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "admins": {
      "type": "array",
      "maxItems": 256,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 128
      },
      "minItems": 1
    },
    "ledger_ids": {
      "type": "array",
      "maxItems": 4096,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^ledger_[a-f0-9]{32}$"
      }
    },
    "read": {
      "type": "array",
      "maxItems": 256,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 128
      }
    },
    "collection_id": {
      "type": "string",
      "pattern": "^collection_[a-f0-9]{32}$"
    }
  },
  "required": [
    "name",
    "admins",
    "ledger_ids",
    "read",
    "collection_id"
  ]
}
```

## Behavior

- Use collection_id as the stable resource selector. Creation takes no expected_revision. Identical retries return the created resource; conflicting creation fails.
- Resource administration and ledger authorization remain independent.
- Collections save ledger selections; use records.search or records.feed to retrieve records.
- Selection access never supplies a missing ledger grant. Each retrieval rechecks current permissions.

## Response

Returns CollectionsResource. See the complete result schema below; transport envelopes are separate.

### Complete result JSON Schema

```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "admins": {
      "type": "array",
      "maxItems": 256,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 128
      },
      "minItems": 1
    },
    "ledger_ids": {
      "type": "array",
      "maxItems": 4096,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^ledger_[a-f0-9]{32}$"
      }
    },
    "read": {
      "type": "array",
      "maxItems": 256,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 128
      }
    },
    "kind": {
      "enum": [
        "group",
        "collection"
      ]
    },
    "revision": {
      "type": "integer",
      "minimum": 0
    },
    "principal_issuer": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256
    },
    "collection_id": {
      "type": "string",
      "pattern": "^collection_[a-f0-9]{32}$"
    }
  },
  "required": [
    "name",
    "admins",
    "ledger_ids",
    "read",
    "collection_id",
    "kind",
    "revision"
  ]
}
```


[Runtime output field catalog](/docs/output-contracts.json) (descriptive contracts, not JSON Schema validators).

CLI: use --output json. For tools call, read the operation result at payload.tool.result; payload.tool.name identifies the capability. The outer envelope is {schema_version: "v1", payload: {tool: {name, result}}}.

Python: client.capabilities.call(name, arguments) returns the operation result. SDK exceptions preserve reason and code.

MCP: tools/call returns JSON text and structuredContent. Application failures set isError; inspect reason/code instead of matching message text.

Related resource schemas (not necessarily a complete operation response):
- [ledger-core.v1.schema.json](/docs/schemas/ledger-core.v1.schema.json)

## Errors and recovery

[Ledger limits and operation catalog](/docs/ledger-core.json)

Canonical operation: collections.create

Permissions: resource.admin, per_ledger_records.read

Retry: inspect_and_revise; concurrency: resource_identity

Codes: invalid_input, contract_invalid, payload_invalid, contract_not_admitted, permission_denied, not_found, revision_conflict, operation_conflict, unsupported, authority_unavailable, outcome_uncertain, outcome_expired, validation_context_unavailable, file_unavailable, integrity_failure, ledger_archived, ledger_deleted, resnapshot_required, identity_changed, authority_fenced, withdrawal_requires_resolution, limit_exceeded, rate_limited, record_resource_conflict, record_selection_changed, record_cursor_invalid, record_cursor_expired, payment_required

[HTTP status mappings and schemas](/docs/ledger-core.openapi.json)

- record_resource_conflict: Read the current collection revision and reconcile the desired selection before updating.
- permission_denied: Inspect resource administration and ledger permissions.

Family reasons are representative, not exhaustive.

A timeout is not proof that a write failed. Reuse the documented retry identity, batch, offset or mutation ID. If this operation has no documented retry identity, inspect its state before repeating it.

On authorization failure, correct the configured identity or grants; do not change the local actor to impersonate a hosted principal. On validation failure, correct the input against the published schema and selected contract.

On a revision or state conflict, retrieve current state and reconcile intent. Do not automatically overwrite a competing update. Preserve unknown additive response fields when building consumers.

## Source manuals

- [record-collections](/docs/raw/manuals/record-collections.md)
- [public-capabilities](/docs/raw/manuals/public-capabilities.md)
- [command-output-schema](/docs/raw/manuals/command-output-schema.md)
