- How do I install and configure openai-php/laravel in a Laravel app?
- Run composer require openai-php/laravel, then execute php artisan openai:install. The install command creates config/openai.php and appends blank OPENAI_API_KEY and OPENAI_ORGANIZATION entries to your .env file. Add your OpenAI API key and adjust config/openai.php or environment values as needed, then use the OpenAI facade in your application.
- Which Laravel and PHP versions does openai-php/laravel support?
- As of v0.20.0, the package officially supports Laravel 10 through 13 and requires PHP 8.2 or newer. Laravel version support can change between package releases, so check the composer.json constraints before upgrading. Pin compatible versions in CI to avoid unexpected breakage.
- How do I call the OpenAI API with the OpenAI facade in Laravel?
- Use OpenAI\Laravel\Facades\OpenAI and call endpoint-specific methods such as OpenAI::responses()->create([...]). Pass the model and input or other parameters as arrays that match OpenAI's API, then read response properties such as outputText. The facade resolves the underlying client through Laravel's service container, so no manual client wiring is required.
- How can I fake OpenAI responses in Laravel tests?
- The package provides a fake() method for mocking API responses, so unit and integration tests do not hit the real OpenAI API. Use it to return deterministic payloads for success, error, and edge-case scenarios. This keeps CI fast and avoids token costs or rate-limit flakiness during test runs.
- Can I use openai-php/laravel with Azure OpenAI or a custom base URL?
- Yes, the package supports a configurable base URL, so you can point it at Azure OpenAI or another compatible endpoint. Set the relevant base URL value in config/openai.php or through environment configuration. Verify that the endpoint and API version expectations match what the underlying client sends.
- Is openai-php/laravel Laravel-only, or can I use it outside Laravel?
- This package is Laravel-specific and relies on Laravel facades, service providers, and dependency injection. For framework-agnostic PHP projects, use the underlying openai-php/client package instead. The Laravel package is best when you want native configuration and facade access inside a Laravel application.
- How should I store the OpenAI API key securely in Laravel?
- Put OPENAI_API_KEY in your .env file and never commit .env to version control. Access configuration through config/openai.php and environment variables rather than hardcoding keys in source code. In production, use your platform's secret management and restrict who can view environment variables.
- What OpenAI endpoints can I access through openai-php/laravel?
- The package exposes multiple OpenAI API areas via the facade, including responses, conversations, fine-tuning, realtime, and containers in recent versions. It maps closely to OpenAI's official API, including model support and rate-limit handling. If you need an endpoint or feature that is not exposed, use the underlying openai-php/client package or a custom implementation.
- How do I handle OpenAI rate limits and timeouts in production?
- Catch rate-limit errors such as RateLimitException and implement retry logic with exponential backoff for 429 responses. API calls are synchronous by default, so offload long-running work like fine-tuning to Laravel queues. For high-volume usage, add caching for repeatable responses and monitor usage to control costs.
- Is openai-php/laravel actively maintained and how should I manage upgrades?
- It is a community-maintained package, so track releases and the underlying openai-php/client dependency for changes. Pin versions with Composer semantic versioning and test upgrades in CI before deploying to production. Because OpenAI can deprecate endpoints or change response formats, review release notes and keep retry and error handling resilient.