Download the PHP package focusbp/openai-response-php without Composer

On this page you can find all versions of the php package focusbp/openai-response-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package openai-response-php

OpenAI Response PHP

A lightweight PHP library that wraps the OpenAI Responses API to provide:

This library is intended to be easy to drop into a simple PHP app, even on older environments.

Install

You can install it via Composer:


Features

🧠 Vector Store Integration

🔧 Function Calling

💬 Conversation Recording

📡 Status Polling


Requirements


Quick Start

This is the fastest way to see it working in a browser.

  1. Set your API key

    Open tests/config/config.php and set your OpenAI API key:

  2. Deploy

    Upload the entire tests/ directory (and the project library) to a PHP-capable web server.

  3. Access the demo UI

    Open index.php in your browser.
    The sample UI can answer:

    • questions about upcoming events (from the Vector Store)
    • weather questions (via Function Calling)

Vector Store Usage

1. Add source files

Put plain text files (or other supported text content) into the vector_store/ directory.
For example:

These files act as your "knowledge base."

2. Sync with OpenAI

From the sample UI (the test app in tests/), click:

"Sync Vector Store"

When you click that:

If a Vector Store does not exist yet, the library can create one.
If it already exists, the library can update it.


Function Calling

The library exposes a Function Calling interface so the model can decide to call your PHP functions as tools.

1. Create a tool

Create a class in the function_tools/ directory that implements \focusbp\OpenAIResponsePhp\FunctionTool.

Example (simplified):

2. Dependency injection via Controller

If your tool needs shared services like:

…you can create your own class that extends \focusbp\OpenAIResponsePhp\Controller and put those dependencies there.

Then, when you instantiate the OpenAI client, pass that controller instance into the constructor.

Inside execute(), you’ll receive that same $ctl instance, so you can do things like $ctl->db->query(...) or $ctl->weatherApi->fetch(...).

3. Auto-loading

Any class you put in function_tools/ that implements FunctionTool will be auto-discovered and made available to the model.


Conversation & Status

Message history

The library keeps a running conversation history (system / user / assistant / tool messages).
This can be persisted using a Recorder:

Both provide:

Status polling

The sample UI calls status_poll.php on an interval and displays a short status string (e.g. “fetching vector store…”).
This status string is stored via a StatusManager implementation.

Example implementation:


Logging

All request/response logs and debug output can be written to the log/ directory.

If you’re debugging or auditing model behavior:


Project Structure (reference)

Below is a typical layout to help you navigate:


Demo Flow (What the sample UI does)

  1. You open tests/index.php in your browser.
  2. You see a chat-like interface.
  3. You ask something like:
    • “What upcoming events are there?”
    • “What’s the weather tomorrow in Tokyo?”
  4. Under the hood:
    • For event questions, it retrieves knowledge from the synced Vector Store.
    • For weather questions, it calls the Weather tool via Function Calling.
  5. The UI polls status_poll.php so you can see status text like “Start AI Processing...” or other internal messages.

Security Notes


License

Add your preferred license here (MIT, Apache-2.0, etc.).


Contributing

Pull requests and issues are welcome.
If you add new tools or storage backends (e.g. RedisRecorder, DatabaseStatusManager), please include minimal usage docs in your PR so others can learn from it.


All versions of openai-response-php with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
ext-curl Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package focusbp/openai-response-php contains the following files

Loading the files please wait ...