explaingit

openai-php/laravel

Analysis updated 2026-07-03

3,720PHPAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A Laravel package that connects PHP web apps to the OpenAI API, making it easy to send messages to AI models and receive responses with minimal setup.

Mindmap

mindmap
  root((openai-php laravel))
    What it does
      OpenAI API in Laravel
      Chat and text generation
    Setup
      Composer install
      Config file
      Env variables
    Features
      Clean Laravel interface
      Fake testing mode
      Timeout config
    Use cases
      AI chatbots
      Text generation
      Automated testing
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Add a ChatGPT-powered chatbot to a Laravel web app by sending user messages to OpenAI and streaming the response back.

USE CASE 2

Generate AI-written text or summaries inside a Laravel controller without managing HTTP requests manually.

USE CASE 3

Write automated tests for AI-powered features by using the package's fake response mode to avoid real API calls.

USE CASE 4

Quickly prototype an AI feature in an existing Laravel project using environment-variable-based API key configuration.

What is it built with?

PHPLaravelComposer

How does it compare?

openai-php/laravelkriswallsmith/asseticcrinsane/laravelshoppingcart
Stars3,7203,7183,704
LanguagePHPPHPPHP
Setup difficultyeasymoderateeasy
Complexity2/53/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min

Requires PHP 8.2 or higher and an OpenAI API key from your account dashboard.

MIT license: free to use in personal and commercial projects as long as you keep the copyright notice.

In plain English

This package connects Laravel applications to the OpenAI API. Laravel is a widely used PHP framework for building websites and web applications, and OpenAI provides the AI models behind tools like ChatGPT. This package acts as the bridge between the two, making it straightforward to send text to OpenAI models and receive responses back, all within a Laravel project. Installing the package takes a few commands. You add it to your project using Composer, which is a standard tool for managing PHP packages, then run a setup command that creates a configuration file and adds two placeholder lines to your project's settings file: one for your OpenAI API key and one for your organization ID. Both come from your OpenAI account dashboard. Once that is done, you call OpenAI's services through a clean interface that Laravel developers will recognize. The README shows a brief example of sending a message to a model and printing the response. Configuration is handled through environment variables, so API keys stay out of the code itself. You can also adjust settings like the base URL for the API and how long the application should wait before giving up on a request. For testing, the package includes a way to simulate OpenAI responses without actually sending requests to the real API. This is useful during development and automated testing, where you do not want to spend API credits or depend on a live network connection. You can define what fake responses the application should receive, then verify that the right requests were made. The package is community-maintained and released under the MIT license. It requires PHP 8.2 or higher. For developers who want to use the same OpenAI client outside of Laravel, a separate framework-agnostic version of the client is also available.

Copy-paste prompts

Prompt 1
I have a Laravel app and I want to add an AI chat endpoint using the openai-php/laravel package. Walk me through installation with Composer and show me a controller that sends a user message to GPT-4 and returns the reply.
Prompt 2
How do I use the fake testing mode in openai-php/laravel to simulate OpenAI responses in PHPUnit tests without making real API calls?
Prompt 3
I want to stream OpenAI responses in real time inside a Laravel app using this package. Show me how to set up a streaming response and send chunks to the browser.
Prompt 4
What environment variables does openai-php/laravel require and how do I set custom timeouts or a different API base URL in the config file?

Frequently asked questions

What is laravel?

A Laravel package that connects PHP web apps to the OpenAI API, making it easy to send messages to AI models and receive responses with minimal setup.

What language is laravel written in?

Mainly PHP. The stack also includes PHP, Laravel, Composer.

What license does laravel use?

MIT license: free to use in personal and commercial projects as long as you keep the copyright notice.

How hard is laravel to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is laravel for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub openai-php on gitmyhub

Verify against the repo before relying on details.