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

Client Laravel Package

openai-php/client

Community-maintained PHP client for the OpenAI API. Send requests for models, responses and chat, conversations, containers and files, with streaming support and a clean, typed interface. Install via Composer and use in any PHP app (Laravel-friendly).

View on GitHub
Deep Wiki
Context7

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

Frequently asked questions about Client
How do I install **openai-php/client** in a Laravel project?
Run `composer require openai-php/client` in your project directory. Laravel’s autoloader will handle dependencies automatically. Ensure your project uses PHP 8.2+ for full compatibility. The package integrates seamlessly with Laravel’s service container, so no extra configuration is needed for basic usage.
Does this package support Laravel’s service container and dependency injection?
Yes, the package is designed for Laravel’s service container. Bind the `OpenAI` client to the container in your `AppServiceProvider` or use Laravel’s `make:provider` to manage configurations like API keys. This allows you to leverage Laravel’s DI features for testing and modularity.
Can I use this for real-time chat applications in Laravel?
Absolutely. The `Responses` resource includes streaming capabilities (e.g., `createStreamed()`), making it ideal for real-time chat interfaces. Pair it with Laravel’s Blade or Livewire for dynamic UI updates. For async processing, consider Laravel queues to handle long-running conversations.
How do I handle API rate limits or cost tracking in Laravel?
The package doesn’t include built-in rate limiting, but you can integrate OpenAI’s usage APIs or third-party tools like Stripe for billing. For rate limits, implement middleware or a decorator around the `OpenAI` client to track and enforce limits. Laravel’s caching layer can also store API responses to reduce costs.
Is there built-in support for Laravel queues or async operations?
No, the package doesn’t natively support Laravel queues, but you can wrap long-running operations (e.g., fine-tuning, batch processing) in a `Job` class. Dispatch the job via `dispatch()` and process it in a queue worker. For webhooks or async events, use Laravel’s queue listeners or event system.
Which Laravel versions and PHP versions are supported?
The package requires **PHP 8.2+** and is compatible with Laravel 9.x and 10.x. Older Laravel versions (e.g., 8.x) may work but aren’t officially tested. If you’re on PHP 8.1 or lower, upgrade to meet the package’s requirements for type safety and modern PHP features.
How do I integrate embeddings or vector databases with Laravel?
Use the `Embeddings` resource to generate vectors, then store them in Laravel’s database (e.g., PostgreSQL with `pgvector`) or an external vector DB like Weaviate. For retrieval, query the database directly or build a Laravel service layer to abstract the logic. The package doesn’t enforce a specific storage method.
Are there alternatives to this package for Laravel?
Yes, alternatives include `php-openai/php-openai` (a lower-level client) or `spatie/laravel-ai` (a Laravel-specific wrapper). However, `openai-php/client` offers a **typed, fluent API** and better Laravel integration (e.g., service container support). Choose based on your need for abstraction vs. flexibility.
How do I handle errors or exceptions in Laravel?
The package throws `OpenAIException` for API errors. Convert these to Laravel’s `HttpException` or `ProblemException` in a middleware or service layer. For example, catch `OpenAIException` and throw a `ProblemException` with a custom status code for consistent API responses.
Does this package support deprecated OpenAI APIs like Assistants or Threads?
Yes, but the package explicitly marks deprecated resources (e.g., `Assistants`, `Threads`) to help you phase them out. If you rely on these, check OpenAI’s documentation for migration paths. For new projects, focus on modern resources like `Responses` or `Conversations` for better long-term support.
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.
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
anil/file-picker
broqit/fields-ai