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

Community-maintained OpenAI PHP integration for Laravel. Install via Composer and artisan, configure API key in .env, then use the OpenAI facade to call OpenAI endpoints (e.g., Responses API) from your Laravel app.

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 configure openai-php/laravel in my Laravel project?
Run `composer require openai-php/laravel` and execute `php artisan openai:install`. This generates a `config/openai.php` file and adds `.env` variables for your API key and organization ID. Configure these in `.env` and use the `OpenAI` facade to start making API calls.
Which Laravel versions does this package support, and what are the PHP requirements?
The package officially supports Laravel 10–13 and requires PHP 8.2+. Verify your Laravel version matches the package’s requirements, especially if using newer features like the `responses` facade. Check the [GitHub releases](https://github.com/openai-php/laravel/releases) for updates.
Can I use this package with Azure OpenAI or other custom endpoints?
Yes, you can configure a custom base URL in `config/openai.php` under `base_url`. This allows you to point to Azure OpenAI or other OpenAI-compatible endpoints. Ensure the endpoint supports the same API structure as OpenAI’s official API.
How do I mock OpenAI API responses for testing in Laravel?
Use the built-in `fake()` method provided by the package. For example, `OpenAI::fake([...])` allows you to simulate API responses in unit or integration tests. This is especially useful for CI/CD pipelines where you don’t want to hit the real OpenAI API.
What happens if I exceed OpenAI’s rate limits? How can I handle 429 errors?
The package throws a `RateLimitException` when rate limits are exceeded. Implement exponential backoff or retry logic in your application to handle these errors gracefully. Laravel’s queue system can also help manage retries for async operations.
Is it safe to store my OpenAI API key in the Laravel `.env` file?
Yes, storing the API key in `.env` is secure as long as you never commit the file to version control. Always add `.env` to your `.gitignore`. Access the key in your code using Laravel’s `config('services.openai')` or environment variables to avoid hardcoding.
Can I use this package for high-volume API calls, or do I need to implement caching?
For high-volume usage, caching frequent responses (e.g., embeddings) is recommended. Use Laravel’s cache drivers to store responses and reduce API calls. Additionally, consider batching requests or using OpenAI’s async capabilities for long-running tasks like fine-tuning.
Are there any unsupported OpenAI features, like the Assistants API or Moderations?
The package covers core features like GPT models, fine-tuning, and realtime APIs, but some niche features (e.g., Assistants API, Moderations) may not be included. Check the [GitHub issues](https://github.com/openai-php/laravel/issues) or the underlying [openai-php/client](https://github.com/openai-php/client) for updates or custom implementations.
How do I handle async operations, like realtime APIs or fine-tuning jobs?
The package supports async operations via facades like `OpenAI::realtime()` or `OpenAI::fineTuning()`. For production, offload these tasks to Laravel queues or use WebSockets for realtime updates. Monitor job progress and implement retry logic for failures.
What are the alternatives to this package if I need more flexibility or framework-agnostic support?
For framework-agnostic use, consider the standalone [openai-php/client](https://github.com/openai-php/client) package. If you need more Laravel-specific features or a different API client, explore packages like `guzzlehttp/guzzle` with custom OpenAI endpoints or third-party Laravel wrappers like `spatie/laravel-openai`.
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.
codraw/graphviz
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata