"I want to build an AI app that runs on my own ChatGPT subscription, but I don't know whether to use the codex CLI, SDK, or app-server."—Many individual developers are likely stuck at this point. I will provide the shortest possible answer to "What is the codex app-server?"
There are three pillars to address. 1. The codex app-server is a JSON-RPC 2.0 over stdio server bundled with the Codex CLI, serving as a "GUI bidirectional port" for talking from a child process. 2. The SDK, exec, and app-server are not competitors but are categorized by use case. 3. Authentication is a local trust model residing in ~/.codex/auth.json—I will establish these three points in the first half.
In the second half, I will share all my insights from the initial implementation. I will dive into details with actual code and numbers, including the minimal code to spawn from Tauri 2, the workflow to eliminate documentation drift using generate-json-schema, the ChatGPT Plus break-even point based on gpt-image-2 unit costs (reversing at 95 high-res images/month), and a three-party responsibility table for BYO subscription distribution.
I am an individual developer who implemented codex-image-editor (a desktop image generation and editing app built with Tauri 2 + React, using my own ChatGPT subscription as the engine). Since I will explain this based on a working implementation rather than abstract theory, you will be ready to start prototyping your own BYO distribution app after reading this.
The True Nature and Mechanism of the codex app-server

The codex app-server is a subcommand bundled with the Codex CLI, used by launching it from a child process as a bidirectional server that streams JSON-RPC 2.0 over stdio. By spawning it from a GUI app or a client in another language and writing a single line of JSON to stdin, that message is delivered to codex as one message.
In other words, as long as the codex CLI is in the PATH on the PC, it can be used regardless of the language—whether it's Tauri (Rust), Electron (Node), or Python on a VPS—as long as there is a child process API. This app-server is the most primitive entry point, not tied to a specific runtime like the SDK.
First, I will establish the overall picture with the positioning as a Codex CLI bundled subcommand and the article's key visual, followed by the conventions of JSON-RPC 2.0 over stdio, and finally an overview of the main RPC methods and notifications in Chapter 1.
One-Line Definition and Codex CLI Bundled SubcommandTo put it in one line, the codex app-server is a bidirectional server intended for child processes that speaks the contents of codex via JSON-RPC 2.0 over stdio as a subcommand bundled with the Codex CLI. The basic operation is to spawn it, take control of stdin/stdout, and kill it with kill_on_drop when finished.
What makes this effective is the characteristic that the client-side language is completely free. As long as you can write 1 line = 1 JSON, it doesn't matter if it's TypeScript, Python, Rust, Go, or Swift. The subject codex-image-editor is spawned from Rust (Tauri 2), but it runs with zero npm dependencies.
Another point to keep in mind is that the moment you install the Codex CLI, all three forms—exec, SDK, and app-server—are available. These are not competing products in separate packages, but merely the same codex binary being invoked in different modes. The installation method can be npm, brew, or GitHub release; the acquisition route is irrelevant to the actual entity.
Conventions of JSON-RPC 2.0 over stdioThe protocol is JSON-RPC 2.0 over stdio. Since a newline is the delimiter for one message, you must not include raw newlines within the JSON string. It is a simple three-part structure: stdin from client to child process, stdout from child process to client, and stderr dedicated to logs.
Messages are divided into three types: those containing an id and a method are requests, those containing an id and a result or error are responses, and those without an id but with a method are notifications. Approval requests sent from the server use the same mechanism, and the client responds to them with a decision.
request: jsonrpc, id, method, params — exists in both directions: client to server, and server to client
response: jsonrpc, id, result — response to a request, mapped by id
notification: jsonrpc, method, params — no id, used for streaming and progress notifications
stderr: Unstructured log output, must not be parsed (operational rule)
For the implementation side, the standard approach is a bidirectional tokio task configuration with 1 writer task and 1 reader task. The writer writes JSON from an mpsc channel to stdin with a newline, and the reader reads stdout line by line and sorts it into 3 types. The rpc.rs in the codex-image-editor subject also follows this skeleton.
A common point of failure is detecting TransportClosed when the child process terminates. If you do not wake up all requests in the pending: HashMap<id, oneshot::Sender> with TransportClosed the moment stdin closes, the UI side will freeze with a permanent spinner. This is not a 'nice-to-have' but a requirement.
Overview of major RPC methods and notificationsWe will provide an overview of the major methods that actually flow on top of the mechanism described so far. On the request side, it starts with capability exchange via initialize, followed by ChatGPT OAuth via account/login/start, a list of available models via model/list, and the start of conversations and turn transmission via thread/... as the skeleton.
On the notification side, starting with initialized (handshake completion notification), stream notifications such as thread/started, item/started, item/delta, and item/completed flow continuously. A characteristic feature is that commandExecution and fileChange approval requests from the server to the client interrupt in the middle.
Overview of major RPC methods and notifications of the codex app-server — with field differences from official documentation (Confirmation date: 2026-05-06, Source: codex app-server generate-json-schema actual schema)
As shown in the table above, there are multiple places where the official documentation and the actual schema differ. Representative examples include data: Model[] in model/list, textDelta in item/delta, the approval response decision, and the kebab-case in approvalPolicy / sandbox. There is also a trap where sending in camelCase will silently disable the field.
The countermeasure is simple: rather than trusting the documentation, the operational practice is to fetch the actual schema using codex app-server generate-json-schema --out /tmp/codex-schema, and use that as the source of truth to regenerate TypeScript / Rust types. If you incorporate this into CI, you can detect field changes on the codex side via diffs.
Comparison of the 3 forms of SDK exec app-server
I will start with the conclusion. If you want to stream bidirectionally in a GUI and include an approval dialog, the app-server is the only choice. If you want to call it as a typed function within a Node or Python server, use the SDK; if you want to throw a single command via CI or cron, receive the result, and finish, use exec. The 3 forms are not competing but are for different use cases, and the time spent worrying about the choice is a loss of productivity.
Once you have installed the Codex CLI, the SDK, exec, and app-server are all at your disposal. It is just a matter of which mode you call them in. The axes for differentiation converge on three points: 'bidirectional vs. one-off', 'language-agnostic vs. native to a specific language', and 'whether approval UX is required or not'. With the following comparison table, you can immediately decide which one fits your use case.
Cases where the SDK is suitable: TS/Python server-side completionIf you want to call codex as a single function within a Node server or Python backend, @openai/codex-sdk is the most straightforward. It is typed in TypeScript / Python natively, and you can handle it with the feeling of importing and awaiting to get a result. It is like adding a 'function to call codex' to the logic layer of your backend, without having to worry about the GUI layer or process management.
import Codex from "@openai/codex-sdk"; const codex = new Codex(); const text = await codex.run( prompt: "このリポジトリの README を 3 行で要約して" ); console.log(text);
What it is not suitable for is bidirectional streaming from a GUI, approval dialog round-trips where you ask the user 'is this okay?' every time a command is executed, and use cases called from language clients other than TS / Python. Since the SDK is tied to the language runtime, you need a separate language bridge to call it directly from GUI frameworks like Tauri (Rust) or Qt (C++). If even one of these requirements applies, spawning the app-server instead of the SDK will make subsequent work easier.
I will add one more point. It is often confused that the SDK sets up the app-server internally, but the SDK is a separate implementation with its own API layer. You cannot perform a continuous transition like "start with the SDK for typing, then drop down to the app-server when needed," so if you foresee GUI bidirectional interaction, it is better to start building with the app-server from the beginning to avoid rework.
Cases where exec is suitable: CI one-shotsAt night, a CI job runs a single task that "summarizes the latest commits and formats them into release notes." For such one-off processing where you "throw it, receive the result, and finish," codex exec is the fastest. It follows the Unix philosophy of streaming a prompt to stdin, returning the result to stdout, and returning a success/failure exit code, and since the process restarts every time, no state is carried over.
Can be called in one line from a GitHub Actions step (can be mixed directly into shell scripts)
Suitable for calls from cron or make targets (behaves as a Unix tool that assumes pipes)
The greatest advantage is the ease of connecting via standard input/output, such as git diff codex exec '...'
What is not suitable are bidirectional use cases where you want to output progress sequentially, insert approvals in the middle, or maintain long conversations. Since exec starts and ends a process every time, the context of the conversation is cut off there. The moment you need a UX where "the user can cancel during processing," it is a sign to switch from exec to app-server.
Cases where app-server is suitable: GUI bidirectional streamingBuilding a GUI with Tauri 2 or Electron, displaying progress sequentially, and having the user confirm "is it okay to proceed?" right before executing a command. In such configurations, the app-server demonstrates its true value. Because it continues to run as a resident child process, it can maintain the state of the conversation, and since JSON-RPC is language-agnostic, it can be called from Rust, Node, or Python simply by spawning it as a child_process.
In a front-end + back-end configuration like Tauri 2 + React, it can handle bidirectional streaming and approval round-trips simultaneously
Not tied to the client language (if you can write 1 line = 1 JSON, it works in TS, Rust, or Go)
Can stream "what is happening in the middle" to the UI via threads/notifications, allowing the user to wait while understanding the situation
Conversely, there are clear situations where you should not choose the app-server. If it is a CI one-shot, exec is shorter, and if it is completed within a TS/Python server, the SDK is more straightforward because it has types. Furthermore, the app-server alone does not have an HTTP authorization mechanism. If you set it up raw on a VPS and expose it to the world, any client that can grab stdio will be in a state where they can use your ChatGPT subscription for free. When distributing or publishing on a VPS, please design it on the premise that you will always place Tailscale, mTLS, or your own thin authentication bridge in front of it. Details will be covered in the authentication model in the next section.
The comparison table below is the one page I want you to look at the most. With a 5-axis x 3-form cross, you can point and confirm where your use case falls on this table.
5-axis cross comparison table of SDK / exec / app-server. If you need GUI bidirectional and approval UX, app-server is the way to go; otherwise, SDK or exec is more straightforward.
Authentication model and the boundary of local trust
The codex app-server does not have a layer to identify "whose request it is." The boundary is only the OS user who started the process, and the authentication information itself resides in ~/.codex/auth.json. Once you understand this design, the true nature of the "this is dangerous" thought that crosses the reader's mind and the reason why BYO ChatGPT subscription distribution works are both unraveled at the same time.
In order, I will define the authentication entity, OS user boundary, and VPS exposure risks in Chapter 1. Whether you are releasing it, placing your own agent on a VPS, or using it only locally, your judgment will be determined entirely by these three points in this chapter.
Where and by whom is auth.json read?Authentication information is saved locally in ~/.codex/auth.json. For Plus/Pro, it is written via browser OAuth from codex login, and for API key operation, it is via OPENAI_API_KEY. The process that started the app-server goes to read this auth.json and talks to codex in a state linked to that ChatGPT subscription.
The decisive factor here is that the app-server layer has no mechanism to determine "whose request it is." There is no layer like an API gateway to verify tokens, so the moment the process starts, it is determined that it will use that OS user's subscription. Since there is no concept of identification, the authorization boundary cannot be placed anywhere other than the OS user account.
BYOK and BYO ChatGPT subscription are similar but different. BYOK is a model where you bring your own OPENAI_API_KEY, which has been adopted by Cursor and Cline-based tools. The BYO ChatGPT subscription structure relies on the user's PC having a codex-logged-in state, and the distributed app simply spawns it.
BYOK = Bring your own API key (pass OPENAI_API_KEY via environment variable or settings UI, pay-as-you-go)
BYO ChatGPT subscription = Bring your own codex-logged-in auth.json (included in Plus/Pro monthly fee, includes subscription-only tools like image_gen)
From the app author's perspective, the billing destination for inference costs and the available toolset change here
Different OS users on the same PC are different boundaries. This is a very standard matter of Unix permissions; if home directories are separate, auth.json files are also separate.
The problem is within the same OS user. Since there is no per-app permission isolation, any process running under that OS user can read auth.json. The editor extensions you use daily and the command-line tools you installed on a whim are, in principle, standing in a position where they can access the same file.
If auth.json is stolen, the impact must be considered with the same weight as an API key leak. If replaced on an attacker's machine, the ChatGPT session is restored as-is, and they can even hit image_gen within your Plus/Pro quota.
The etiquette for those distributing GUI apps is also determined by this. The user should perform the codex login on their own PC, and the app author should not touch, copy, or log auth.json. This alone creates a clean separation where the app author never holds the keys, and the scope of responsibility for the distributed app remains small.
Risk table for what happens when exposing via VPSThe moment you set up an app-server on a VPS and expose it, any client that can grasp stdio will be in a state where they can freely use your ChatGPT subscription. Since the app-server itself has no HTTP authorization or API key check, the app side cannot stop an opponent who finds the endpoint and keeps running image generation.
The direction for countermeasures is clear: do not expose stdio directly. Close it to "only your own devices" using Tailscale or WireGuard, set up a thin HTTP bridge covered with mTLS or OAuth in front, or open a hole only for yourself via an SSH tunnel. The premise remains the same regardless of the method. Since the app-server has no authorization mechanism, the designer is responsible for adding authorization at the layer in front.
In terms of terms of service, the point of contention is how to interpret the personal use of a ChatGPT subscription. If it is a BYO distribution, it is a structure where each user uses their own subscription, so it falls within the regular route even from OpenAI's perspective. On the other hand, a design that "handles" others using your own subscription is technically possible but easily deviates from the scope of personal use, so it is safer to avoid it.
Looking at these 6 lines, you can see that whether it is dangerous or not depends on the design. For use cases that complete within local trust, the focus is on OS user hygiene in the first and second lines; for distribution, the decision to avoid VPS exposure in the fourth line; and if you place your own agent on a VPS, the decision to always add an authorization layer in front. If you decide which one to take at this stage, there will be almost no moments of hesitation in the later Tauri implementation and image_gen chapters.
Minimal implementation to spawn from Tauri
From here on, I will answer the question of "how to actually write it" using real code from codex-image-editor. If you can grasp these four points—spawn, writer/reader, handshake, and fetching the actual schema—you will have the foundation to make the codex app-server talk as a child process on the Tauri 2 side. The rest is just adding app-specific message sending and receiving.
All code is excerpted from actual files. Please read this not as a copy-paste-and-run sample, but as a commented citation designed to make the key points easy to read. On the Tauri side, the focus is mainly on src-tauri/src/codex/process.rs and src-tauri/src/codex/rpc.rs.
Minimal code to spawn in process.rsThe responsibilities of the startup section can be narrowed down to three: pass the codex binary to Command and launch it with the app-server subcommand, set stdin/stdout/stderr all to piped to capture all three, and use kill_on_drop(true) to ensure no zombie processes remain when the app terminates. This alone secures the child process body that runs cross-platform.
// src-tauri/src/codex/process.rs (codex-image-editor)
// codex バイナリを app-server --listen stdio:// で子プロセス起動。
// stdin/stdout/stderr 全部 piped にして、kill_on_drop で
// アプリ終了時に確実にゾンビ化させない。
pub async fn spawn_app_server(bin: &Path) -> Result<AppServerProcess> anyhow!("child stdout not captured"))?;
if let Some(stderr) = child.stderr.take()
spawn_stderr_logger(stderr);
Ok(AppServerProcess child, stdin, stdout )
kill_on_drop(true) is quietly effective. If you forget this, even if you quit the Tauri side with Cmd-Q during development, the codex process will remain, consuming CPU and continuing to hold onto auth.json. In production distribution, this also affects resilience when the UI crashes, so it is a setting you should always include from the start.
stderr is piped to tracing::debug! in a separate task and is never displayed on the screen. Since the app-server's stderr is designated solely for logs, attempting to parse it will break your operations the moment you do. For resolving the codex binary, if you start with which::which("codex") and fall back to representative paths for Homebrew, mise, cargo, and bun, you can generally absorb the environmental differences on the user side.
Fix stdio framing with Command::new(bin).arg("app-server").arg("--listen").arg("stdio://")
Capture all three of stdin/stdout/stderr with Stdio::piped (if you forget one, you cannot build the subsequent stages)
Use kill_on_drop(true) to ensure the child process is taken down when the UI terminates
The advantage of spawning via Tauri 2 is that the same code runs on Windows, macOS, and Linux
Once spawn is complete, launch the writer task that writes to stdin and the reader task that reads from stdout in separate tokio::spawn calls. The writer receives JSON lines from mpsc::UnboundedReceiver<String>, appends a newline, and sends them; the reader takes them line by line with BufReader::lines, parses them into JSON, and distributes them to three types via dispatch_message. By completely separating the roles and placing one Pending map (id -> oneshot::Sender) in between, bidirectional JSON-RPC streaming is established.
// src-tauri/src/codex/rpc.rs (codex-image-editor) — writer task
// out_rx (mpsc) で受けた行を stdin に書き込む。
// 1 行 = 1 JSON-RPC メッセージなので、必ず末尾に \n を付けて flush する。
tokio::spawn(async move
let mut stdin = stdin;
while let Some(line) = out_rx.recv().await
if let Err(err) = stdin.write_all(line.as_bytes()).await
tracing::error!(target: "codex.rpc", "write error: err");
break;
if !line.ends_with('\n')
if let Err(err) = stdin.write_all(b"\n").await
tracing::error!(target: "codex.rpc", "newline write error: err");
break;
if let Err(err) = stdin.flush().await
tracing::error!(target: "codex.rpc", "flush error: err");
break;
// transport が切れたら、保留中の request を全部 TransportClosed で叩き起こす
alive_for_writer.store(false, Ordering::SeqCst);
let mut map = pending_for_writer.lock().await;
for (_, tx) in map.drain()
let _ = tx.send(Err(RpcError::TransportClosed));
);
// reader task: stdout を BufReader::lines() で行単位に切り出して
// JSON parse → response / server-request / notification に dispatch。
tokio::spawn(async move
let mut lines = BufReader::new(stdout).lines();
while let Ok(Some(line)) = lines.next_line().await
let trimmed = line.trim();
if trimmed.is_empty() continue;
let value: Value = match serde_json::from_str(trimmed)
Ok(v) => v,
Err(err) =>
tracing::warn!(target: "codex.rpc", "parse error: err");
continue;
;
dispatch_message(value, &pending_reader, ¬if_tx_reader, &server_req_tx_reader).await;
// reader 側でも transport が死んだら pending を全部叩き起こす
alive_for_reader.store(false, Ordering::SeqCst);
let mut map = pending_reader.lock().await;
for (_, tx) in map.drain()
let _ = tx.send(Err(RpcError::TransportClosed));
);The inclusion of logic in both the writer and reader to "cancel all pending requests on TransportClosed" is to prevent accidents. To avoid the accident where the UI side becomes a permanent spinner regardless of whether only one side of the stdio dies or both die simultaneously, you must drain the Pending map at the exit of both tasks. If you don't do this, the app will appear to the user as "frozen without responding," and the cause will be hidden inside tokio, making troubleshooting a nightmare.
The discrimination logic for dispatch_message is determined by just three flags. If id, result arrives, it is a resolution of an in-flight request; id, method, params is a server-to-client request (= show approval dialog); and if it is just method, params, it is a notification (= progress/delta). For anyone who has written an LSP, this structure feels completely natural and works exactly as imagined.
// src-tauri/src/codex/rpc.rs (codex-image-editor) — handshake と dispatch 判別
/// 起動直後にやるべき手続き: initialize で能力交換 → initialized 通知。
/// これを省くと一部 method が 401 相当で失敗する。
pub async fn handshake(client: &RpcClient) -> Result<Value> e
// dispatch_message のフラグ判定 (抜粋)
// id, result → in-flight request の resolve
// id, method, params → server → client request (= 承認ダイアログを出す)
// method, params → server → client notification (= ストリーム / 進捗)
let has_id = obj.contains_key("id");
let has_method = obj.contains_key("method");
let has_result = obj.contains_key("result");
let has_error = obj.contains_key("error");
if has_id && (has_result || has_error) /* response /
else if has_id && has_method / server request /
else if has_method / notification */ The handshake opens with the round trip of initialize request -> initialized notification. If the order is reversed or you forget the initialized notification, you will encounter behavior where subsequent account/login/start or thread/turn calls are kicked back with the equivalent of a 401. It follows the same etiquette as LSP; you receive server capabilities in the initialize result and return initialized as a notification without an id. You just need to write this exactly as instructed, and it will pass.
Eliminating field mismatches with generate-json-schemaOnce the code starts running, the next trap you will encounter is field mismatches. Just to name a few representative examples: delta has been renamed from textDelta to delta, approvalPolicy/sandbox must be sent in kebab-case (on-request / workspace-write), the model/list response is in data: Model[] format (not models as in the official documentation), and the approval response is a new API of decline. Code written by reading only the documentation will fail silently on all of these.
The solution can be narrowed down to one: stop trusting the documentation and switch to an operation of fetching the actual schema. Since codex itself has a command to output the schema, if you incorporate a workflow into your CI that fetches the JSON Schema from there and regenerates the TS/Rust types, you will notice if field names change at the next build.
# 実体スキーマの取得 (確認日 2026-05-06) codex app-server generate-json-schema --out /tmp/codex-schema 出力例 (ディレクトリ構成、抜粋): /tmp/codex-schema/ ├── initialize.request.schema.json ├── initialize.result.schema.json ├── model.list.result.schema.json # → data: Model[] の実体 ├── thread.turn.params.schema.json ├── item.delta.notification.schema.json # → delta フィールドの正式定義 ├── commandExecution.request.schema.json └── ... Rust 側: serde で deserialize する型を schema から生成 TS 側 : openapi-typescript / json-schema-to-typescript で型生成
On the Rust side, deserialize the output schema JSON as a target for serde's derive, and on the TS side, generate types using openapi-typescript or json-schema-to-typescript. If you automate up to this point, even if field names shift every time you upgrade the codex CLI version, the work will move to a position where the CI will stop you with a type check.
The overall pipeline is as shown in the mermaid flow below. If you fix the 4-step cycle of executing generate-json-schema locally, committing the schema JSON, generating types, and detecting diffs in CI, inconsistencies with the documentation can be absorbed by the CI side rather than the implementation side.
delta vs textDelta: Old textDelta is not accepted; the current one is the delta field
approvalPolicy / sandbox: kebab-case (on-request / workspace-write), camelCase is disabled
model/list: Response is data: Model[] (not models from the documentation)
Approval response: decision: accept (old approved: bool is not allowed)
These are traps I encountered as of the confirmation date 2026-05-06, so there is a high possibility that other fields may have shifted by the time you read this. The judgment criterion is simple: treat the actual schema as the truth rather than the documentation. If you run generate-json-schema locally and align your implementation with the resulting JSON Schema as the truth, the time spent stuck on field mismatches will be almost zero.
Codex standard equipment as a coding agent
The codex app-server is not just an LLM endpoint that relays requests to ChatGPT. From the moment it is spawned, file read/write, shell execution, image_gen, Web search, MCP connection, approval workflows, and thread notifications are all launched in the background. The app creator shifts to the side of renting a complete coding agent set, allowing them to focus on the UI and prompt strategy.
The minimal spawn built in the previous chapter only gains meaning from this point forward. Which of the standard tools to allow, how to have dangerous operations approved, and where to confine writes. Deciding these three things solidifies the safe defaults for your distributed app.
Rent the entire set of standard tools along with the backendCodex's standard equipment can be organized into 7 categories: File R/W (read_file / apply_patch), shell execution, image generation (image_gen), Web search, external tools via MCP, approval workflows, and thread/notification streams. For an app that hits the Image API directly, the app-server provides the layer you would otherwise have to build yourself from scratch.
The important point is that "the app creator does not need to hold the tool implementation itself." Codex autonomously performs internal calls to the OpenAI Image API for image_gen, and if you enable MCP connections, external MCP servers can be used as Codex tools as they are. Since progress can be streamed via threads and notifications, the UI side only needs to render the received messages to function.
The table below summarizes in one place what each tool is responsible for, in what situations an approval request is triggered, and which notification is fired. When designing a distributed app, first use this table to sort out "which ones to use for your purpose" and "which ones require an approval dialog."
Round-trip design of the approval workflowImmediately before Codex executes shell or apply_patch, a commandExecution / fileChange server-to-client request is sent. The standard flow is a round-trip where the client expands this into a UI dialog and returns the user's decision as decision (accept / decline, etc.) in the response.
acceptForSession is a mode where "the same type of operation is permitted without re-confirmation during this session," which makes the UX much easier. This is because you don't have to show a dialog every time in a flow of editing the same file continuously or repeatedly executing similar commands. Conversely, if you return decline / cancel, Codex will switch to a different approach or fold the turn.
The standard implementation practice is to build a dedicated UI like ApprovalDialog.tsx and always display the full command and diff preview. If the time from opening the approval dialog to returning is long, the screen may appear frozen, so stream progress notifications in a separate lane to make the status visible. The sequence diagram below shows the overall picture of the round-trip.
Essential defaults for approvalPolicy and sandboxThere are only two defaults to enforce in a distributed app. Use approvalPolicy: "on-request" to always require approval for dangerous operations, and sandbox: "workspace-write" to confine file writes to within the workspace directory. By explicitly stating these two lines in the initialize params, the user protection of your distributed app will exceed the minimum baseline.
The trap you will inevitably fall into here is kebab-case. If you send on-request as onRequest or workspace-write as workspaceWrite in camelCase, the field itself may be accepted, but it will not match the enum, and the policy will be silently ignored. Even in the actual schema (generate-json-schema), it is fixed in hyphenated notation.
For the same reason, avoid designs that rely on default values. If the default on the codex side changes in the future, the behavior of previously distributed binaries will change silently. In the case of BYO ChatGPT subscription distribution, since the user is providing their own subscription, the two settings of approvalPolicy and sandbox should be treated as essential commits even for OSS, and it is safer to explicitly state them every time during initialization.
// initialize params 抜粋。kebab-case で固定する。
// camelCase で送ると無効化されるサイレント罠なので、
// 文字列リテラルは const にしてレビューで見やすくする。
const APPROVAL_POLICY: &str = "on-request";
const SANDBOX_MODE: &str = "workspace-write";
let params = json!(
"clientInfo": default_client_info(),
"capabilities": "experimentalApi": true ,
"approvalPolicy": APPROVAL_POLICY,
"sandbox": SANDBOX_MODE,
);Economics of image_gen and BYO subscription distribution
At the point of generating 100 high-quality images per month, ChatGPT Plus reverses the cost of hitting the API directly. Since image_gen via the codex app-server only 'calls the official tools included in the subscription,' no additional charges are incurred.
The gpt-image-2 (Standard API, 1024x1024) on the official OpenAI pricing page costs $0.006 per image for low, $0.053 for medium, and $0.211 for high (as of 2026-05-06). The $0.211 for high is a level that would exhaust the $20 monthly Plus fee in just 95 images.
What works is the structure beyond this. If you distribute with the codex app-server as the engine, the inference cost is covered by the user's subscription. App creators can focus solely on UI/UX and prompt strategy, and their revenue will not be skimmed by OpenAI. I will finalize the design rationale, tripartite responsibilities, and the entry point for prototyping at the end.
In terms of value, the moment you exceed 100 images, a subscription is the only choice. Use the table below to check your own use case per image.
gpt-image-2 unit price and Plus break-even pointThe Standard API unit price for gpt-image-2 is $0.006 for low, $0.053 for medium, and $0.211 for high at 1024x1024 (as of 2026-05-06, Source: Official OpenAI pricing page). In terms of tokens, image input is $8 per million, output is $30, and the Batch API is half price.
Calculating the break-even point based on the $20 monthly ChatGPT Plus fee, the API-side cost overtakes Plus at approximately 3,333 images for low, 377 images for medium, and 95 images for high. For the $200 monthly Pro, the break-even point for high is approximately 947 images.
For editing purposes, the numbers shift even further. Since gpt-image-2 handles reference images at high resolution, input tokens swell with each edit, making the per-image cost 2-3 times higher than new generation. If you focus on high-quality editing, hitting the API directly will reach $20 per month at 30-50 images.
The judgment criteria are the 'median quality used' and the 'number of images per month.' Large batches of low are cheaper with API + Batch, if medium is the focus, Plus has the advantage at around 400 images per month, and if high is the center
Tripartite responsibilities of BYO subscription distributionThere are three parties involved in BYO ChatGPT subscription distribution: the app creator (the author of Tauri-based OSS like codex-image-editor), the end-user (the person who uses codex login on their own PC), and OpenAI (the provider of the inference entity and subscription).
The app creator is responsible for UI/UX, default values for approvalPolicy: on-request and sandbox: workspace-write, and a design that does not touch auth.json. The inference cost is zero. The end-user is responsible for their own subscription contract, executing codex login, and local storage of auth.json.
OpenAI is responsible for the inference entity, terms of service, and commercial use authorization for output via subscription. Since the roles are clearly separated, app creators can design monetization through other lines (donations, Pro features, one-time purchase licenses, OSS) without their revenue being skimmed by OpenAI.
Commercial use OK and prototyping start CTACommercial use of images generated via ChatGPT is permitted under the OpenAI Terms of Use (as of 2026-05-06, Source: OpenAI Terms of Use). Since the rights to the output belong to the user, you are free to incorporate generated content into commercial works, whether via subscription or API.
Since codex app-server is an official client released by OpenAI itself, using it to call image_gen via a subscription is within the intended scope—in other words, it is a legitimate route. You can rest assured that BYO subscription distribution is not a 'hack to exploit a gray area in the terms,' but rather a usage pattern intended by the design.
There are two keys to the implementation side. One is a design that injects the 'number of images' into the prompt in Japanese, and the other is a design that recursively monitors the output directory to pick up new files. In codex-image-editor's PromptComposer.tsx, we insert '$count images of $verb' at the end, causing the codex autonomous agent to call image_gen 'count' times.
// src/components/PromptComposer.tsx より抜粋 function composeText( prompt: string, count: number, positions: Array< kind: "source" >, ): string
The other output monitoring is implemented in watcher.rs. Since codex writes image_gen outputs under ~/.codex/generated_images/, we use an 800ms debounce from notify-debouncer to avoid firing during partial writes, and then push only the new files to the gallery via Tauri events.
800ms is an empirically measured value to wait until the end of the file is written. If you shorten this, metadata.len may be notified with an incomplete size, leading to accidents where images appear corrupted. If you remember just these two things—prompt injection and output monitoring—the skeleton of a BYO distribution app is built.
Once you have read this far, it is time to get your hands dirty. First, run codex app-server generate-json-schema --out /tmp/codex-schema to download the actual schema locally, and then read through the four files in codex-image-editor: process.rs / rpc.rs / watcher.rs / PromptComposer.tsx.
Once you finish these two steps, you will be ready to start prototyping your own BYO ChatGPT subscription distribution app based on your ideas. The rest is in the realm of UI and prompt strategy, so you can run it without worrying about inference costs.
By now, the foundation is solid: the true nature of codex app-server is a JSON-RPC 2.0 over stdio server bundled with the Codex CLI, designed to be spawned as a child process. The distinction between SDK, exec, and app-server boils down to a one-line rule: use SDK if you want to keep it within a TS or Python server, use exec for one-shot CI tasks, and use app-server if you want to handle bidirectional streaming and approval dialogs in a GUI. This state of being able to 'instantly answer which one to choose' was the goal of the awareness layer we wanted to achieve in the first half.
The authentication model is a trust model that places ~/.codex/auth.json locally, with the boundary being the OS user unit; the app-server layer has no concept of identifying 'whose request it is.' It is a very straightforward design when touched from your own GUI locally, but the moment you expose stdio over a network, authorization becomes the responsibility of the designer to implement themselves. Measures like narrowing the trust boundary with Tailscale or mTLS, or preparing a separate HTTP layer, will not waver if you view them as a natural extension of local trust.
For readers interested in BYO ChatGPT subscription distribution, I have presented three axes of differentiation: the minimal implementation spawned from Tauri 2 via tokio::process::Command, the economics of gpt-image-2 (the break-even point where ChatGPT Plus reverses API billing at 95 images/month for high quality), and the tripartite responsibility table for app authors, end-users, and OpenAI. The essence of BYO distribution is a clean separation where the app author focuses on UI/UX and default values like approvalPolicy: on-request + sandbox: workspace-write, while inference costs are covered by the end-user's ChatGPT subscription. Commercial use is permitted under the OpenAI Terms of Use, and image_gen via subscription can be treated as a legitimate route through an official client.
As a next step, first run codex app-server generate-json-schema --out /tmp/codex-schema locally to obtain the actual schema and update the field definitions, which tend to drift from the documentation. Then, read the codex-image-editor repository (a reference implementation of Tauri 2 + React), and by overlaying the actual code of process.rs / rpc.rs / watcher.rs / PromptComposer.tsx onto the image of the app you want to create, you can start prototyping your BYO ChatGPT subscription distribution app that very day. The foundation is ready. Now, try spawning one image with your own idea.
I operate an AI x Development Practical Community on note. I provide information and a learning environment for 'truly useful' AI for
experienced 'professional developers'. We offer unlimited consultations, study sessions, and exclusive code & articles. If you are interested, please check the link below.