Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Laravel Package

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+.

View on GitHub
Deep Wiki
Context7

⚡️ OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with OpenAI API

Frequently asked questions about Laravel
How do I install and set up openai-php/laravel in a Laravel project?
Run `composer require openai-php/laravel` to install the package, then execute `php artisan openai:install` to generate the `config/openai.php` file. Add your OpenAI API key and organization ID to your `.env` file using `OPENAI_API_KEY` and `OPENAI_ORGANIZATION`. The package automatically appends these variables to your `.env` during installation.
Which Laravel versions and PHP versions does this package support?
The package requires **PHP 8.2+** and is officially compatible with **Laravel 10 and 11**. The latest release (2026-03-17) also supports Laravel 13. Check the [GitHub releases](https://github.com/openai-php/laravel/releases) for version-specific details.
Can I use this package for real-time chat applications with streaming responses?
Yes, the package includes a `realtime` facade for streaming responses, such as chat completions. Use `OpenAI::realtime()->chat()->create()` with the `stream` parameter set to `true` to handle real-time data. This is ideal for chatbots or interactive AI features.
How do I mock OpenAI API calls in Laravel tests (Pest/PHPUnit)?
Use the built-in `fake()` method to simulate API responses. Call `OpenAI::fake()` before your test and define fake responses with `OpenAI::shouldReceive('chat')->andReturn($fakeResponse)`. The package integrates with Laravel’s testing tools, including assertion helpers like `assertSent()` to verify API calls.
Does this package support caching API responses to reduce costs?
While the package doesn’t enforce caching, you can manually cache responses using Laravel’s `Cache` facade. For example, cache a chat completion response with `Cache::remember('chat_response_key', now()->addHours(1), fn() => OpenAI::chat()->create(...))`. This reduces API calls and costs for repeated requests.
What happens if OpenAI’s API endpoints change or deprecate?
The package is actively maintained and tied to the underlying `openai-php/client` library, which adapts to OpenAI’s API changes. Monitor the [changelog](https://github.com/openai-php/client/blob/main/CHANGELOG.md) for updates. If OpenAI deprecates an endpoint, you may need to update the package or extend its functionality manually.
Is there a way to handle rate limits or retries for high-volume API calls?
The package uses Guzzle under the hood, which supports retries and middleware for rate limits. Configure retries in `config/openai.php` under the `http_client` section. For high-volume apps, consider queueing requests with Laravel Queues or implementing custom middleware to handle 429 errors.
Can I use this package with other AI providers (e.g., Mistral, Anthropic) in the future?
Currently, the package is tightly coupled to OpenAI’s API. If you need multi-provider support, you’d need to extend the `openai-php/client` library or refactor to use a generic HTTP client (e.g., Symfony HTTP Client). The facade layer abstracts OpenAI-specific logic, but switching providers would require significant customization.
How do I manage API keys securely across dev/staging/prod environments?
Use Laravel’s `.env` files to store environment-specific API keys (e.g., `OPENAI_API_KEY`). For production, consider using a secrets manager like AWS Secrets Manager or Laravel Forge. The package respects `.env` variables, so keys are automatically loaded from the environment.
Are there alternatives to this package for Laravel OpenAI integration?
Yes, alternatives include the official `openai-php/client` (framework-agnostic) or Laravel-specific packages like `spatie/laravel-openai`. However, `openai-php/laravel` stands out for its deep Laravel integration (facades, config, testing tools) and active maintenance. Compare features based on your needs, such as real-time support or caching.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope