Codex

Codex API for apps: model access vs agent runs

How to choose between a Codex-optimized model API and a complete Codex agent run when adding coding work to a product.

Short answer

Use a Codex-optimized model through the OpenAI API when you want model inference and will build the surrounding loop. Use a complete Codex agent run when your product needs repository work, commands, tests, session state, and reviewable changes as one workflow.

  • A Codex model endpoint and a Codex agent harness are different integration layers.
  • The model route offers lower-level control; the agent route performs work in an execution environment.
  • Your product contract should represent tasks, status, files, and reviewable results instead of leaking harness-specific events into the UI.

Separate the model API from the agent harness

QuestionCodex-optimized model APICodex agent run
Primary interfaceOpenAI API request and model response.A task executed by Codex in a working environment.
InfrastructureYour team builds the loop, tools, sandbox, files, and persistence.The harness provides the execution workflow around the model.
Product outputText, structured output, or tool-call data you assemble.Repository changes, test results, files, and a reviewable task outcome.

Keep the product contract stable

  • Send a clear product task and the repository or files the user authorized.
  • Expose status and streaming progress without coupling the UI to every Codex event.
  • Return diffs, files, test evidence, and summaries as explicit artifacts.
  • Persist enough session state for the user to continue, revise, or retry the work.
  • Keep credentials and harness execution on the server side.

Use the smallest layer that completes the job

Choose the model API
When you need coding-oriented inference and already own the agent loop and runtime.
Choose a Codex agent run
When users expect completed repository work, commands, tests, and a reviewable change.
Choose a multi-harness backend
When the product must route between Codex and other agent harnesses behind one stable integration.

FAQ

Is the Codex API the same as the OpenAI Responses API?
Not exactly. OpenAI exposes Codex-optimized models through its API, while Codex as an agent also includes an execution workflow around the model. Choose based on whether you need inference or completed agent work.
Can I put Codex behind my own product UI?
Yes, but the product still needs a secure server-side integration, run lifecycle, file handling, and a way to present reviewable results to the user.
Why route Codex with other agents?
Routing lets a product use the harness best suited to each task while preserving one task, session, streaming, file, and artifact contract.

Sources

Open integration docs