Models¶
This page is the API reference for ModelCatalog, the pre-launch model check that Dispatcher runs by default.
Summary¶
ModelCatalog(runner=None): checks that a model name exists for a harness; loaded lists are cached per instance.
| Member | Purpose |
|---|---|
.models(harness) -> list[str] |
known model names: codex/opencode run their catalogue command once per instance; claude has no catalogue command and returns PHD's static list |
.validate(harness, model) -> list[str] |
warnings if acceptable; raises ModelNotSupported if unknown |
Sources:
| Harness | Source | If the source fails |
|---|---|---|
| claude | built-in list: aliases opus, sonnet, haiku, fable + known ids; any other claude-... id passes with a warning; a [1m]-style suffix is ignored |
n/a (no command) |
| codex | codex debug models (JSON, slug of each entry) |
warning, model not checked |
| opencode | opencode models (lines with / and no space) |
warning, model not checked |
A catalogue proves only that a model exists. A model the account cannot use fails after launch with
error.kind == "model_unavailable".
from phd import Dispatcher, ModelCatalog
catalog = ModelCatalog()
catalog.validate("claude", "claude-opus-5-5") # []
Dispatcher(spec, catalog=catalog) # reuse one catalogue (and its cache) across dispatchers
Dispatcher(spec, validate_model=False) # skip the check
The runner argument (a function taking an argv list and returning stdout) lets tests inject fake catalogue
output.
Full reference¶
Rendered from the docstrings (MkDocs site only).
ModelCatalog ¶
ModelCatalog(runner: Runner | None = None, *, executables: dict[str, list[str]] | None = None)
Checks that a model name exists for a harness before launch.
Sources: codex runs codex debug models (JSON slugs); opencode runs opencode models
(provider/model lines); claude has no catalogue command, so PHD uses built-in aliases
(opus, sonnet, haiku, fable) and known ids, and accepts any other claude-* id with a
warning. Loaded lists are cached per instance; with the default runner they are also cached per
process (per harness, executable and credential), so repeated Dispatchers run each catalogue command once.
The default runner never uses the host's harness setup: the command gets the host environment minus every
ANTHROPIC_/CLAUDE_/CODEX_/OPENAI_/OPENCODE_/XDG_ variable, PHD-owned folders under the PHD cache
($PHD_CACHE_DIR, default ~/.phd/cache) as its harness home and cwd, and the given credentials. Without
credentials it still runs isolated, but codex and opencode then list only the models that need no login.
models and validate block while a catalogue loads: call them from a worker thread in async code. A catalogue proves only that a model exists;
whether the account may use it shows up after launch as error.kind="model_unavailable".
Example
cat = ModelCatalog()
cat.validate("claude", "sonnet") # [] (no warnings)
cat.models("opencode", spec.credentials) # runs `opencode models`, isolated
Create an empty catalogue; nothing is loaded until first use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runner
|
Runner | None
|
Function that runs a CLI argv and returns its stdout. Defaults to a subprocess call with a 60 s timeout in an isolated environment; inject one in tests. An injected runner receives only the argv (no environment) and is cached per instance only. |
None
|
executables
|
dict[str, list[str]] | None
|
Per-harness argv prefix replacing the CLI name in the catalogue command
(as |
None
|
is_static ¶
is_static(harness: str) -> bool
True when validate for harness needs no subprocess (claude).
models ¶
models(harness: str, credentials: Credentials | None = None) -> list[str]
Return (and cache) the known model names for harness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
harness
|
str
|
Harness name. |
required |
credentials
|
Credentials | None
|
The login the catalogue command uses (normally |
None
|
Raises:
| Type | Description |
|---|---|
UnknownHarness
|
|
HarnessNotInstalled
|
The CLI is not on PATH (codex / opencode). |
RuntimeError
|
The catalogue command failed. |
MissingCredentials
|
The credential file cannot be read. |
validate ¶
validate(harness: str, model: str, credentials: Credentials | None = None) -> list[str]
Check model for harness; return warnings, raise if it is unknown.
For codex and opencode, a catalogue that cannot be loaded (CLI missing, command failing, unparsable output, timeout, an unusable PHD cache folder) yields a warning instead of an error; on timeout the command's whole process tree is killed. A loaded list whose temporary codex home could not be removed is kept, with a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
harness
|
str
|
Harness name. |
required |
model
|
str
|
Model name as it would go in |
required |
credentials
|
Credentials | None
|
The login the catalogue command uses (see |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Warnings (empty when the model is known). |
Raises:
| Type | Description |
|---|---|
ModelNotSupported
|
The model is not in the catalogue (carries |
Next: Errors ยท See also: API overview, Harnesses