﻿# Choose Codex exec, SDK or app-server for an integration

Choose between Codex exec, the official SDK and app-server by matching job lifecycle, conversation continuity and the amount of user-interface control you need.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/learn-codex-integration-layer/
Language: en

Codex can be used from a command-line job, a programmatic SDK or a rich client protocol. These are integration choices around the agent, not interchangeable names for a model. Start by describing how work begins, continues and returns an artifact to the surrounding application.

## Use exec for a bounded process boundary

A script can invoke Codex for a defined repository question and collect the final artifact. This fits a job that has a clear input and an expected stopping point. The illustrative command below does not prescribe authentication or repository setup; those remain part of the environment in which the process runs.

```bash
codex exec "Explain the export path and return the relevant source files"
```

## Use the SDK for application-level orchestration

The official TypeScript SDK exposes a thread and a run operation. An application can keep that thread object or resume a thread when its workflow requires continuity. The following small example illustrates the documented API shape. It is not a complete service implementation or a claim that a returned explanation has been independently validated.

```typescript
import { Codex } from "@openai/codex-sdk";
const client = new Codex();
const thread = client.startThread();
const result = await thread.run("Explain the export path");
console.log(result.finalResponse);
```

## Use app-server when the client owns interaction

App-server exposes conversation history, authentication flows, approvals and streamed events through a documented client protocol. This is useful when the product needs to render and control the agent lifecycle directly. The client then has more integration work: request correlation, event projection and user-interface state become explicit responsibilities rather than details hidden inside a terminal process.

## Compare the ownership boundaries

The layers can serve related tasks with different amounts of surrounding control. A useful comparison names the application behavior that requires a particular layer. This keeps selection tied to an actual workflow instead of an abstract preference for more features.

| Integration need | Starting layer | State the surrounding product still owns |
| --- | --- | --- |
| Bounded command-line job | Codex exec | Job input, artifact storage and downstream acceptance. |
| Programmatic local workflow | Codex SDK | Application records and the decision to continue a thread. |
| Rich interactive client | Codex app-server | Interface state, product-specific tools and user-facing controls. |
| Review before a write | The selected layer plus an application rule | The exact proposed change and the evidence used for approval. |

## Keep product records outside the agent abstraction

A support dashboard may associate a Codex thread with a customer issue, but the issue remains an application record with its own permissions and status. The integration layer does not replace that record. Preserve the association, the returned artifact and the application’s acceptance decision. This makes a later migration between exec, SDK and app-server easier to reason about because the business object does not disappear into an opaque conversation.

## Documentation and further study

- [Codex SDK](https://learn.chatgpt.com/docs/codex-sdk).

- [Codex as a platform: build on the open agent harness](https://developers.openai.com/blog/codex-as-a-platform).

- [Codex App Server](https://learn.chatgpt.com/docs/app-server).

Related engineering guides: [Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [Choose a local AI stack: desktop chat, shared UI or coding agent](/journal/local-ai-app-stack-selection/).
