codex-app-server-sdk
Tokio Rust SDK for Codex App Server JSON-RPC over JSONL.
Status
0.1.1- 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(...)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.
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.
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