# api_keys.create

Create a scoped credential and save its one-time secret to a new private file. Creation is not automatically retried.

Capability: op_sys_api_keys_create
Protocol: op-sys.capabilities.v1
Runtime: 0.3.0
Availability: Configured shared service
Optional integration: false
Canonical page: /docs/reference/op_sys_api_keys_create

## Authority

Workspace owners manage membership invitations. Anyone with a link can preview its offer. Accepting requires a signed-in account with the invited verified email.

## 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_api_keys_create \
  --arguments '{"name":"<name>","scope":"connection","output_file":"<output_file>"}'
```

### Python SDK

```python
import json
from op_sys import OpSys

client = OpSys()
arguments = json.loads("{\"name\":\"<name>\",\"scope\":\"connection\",\"output_file\":\"<output_file>\"}")
result = client.capabilities.call(
    "op_sys_api_keys_create", arguments
)
print(result)
```

### MCP (initialized connection)

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "op_sys_api_keys_create",
    "arguments": {
      "name": "<name>",
      "scope": "connection",
      "output_file": "<output_file>"
    }
  }
}
```

### HTTP

```sh
curl --fail-with-body --request POST "$VEYLAR_ENDPOINT/v1/access/api-keys" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"name":"<name>","scope":"connection","tenant_id":"<tenant_id>"}'
```

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

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

## Parameters

### tenant_id

Optional; string. Organization ID; defaults to the selected organization in supplied clients.

minLength: 1; maxLength: 128

### name

Required; string. 

minLength: 1; maxLength: 256

### scope

Required; string. 

Allowed: "connection", "read", "ingest", "admin"

### restrictions

Optional; object. 


```json
{
  "type": "object",
  "properties": {
    "source_scope_mode": {
      "enum": [
        "all",
        "allowlist"
      ]
    },
    "source_ids": {
      "type": "array",
      "maxItems": 256,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 128
      }
    },
    "namespace_scope_mode": {
      "enum": [
        "all",
        "allowlist"
      ]
    },
    "namespaces": {
      "type": "array",
      "maxItems": 256,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 128
      }
    },
    "allow_raw_payload": {
      "type": "boolean"
    },
    "max_query_limit": {
      "type": "integer",
      "minimum": 1,
      "maximum": 500
    },
    "policy_version": {
      "const": "key-policy-v1"
    }
  },
  "required": [],
  "additionalProperties": false
}
```


### output_file

Required; string. New private file for the generated key; existing paths are rejected.

minLength: 1; maxLength: 256

### Complete input schema

```json
{
  "type": "object",
  "properties": {
    "tenant_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "description": "Organization ID; defaults to the selected organization in supplied clients."
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256
    },
    "scope": {
      "type": "string",
      "enum": [
        "connection",
        "read",
        "ingest",
        "admin"
      ]
    },
    "restrictions": {
      "type": "object",
      "properties": {
        "source_scope_mode": {
          "enum": [
            "all",
            "allowlist"
          ]
        },
        "source_ids": {
          "type": "array",
          "maxItems": 256,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          }
        },
        "namespace_scope_mode": {
          "enum": [
            "all",
            "allowlist"
          ]
        },
        "namespaces": {
          "type": "array",
          "maxItems": 256,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          }
        },
        "allow_raw_payload": {
          "type": "boolean"
        },
        "max_query_limit": {
          "type": "integer",
          "minimum": 1,
          "maximum": 500
        },
        "policy_version": {
          "const": "key-policy-v1"
        }
      },
      "required": [],
      "additionalProperties": false
    },
    "output_file": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256,
      "description": "New private file for the generated key; existing paths are rejected."
    }
  },
  "required": [
    "name",
    "scope",
    "output_file"
  ],
  "additionalProperties": false
}
```

## Behavior

- Workspace invitations offer the Member role. Ledger access is granted independently.
- Read the current membership revision before changing a role or removing a member.
- Follow the returned pagination cursor when listing members or invitations.
- API key creation returns a secret once over HTTP; supplied clients save it to a new private file. Never automatically retry uncertain key creation.

## Response

Returns the account operation result. HTTP returns bearer secrets only where documented; supplied clients retain generated secrets in private files.

### Complete result JSON Schema

```json
{
  "type": "object",
  "description": "Structured authenticated account operation result. Never contains credentials. Login can return sign_in_pending, organization_selection_required, provisioning or ready with next_step; status is a saved authentication observation."
}
```


[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.

No standalone response JSON Schema is published for this operation. The input schema is not a response contract.

## Errors and recovery

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

Canonical operation: api_keys.create

Permissions: organization.admin

Retry: inspect_before_retry; 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)



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

- [account-administration](/docs/raw/manuals/account-administration.md)
- [team-onboarding](/docs/raw/manuals/team-onboarding.md)
- [public-capabilities](/docs/raw/manuals/public-capabilities.md)
- [command-output-schema](/docs/raw/manuals/command-output-schema.md)
