Skip to main content

Crate apiari_codex_sdk

Crate apiari_codex_sdk 

Source
Expand description

Rust SDK for the Codex CLI.

This crate wraps the codex command-line tool, reading JSONL events from stdout when invoked with codex exec --json. Unlike the Claude SDK, this is unidirectional — the prompt goes as a CLI argument and stdin is /dev/null.

§Quick start

use apiari_codex_sdk::{CodexClient, ExecOptions, Event, Item};

let client = CodexClient::new();
let mut execution = client.exec("List files in the current directory", ExecOptions {
    model: Some("o4-mini".into()),
    full_auto: true,
    ..Default::default()
}).await?;

while let Some(event) = execution.next_event().await? {
    match &event {
        Event::ItemCompleted { item: Item::AgentMessage { text, .. } } => {
            if let Some(text) = text {
                println!("{text}");
            }
        }
        Event::TurnCompleted { usage } => {
            if let Some(usage) = usage {
                println!("Tokens: {} in, {} out", usage.input_tokens, usage.output_tokens);
            }
        }
        _ => {}
    }
}

Re-exports§

pub use client::CodexClient;
pub use client::Execution;
pub use error::Result;
pub use error::SdkError;
pub use options::ApprovalPolicy;
pub use options::ExecOptions;
pub use options::ResumeOptions;
pub use options::SandboxMode;
pub use types::Event;
pub use types::FileUpdateChange;
pub use types::Item;
pub use types::ThreadError;
pub use types::TodoItem;
pub use types::Usage;

Modules§

client
High-level client for spawning and streaming codex executions.
error
SDK error types.
options
Execution options and CLI argument building.
transport
Read-only NDJSON transport over a subprocess.
types
Protocol types for the Codex CLI exec --json JSONL output.