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.
Download neosoftware/openai-codex-sdk
More information about neosoftware/openai-codex-sdk
Files in neosoftware/openai-codex-sdk
Package openai-codex-sdk
Short Description PHP 8.2 SDK for OpenAI Codex CLI agent
License MIT
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
- PHP 8.2+
- Composer
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