# records.append

Submit a payload for authoritative validation and acceptance under a stable operation identity. Attachments additionally require files.read and completed, verified files in this ledger.

Capability: op_sys_records_append
Protocol: op-sys.capabilities.v1
Runtime: 0.3.0
Availability: Local or hosted ledger operations, including cross-ledger discovery, search and feed.
Optional integration: false
Canonical page: /docs/reference/op_sys_records_append

## Authority

The authenticated issuer-qualified principal must hold the requested ledger permission.

## 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. Request template: replace placeholder IDs and supply complete contract-specific objects before use. This is not a complete runnable workflow.

### CLI

```sh
op-sys --output json tools call op_sys_records_append \
  --arguments '{"ledger_id":"<ledger_id>","payload":"<payload>"}'
```

### Python SDK

```python
import json
from op_sys import OpSys

client = OpSys()
arguments = json.loads("{\"ledger_id\":\"<ledger_id>\",\"payload\":\"<payload>\"}")
result = client.capabilities.call(
    "op_sys_records_append", arguments
)
print(result)
```

### MCP (initialized connection)

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "op_sys_records_append",
    "arguments": {
      "ledger_id": "<ledger_id>",
      "payload": "<payload>"
    }
  }
}
```

### HTTP

```sh
curl --fail-with-body --request POST "$VEYLAR_ENDPOINT/v1/ledgers/$LEDGER_ID/records" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "X-Veylar-Tenant: $TENANT_ID" \
  -H 'Content-Type: application/json' \
  --data '{"payload":"<payload>","operation_id":"<saved-operation-id>"}'
```

Named CLI command: op-sys records append (use --help for flags).

SDK convenience: client.records.append(…). The capability adapter may wrap the result.

## Parameters

### ledger_id

Required; string. Stable ledger identity, local or hosted. A display name is not interchangeable with this ID.

minLength: 1; maxLength: 128

### payload

Required; JSON value. Consumer-defined JSON value validated against the selected admitted contract.



### contract

Optional; object. Contract body when publishing/creating; immutable contract reference when selecting an admitted contract for a write.


```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "contract_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "version": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "digest": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    }
  },
  "required": [
    "contract_id",
    "version",
    "digest"
  ]
}
```


### attachments

Optional; array. 

maxItems: 16
```json
{
  "type": "array",
  "items": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
      "file_id": {
        "type": "string",
        "minLength": 1,
        "maxLength": 128
      },
      "name": {
        "type": "string",
        "minLength": 1,
        "maxLength": 256
      }
    },
    "required": [
      "file_id"
    ]
  },
  "maxItems": 16
}
```


### operation_id

Optional; string. Save before dispatch and reuse with identical input and principal. Required for HTTP append; supplied clients can generate and persist an omitted ID.

minLength: 1; maxLength: 128

### confirmation

Optional; string. 

Allowed: "authoritative", "allow_pending"

### expected_revision

Optional; integer. Revision observed before updating an existing resource. Group/collection creation takes no revision.

minimum: 1; maximum: 9007199254740991

### context_id

Optional; string. Supplied-client context for retained delivery state; not part of authoritative record intent.

minLength: 1; maxLength: 128

### resolved_contract

Optional; object. 


```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "contract_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "version": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "digest": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    }
  },
  "required": [
    "contract_id",
    "version",
    "digest"
  ]
}
```


### Complete input schema

```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "ledger_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "payload": {},
    "contract": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "contract_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "digest": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "required": [
        "contract_id",
        "version",
        "digest"
      ]
    },
    "attachments": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "file_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          }
        },
        "required": [
          "file_id"
        ]
      },
      "maxItems": 16
    },
    "operation_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "confirmation": {
      "type": "string",
      "enum": [
        "authoritative",
        "allow_pending"
      ]
    },
    "expected_revision": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991
    },
    "context_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "description": "Supplied-client context for retained delivery state; not part of authoritative record intent."
    },
    "resolved_contract": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "contract_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "digest": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "required": [
        "contract_id",
        "version",
        "digest"
      ]
    }
  },
  "required": [
    "ledger_id",
    "payload"
  ]
}
```

## Behavior

- Retry: same_operation. Concurrency: none.
- Required rights: records.append, files.read_if_attached. Check discovery for environment availability and effective authorization.
- Configured state rules validate expected versions and allowed transitions atomically with acceptance.
- On state_conflict, inspect records.state and reconsider before submitting new intent; on an uncertain response preserve the original operation ID.
- Inspect the admitted contract before writing.
- Accepted records retain immutable identity and acceptance facts.
- Pending contributions are separate from accepted history.

## Response

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

### Complete result JSON Schema

```json
{
  "anyOf": [
    {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "state": {
          "type": "string",
          "enum": [
            "accepted"
          ]
        },
        "acceptance": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "record_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "operation_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "contract": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "contract_id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 128
                },
                "version": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 128
                },
                "digest": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                }
              },
              "required": [
                "contract_id",
                "version",
                "digest"
              ]
            },
            "authority_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "authority_epoch": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "position": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "accepted_at": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64
            },
            "principal": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "issuer": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 2048
                },
                "subject": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                }
              },
              "required": [
                "issuer",
                "subject"
              ]
            },
            "trust": {
              "type": "string",
              "enum": [
                "local",
                "authenticated"
              ]
            }
          },
          "required": [
            "record_id",
            "operation_id",
            "contract",
            "authority_id",
            "authority_epoch",
            "position",
            "accepted_at",
            "principal",
            "trust"
          ]
        },
        "replayed": {
          "type": "boolean"
        },
        "local_availability": {
          "type": "string",
          "enum": [
            "retained",
            "not_retained",
            "not_applicable"
          ]
        }
      },
      "required": [
        "state",
        "acceptance",
        "replayed",
        "local_availability"
      ]
    },
    {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "state": {
          "type": "string",
          "enum": [
            "pending"
          ]
        },
        "operation_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "context_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "contract": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "contract_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "version": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "digest": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          },
          "required": [
            "contract_id",
            "version",
            "digest"
          ]
        }
      },
      "required": [
        "state",
        "operation_id",
        "context_id",
        "contract"
      ]
    },
    {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "state": {
          "type": "string",
          "enum": [
            "uncertain"
          ]
        },
        "operation_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "context_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "recovery": {
          "type": "string",
          "enum": [
            "check_outcome"
          ]
        }
      },
      "required": [
        "state",
        "operation_id",
        "recovery"
      ]
    }
  ]
}
```


[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: records.append

Permissions: records.append, files.read_if_attached

Retry: same_operation; concurrency: none

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, state_conflict, state_transition_invalid, state_rule_invalid, state_rule_conflict, state_payload_invalid, state_rule_not_found, state_history_limit, record_history_unavailable, payment_required

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

- permission_denied: Inspect the selected principal and ledger grants.
- payload_invalid: Correct the input against the admitted contract.

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

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