openai-php/laravel
Laravel integration for the OpenAI PHP client. Provides config, install command, and an OpenAI facade to call the OpenAI API (Responses, chat, etc.) from Laravel apps. Requires PHP 8.2+.
.env variables, service binding).responses, fineTuning, conversations, realtime) via dedicated facades, enabling granular adoption. This modularity allows TPMs to scope integration to specific use cases (e.g., chatbots vs. fine-tuning).OpenAI facade abstracts the underlying openai-php/client, simplifying API calls while maintaining access to raw client functionality if needed. This balances ease of use with flexibility.composer require + php artisan openai:install, with no database migrations or schema alterations.config/openai.php file provides a centralized configuration hub.openai-php/client ensures feature parity with OpenAI’s API updates.openai-php/client is framework-agnostic. Risk of lock-in is mitigated by the ability to swap out the facade layer if needed.client package (e.g., v0.19.0 → v0.19.1).fake() method for testing is powerful but requires understanding of OpenAI’s response structures. TPMs must ensure test coverage aligns with production use cases (e.g., rate limits, error handling).RateLimitException for HTTP 429 errors, but TPMs must design retry logic (e.g., exponential backoff) to handle production-scale usage.responses, fineTuning) or a subset? This impacts facade adoption and testing effort.OPENAI_BASE_URL configuration?realtime) be used? These require additional client-side handling..env)?openai-php/client changes? The package’s changelog is minimal; TPMs may need to subscribe to the client repo for updates.OpenAI facade and client to the container, enabling dependency injection.openai:install automates configuration setup, reducing manual error risk.fake() method integrates with Laravel’s testing tools (e.g., Pest, PHPUnit), enabling seamless test-driven development.openai-php/client). TPMs must ensure their stack supports this.responses for chatbot features").composer.json and run composer update.php artisan openai:install to generate .env variables and config/openai.php.OPENAI_API_KEY and OPENAI_ORGANIZATION in .env.config/openai.php for advanced use cases (e.g., OPENAI_BASE_URL for Azure).OpenAI facade (e.g., OpenAI::responses()->create()).// Before (e.g., Guzzle)
$client = new \GuzzleHttp\Client();
$response = $client->post('https://api.openai.com/v1/completions', [...]);
// After
$response = OpenAI::responses()->create(['model' => 'gpt-5', 'prompt' => '...']);
fake() for unit tests. Example:
OpenAI::fake([
CreateResponse::fake(['choices' => [['text' => 'Mocked response']]])
]);
assertSent() to verify API calls in integration tests.RateLimitException or timeouts during ramp-up.v0.3.1 (last version with Laravel 10 support).responses, fineTuning).RateLimitException and ErrorException.realtime) if needed.client package frequently. TPMs must:
openai-php/client (e.g., deprecated methods).composer update openai-php/laravel cautiously, as it may pull newer client versions.config/openai.php and .env, reducing maintenance overhead.OPENAI_API_KEY. Validate .envHow can I help you explore Laravel packages today?