> Canonical guide: https://developers.foxlight.ai/build/sdk/reference/credentials/
> Contract snapshots: Skulk 2.0.0 (b0af39c79b6b7102b2478062904f1d7cc8619975); SDK 1.0.1 (fe6e0f8737ae343769b8cfc0a67ab112b9efac52). Check the installed runtime when versions differ.

# credentials API

SDK 1.0.1. This reference describes the supported authoring interface.

## `CredentialUnavailable`

A declared credential cannot be resolved; messages contain no secret or path.

## `CredentialSelection`

Protected backend selection shared with the owner, never ordinary settings.

This model is a base for the private owner's management interface. Capability
authors use CredentialReader, which cannot create, rotate or retire entries.

### Fields

```python
root: str
backend: BackendName
namespace: str
```

| Field | Description | Declared defaults and constraints |
| --- | --- | --- |
| `root` | Absolute protected vault directory. | min_length=1; max_length=4096 |
| `backend` | Explicit backend; no discovery or fallback. | default="file" |
| `namespace` | Owner-provisioned native namespace. | pattern="^[a-f0-9]&#123;32}$" |

## `CredentialAccess`

Internal admission projection shared by the native application runtime.

This contains no credential values and grants no filesystem authority. It
must come from an already-admitted startup; it is not a startup validator.
Authors obtain a reader from ApplicationStartup.credentials instead.

### Fields

```python
configuration: str | None
declarations: tuple[tuple[str, bool], ...]
```

| Field | Description | Declared defaults and constraints |
| --- | --- | --- |
| `configuration` | — | — |
| `declarations` | — | — |

## `CredentialReader`

Resolve only this child's declared references without importing the host.

Call read off the event loop: journal lock waits have a two-second timeout and
native resolution uses a bounded, reaped helper. Each read observes the
active alias again, including rotation and retirement. Values are SecretBytes;
errors reveal no values, fingerprints, backend paths or native diagnostics.
Missing selected storage never creates a new store or falls back to another.

### `CredentialReader.__init__`

Retain only trusted startup selection and signed credential declarations.

```python
def __init__(self, startup: Startup | CredentialAccess) -> None:
    ...
```

### `CredentialReader.read`

Read an active value; None means a valid optional input is unconfigured.

An undeclared reference raises ValueError. Required absence, damaged
metadata, missing selected storage and unavailable native backends raise
CredentialUnavailable. The method never changes aliases or versions.

```python
def read(self, reference: str) -> SecretBytes | None:
    ...
```

## `read_contained_credential`

Read a declared value in the SDK-owned, parent-bounded bridge process.

This synchronous entry point starts no helper descendants. Its parent must
enforce a deadline and await this process's actual exit. Normal Python
applications keep using CredentialReader.read, whose native subprocess
containment remains unchanged. No backend or storage fallback is permitted.

```python
def read_contained_credential(access: CredentialAccess, reference: str) -> SecretBytes | None:
    ...
```

## `run_credential_helper`

Handle the SDK-only native reader command before a frozen child's normal CLI.

A child entry point calls this first and returns when it is True. Native
values use private pipes, never argv. Normal child invocations return False.
Pure-Python installations launch the same helper as an isolated module.

```python
def run_credential_helper() -> bool:
    ...
```
