CodexCliBackend
LlmBackend for the OpenAI codex CLI.
Usage
CodexCliBackend()Invokes codex exec with an ephemeral session and a read-only sandbox.
Attributes
models: dict[TModel, str]- Mapping from abstract model size to an OpenAI model name.
Methods
| Name | Description |
|---|---|
| build_command() |
Build the codex exec argv for one stdin-prompted invocation.
|
| env() |
Return no extra environment variables; the codex CLI runs with the inherited environment.
|
| parse_response() |
Parse codex stdout into text or a validated model.
|
build_command()
Build the codex exec argv for one stdin-prompted invocation.
Usage
build_command(model, schema_path, agent)Every invocation runs an ephemeral session in a read-only sandbox. Non-agent invocations disable Codex hooks and MCP servers. A schema path adds --output-schema.
Parameters
model: str-
OpenAI model name, e.g.
gpt-5.5. schema_path: str | None-
Path to a JSON schema file passed to
--output-schema, orNone. agent: bool- Whether the invocation may use tools / agent capabilities.
Returns
list[str]- The argv list to execute.
env()
Return no extra environment variables; the codex CLI runs with the inherited environment.
Usage
env()parse_response()
Parse codex stdout into text or a validated model.
Usage
parse_response(raw, response_model)Parameters
raw: str-
Raw stdout from the
codexCLI. response_model: type[BaseModel] | None-
Model to validate against, or
Nonefor raw text.
Returns
str | BaseModel-
rawwhenresponse_modelisNone; otherwiserawvalidated as JSON againstresponse_model.