CodexCliBackend

LlmBackend for the OpenAI codex CLI.

Usage

Source

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

Source

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, or None.

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

Source

env()

parse_response()

Parse codex stdout into text or a validated model.

Usage

Source

parse_response(raw, response_model)
Parameters
raw: str

Raw stdout from the codex CLI.

response_model: type[BaseModel] | None
Model to validate against, or None for raw text.
Returns
str | BaseModel
raw when response_model is None; otherwise raw validated as JSON against response_model.