# files.get

Inspect authorized file metadata and current byte availability.

Capability: op_sys_files_get
Protocol: op-sys.capabilities.v1
Runtime: 0.3.0
Availability: Local or hosted ledger operations
Optional integration: false
Canonical page: /docs/reference/op_sys_files_get

## Authority

File upload requires files.upload; metadata and byte reads require files.read. Attaching a file requires records.append and files.read. Erasure requires files.erase and the current ledger revision; hosted legal holds, credential scopes and raw-data policy remain upper bounds.

## 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_files_get \
  --arguments '{"ledger_id":"<ledger_id>","file_id":"<file_id>"}'
```

### Python SDK

```python
import json
from op_sys import OpSys

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

### MCP (initialized connection)

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

### HTTP

```sh
curl --fail-with-body --request GET "$VEYLAR_ENDPOINT/v1/ledgers/$LEDGER_ID/files/$FILE_ID" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "X-Veylar-Tenant: $TENANT_ID"
```

Named CLI command: op-sys files get (use --help for flags).

SDK convenience: client.files.get(…). 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

### file_id

Required; string. 

minLength: 1; maxLength: 128

### Complete input schema

```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "ledger_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "file_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    }
  },
  "required": [
    "ledger_id",
    "file_id"
  ]
}
```

## Behavior

- Inspect authorized file metadata and current byte availability.
- Required rights: files.read. Effective permissions are checked when called.
- File identities bind immutable SHA-256, size and declared media type. A hash is not a grant or public download URL. Record references resolve only with target-ledger permission.
- Files are bounded to 1 GiB, decoded chunks to 1 MiB, and the permissive contract permits 16 attachments per record. Consumer contracts may impose tighter file rules.
- Retry identical chunks at the same offset under the original uploader. Changed bytes or metadata conflict. Complete integrity verification before attaching a file.
- Metadata distinguishes missing, partial, available and erased files. Erasure keeps an identity tombstone; retained attachments do not guarantee that bytes remain available.

## Response

Returns File. See the result schema for exact fields.

### Complete result JSON Schema

```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "ledger_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "file_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "size": {
      "type": "integer",
      "minimum": 0,
      "maximum": 1073741824
    },
    "media_type": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^[a-z0-9][a-z0-9!#$&^_.+-]*/[a-z0-9][a-z0-9!#$&^_.+-]*$"
    },
    "availability": {
      "type": "string",
      "enum": [
        "available",
        "partial",
        "missing",
        "erased",
        "unavailable"
      ]
    },
    "uploaded_bytes": {
      "type": "integer",
      "minimum": 0,
      "maximum": 1073741824
    }
  },
  "required": [
    "ledger_id",
    "file_id",
    "availability"
  ],
  "anyOf": [
    {
      "properties": {
        "availability": {
          "enum": [
            "available",
            "partial"
          ]
        }
      },
      "required": [
        "sha256",
        "size",
        "media_type",
        "uploaded_bytes"
      ]
    },
    {
      "properties": {
        "availability": {
          "enum": [
            "missing",
            "erased",
            "unavailable"
          ]
        }
      }
    }
  ]
}
```


[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: files.get

Permissions: files.read

Retry: read_only; 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, payment_required

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

- file_unavailable: Inspect file availability and finish any partial upload before attaching or reading bytes.
- permission_denied: Check the specific file or target-record permission, credential scope and hosted raw-data policy.
- operation_conflict: Preserve the original file identity, metadata and chunk bytes; use a new ID for new content.
- integrity_failure: Verify declared size, SHA-256, base64 bytes and exact chunk offsets.
- revision_conflict: Read the current ledger revision and reconsider before erasure.
- legal_hold: The service hold prevents removal; do not bypass it.

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

- [ledger-files](/docs/raw/manuals/ledger-files.md)
- [ledger-lifecycle](/docs/raw/manuals/ledger-lifecycle.md)
- [public-capabilities](/docs/raw/manuals/public-capabilities.md)
- [command-output-schema](/docs/raw/manuals/command-output-schema.md)
