Download the PHP package neosoftware/openai-codex-sdk without Composer

On this page you can find all versions of the php package neosoftware/openai-codex-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package openai-codex-sdk

OpenAI Codex SDK for PHP

PHP 8.2 SDK for working with the OpenAI Codex CLI agent. An exact port of the @openai/codex-sdk package (TypeScript).

Requirements

Installation

Codex Binary

The SDK runs codex (Codex CLI) as a subprocess. Specify its path in one of the following ways:

Via CodexOptions — explicitly for a specific instance:

Installation into vendor/bin — convenient for containers and servers where Codex CLI is not installed globally. The command downloads the binary for your platform from npm and adds a vendor/bin/codex symlink:

allow-plugins permissions are not required.

Quick Start


Initialization

new Codex(CodexOptions $options = null)

Creates the main SDK object.

CodexOptions

Property Type Default Description
apiKey ?string null OpenAI API key. Passed to the binary as CODEX_API_KEY
baseUrl ?string null Custom API URL (--config openai_base_url=...)
codexPathOverride ?string null Absolute path to your custom codex binary
config ?array null Arbitrary key => value pairs for --config flags
env ?array null Environment variables for the subprocess. If null, the subprocess inherits the entire PHP process environment. If explicitly set, the subprocess receives only the specified variables

Threads

Codex works within threads — each thread stores the conversation history.

ThreadOptions

Property Type Default Description
model ?string null Model name (codex-mini-latest, gpt-4o, …)
sandboxMode ?SandboxMode null Sandbox mode for running commands
workingDirectory ?string null Agent working directory (--cd)
skipGitRepoCheck bool false Do not require a Git repository
modelReasoningEffort ?ModelReasoningEffort null Depth of the model's “reasoning”
networkAccessEnabled ?bool null Network access from the sandbox
webSearchMode ?WebSearchMode null Web search mode
webSearchEnabled ?bool null Enable/disable web search (legacy)
approvalPolicy ?ApprovalMode null Action approval policy
additionalDirectories ?string[] null Additional directories (--add-dir)

Running Requests

run() — blocking

Runs a request, waits for the full response, and returns a Turn.

Turn

Property Type Description
finalResponse string The agent's final message (or JSON when using outputSchema)
items object[] List of all completed ThreadItem objects
usage ?Usage Token usage information

runStreamed() — streaming

Returns StreamedTurn immediately. Events are read as they arrive through a generator.

StreamedTurn::events()Generator<ThreadEvent>

A generator that sequentially yields events:

Event Fields Description
ThreadStartedEvent threadId Thread created; ID is now available
TurnStartedEvent Request processing started
ItemStartedEvent item Item started running
ItemUpdatedEvent item Intermediate item update (command output, etc.)
ItemCompletedEvent item Item completed
TurnCompletedEvent usage Request completed; token statistics
TurnFailedEvent error The agent returned an error (throws TurnFailedException)
ThreadErrorEvent message Non-fatal error

Input Types

The run() and runStreamed() methods accept either a string or an array of objects:

Multiple TextInput instances are concatenated with \n\n. Images are passed as --image flags.


ThreadItems

Each completed agent step is an item of one of the following types:

AgentMessageItem

Agent text response.

ReasoningItem

Internal model “reasoning” (if enabled).

CommandExecutionItem

Executed shell command.

FileChangeItem

File changes in the working directory.

McpToolCallItem

Tool call via the Model Context Protocol.

WebSearchItem

Web search request.

TodoListItem

Agent task list.

ErrorItem

Non-fatal error during execution.


TurnOptions

Options for a specific request (passed as the second argument to run() / runStreamed()):

Property Type Description
outputSchema ?array JSON Schema — the agent will return JSON compatible with the schema
timeoutSeconds ?int Maximum response wait time

Structured Output

The OpenAI API requires "additionalProperties": false in the schema:


Enumerations (Enums)

SandboxMode

ModelReasoningEffort

WebSearchMode

ApprovalMode


Error Handling

Exception When
TurnFailedException The agent returned turn.failed (API error, invalid schema, …)
SpawnException Binary not found, failed to start, hung, or exited with a non-zero code
ParseException Binary returned invalid JSON in the JSONL stream
CodexException Base class for all SDK exceptions

Complete Example


License

MIT


All versions of openai-codex-sdk with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package neosoftware/openai-codex-sdk contains the following files

Loading the files please wait ...