codex-app-server-sdk
Tokio Rust SDK for Codex App Server JSON-RPC over JSONL.
Status
0.3.0- Focused on deterministic automation: explicit timeouts and no implicit retries.
- Typed v2 request methods with raw JSON fallback for protocol drift.
Features
stdio: spawncodex app-serverlocally.ws: websocket transport with loopback daemon management.- For loopback URLs (
ws://127.0.0.1:*,ws://[::1]:*,ws://localhost:*),start_and_connect_wsreuses an existing app-server or auto-startscodex app-server --listen ...and leaves it running. - Use
connect_wsto connect directly without any process management. - Daemon logs are written to
/tmp/codex-app-server-sdk/*.log.
- For loopback URLs (
- High-level typed thread helpers:
Codex::ask(...)Codex::ask_with_options(...)ResumeThreadenum for typed resume targetsCodex::resume_thread_by_id(...)Codex::resume_latest_thread(...)Thread::run(...)Thread::run_streamed(...)
- Typed schema generation via
OpenAiSerializableandopenai_json_schema_for::<T>().
Requirements
codexCLI installed and available onPATH.codex app-servermust start locally for live flows.- Active Codex authentication for account/model/turn requests.
Quickstart (stdio)
use ;
use ;
# async
Quickstart (high-level typed API)
use ;
use StdioConfig;
# async
Use run_streamed(...) when you need incremental item and lifecycle events.
Resume a recorded thread with a typed resume target:
# use ;
# use StdioConfig;
# async
Resume the latest recorded thread for a workspace:
# use ;
# use StdioConfig;
# async
The explicit helpers remain available: use resume_thread_by_id(...) and resume_latest_thread(...) when you prefer the narrower API surface.
AgentMessageItem.phase mirrors the app-server's optional agentMessage.phase field (commentary or final_answer). Use message.is_final_answer() to identify the final turn message from ItemCompleted; Turn.final_response and ask(...) already prefer the final_answer item when the server provides it and otherwise fall back to the last completed agent message.
Typed output schema
use ;
use ;
use ;
# async
Use codex_app_server_sdk::JsonSchema instead of adding a separate schemars dependency unless you deliberately need a different version elsewhere in your application. That keeps the derive macro and OpenAiSerializable on the same trait version.
If you want the SDK to wire the derives and crate paths for you, use the convenience attribute:
Websocket flow
use ;
use ;
use HashMap;
# async
Reliability model
- No automatic retries for any RPC method.
- Every request has a timeout (
ClientOptions::default_timeout) with per-call override available through raw request APIs. - Requests are blocked client-side until you complete both steps:
initialize()theninitialized(). - Unknown events and fields are preserved through
Unknownvariants andextramaps.
Raw fallback
Use:
send_raw_request(method, params, timeout)send_raw_notification(method, params)
for newly added methods or fields not yet wrapped in typed helpers.
Examples
cargo run -p codex-app-server-sdk --example turn_start_streamcargo run -p codex-app-server-sdk --example raw_fallbackcargo run -p codex-app-server-sdk --example high_level_runcargo run -p codex-app-server-sdk --example high_level_streamedcargo run -p codex-app-server-sdk --example high_level_resumecargo run -p codex-app-server-sdk --example high_level_output_schemacargo run -p codex-app-server-sdk --example ws_persistentcargo run -p codex-app-server-sdk --example web_search_agent