OpenAI Codex SDK for Rust
An async-first Rust port of the public
openai-codex Python SDK.
It starts codex app-server over stdio, speaks its typed JSON-RPC protocol,
routes concurrent turn streams by ID, and provides a blocking facade for direct
migration from Python.
This port currently tracks upstream commit
f0c30e5.
It is not an official OpenAI Rust package.
Installation
Requirements
- Rust 1.85 or newer.
- A compatible
codexexecutable onPATH, or an explicitCodexConfig::codex_bin.
The Python wheel pins and bundles Codex CLI 0.144.4. Rust crates cannot bundle
that platform-specific executable in the same way, so production applications
should explicitly manage and pin the CLI version.
Blocking quickstart
The default blocking feature provides the API closest to Python:
use ;
Async quickstart
use ;
async
Disable the blocking facade for async-only applications:
[]
= { = "0.1", = false }
= { = "1", = ["macros", "rt-multi-thread"] }
= "0.1"
Inputs and options
Plain strings are shorthand for text input. Mixed inputs use InputItem:
use ;
async
Python keyword arguments map to Rust option structs:
thread_start(...)→thread_start_with(&ThreadStartOptions { ... })thread_list(...)→thread_list_with(&ThreadListOptions { ... })thread_resume(...)→thread_resume_with(..., &ThreadResumeOptions { ... })thread_fork(...)→thread_fork_with(..., &ThreadForkOptions { ... })thread.run(...)/thread.turn(...)→run_with/turn_with
Streaming and controls
turn() returns a handle that can be steered, interrupted, streamed, or
collected:
use ;
use StreamExt;
async
One turn handle has one consumable stream, matching the single-consumer behavior of Python's iterator. Separate active turns on the same client are routed independently.
Documentation
- Python-to-Rust migration guide
- Compatibility and deliberate deviations
- Weekly upstream update process
- Testing tiers and authenticated integration tests
- Release process
- Changelog
- Machine-readable upstream contract
Verification
The instrumented suite covers more than 98% of executable source lines and
enforces that floor in CI. It exercises the complete public workflow against a
deterministic app-server process: initialization, lifecycle RPCs, exact wire
options, inputs, login, approvals, routing, concurrent streams, controls,
result collection, errors, retry classification, and both sync/async facades.
An opt-in authenticated test additionally runs a real model turn through the
installed Codex CLI; see TESTING.md.