openai-php/client
OpenAI PHP is a community-maintained PHP client for the OpenAI API, giving Laravel and PHP applications typed, framework-agnostic access to chat, responses, embeddings, images, audio, files, and streaming, backed by an active community and thousands of GitHub stars.
models(), chat(), responses()) maps cleanly onto Laravel’s service-layer pattern (repositories/services).responses() resource now supports programmatic tool calling and the apply_patch tool, materially strengthening the package for agentic/tool-using workflows.Services/Webhooks) enable real-time interactions. v0.21.0 optimizes streamed response processing, reducing event-loop overhead for chatbot and assistant use cases.responses() into richer retrieval-augmented flows.php-http/discovery or an explicit HTTP client (e.g., Guzzle). Laravel’s Http facade or GuzzleHttp\Client can substitute with minimal config.AppServiceProvider.assistants, threads) may require refactoring if legacy features are used. New responses() tooling features are additive and low risk, but teams should track forward-compatibility as the Responses API matures.OpenAIException) to Laravel’s exception handler (render()).usage->totalTokens) should integrate with logging/monitoring. v0.21.0 adds cache_write_tokens to CreateResponseUsagePromptTokensDetails — cost dashboards should be updated to account for cached-write tokens.apply_patch and programmatic tool calling execute structured actions driven by model output. Apply strict schema validation and authorization checks before mutating state — treat model-emitted arguments as untrusted input.ranking_options and max_num_results now accept null in FileSearchTool; previously rigid validation could throw. Review code paths that relied on previous defaulting behavior to confirm expected semantics.assistants) be used? If so, plan migration to threads/responses — the new tool features live only in responses()..env + Vault or secrets manager.apply_patch / programmatic tool calls before any file or state mutation.openai-php/client (upgrade to ^0.21 to unlock Responses tooling, streaming optimizations, and cache-token usage details).guzzlehttp/guzzle, php-http/discovery (optional), laravel/queue, spatie/laravel-activitylog (auditing).AppServiceProvider:
public function register()
{
$this->app->singleton(\OpenAI\Client::class, function ($app) {
return \OpenAI::client(config('services.openai.key'));
});
}
app/Services/OpenAIService.php facade/repository.chat()->create(), embeddings()->create()).$stream = $client->responses()->createStreamed([...]);
foreach ($stream as $chunk) {
event(new OpenAIResponseChunk($chunk));
}
programmatic tool calling and apply_patch in the responses() payload. Gate apply_patch behind an authorization service and schema validation.Cache::remember('openai_models', ...).FineTuneJob::dispatch(...)->onQueue('openai'); similarly queue tool invocations.POST /openai/webhook in Laravel.if (OpenAIRateLimiter::tooManyRequests()) {
return response()->json(['error' => 'Rate limit exceeded'], 429);
}
FileSearchTool defaults now that ranking_options/max_num_results may be null.withBaseUri().chat(), embeddings(), and responses() (non-tool).programmatic tool calling, apply_patch), vector stores, fine-tuning.Http::fake() for API responses, including mocked tool-call and apply_patch payloads.apply_patch.openai-php/client for breaking changes. v0.21.0 is backward-compatible; schedule routine minor upgrades. Use composer.json conflict/replace if forking.cache_write_tokens addition implies OpenAI’s usage model continues to expand; keep usage-parsing logic resilient to new fields.apply_patch arguments could target unintended files — require allow-listing, sandboxed filesystems, and human-in-the-loop approval for high-risk operations.ranking_options/max_num_results now nullable, downstream code that assumed non-null values may break; add assertions.cache_write_tokens) silently ignored by older parsing code — use tolerant DTOs.apply_patch handling.How can I help you explore Laravel packages today?