Download the PHP package openai-php/client without Composer

On this page you can find all versions of the php package openai-php/client. 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 client

OpenAI PHP

GitHub Workflow Status (main) Total Downloads Latest Version License


OpenAI PHP is a community-maintained PHP API client that allows you to interact with the Open AI API. If you or your business relies on this package, it's important to support the developers who have contributed their time and effort to create and maintain this valuable tool:

Table of Contents

Get Started

Requires PHP 8.1+

First, install OpenAI via the Composer package manager:

Ensure that the php-http/discovery composer plugin is allowed to run or install a client manually if your project does not already have a PSR-18 client integrated.

Then, interact with OpenAI's API:

If necessary, it is possible to configure and create a separate client.

Usage

Models Resource

list

Lists the currently available models, and provides basic information about each one such as the owner and availability.

retrieve

Retrieves a model instance, providing basic information about the model such as the owner and permissioning.

delete

Delete a fine-tuned model.

Completions Resource

create

Creates a completion for the provided prompt and parameters.

create streamed

Creates a streamed completion for the provided prompt and parameters.

Chat Resource

create

Creates a completion for the chat message.

Creates a completion for the chat message with a tool call.

Creates a completion for the chat message with a function call.

create streamed

Creates a streamed completion for the chat message.

Audio Resource

speech

Generates audio from the input text.

speechStreamed

Generates streamed audio from the input text.

transcribe

Transcribes audio into the input language.

translate

Translates audio into English.

Embeddings Resource

create

Creates an embedding vector representing the input text.

Files Resource

list

Returns a list of files that belong to the user's organization.

delete

Delete a file.

retrieve

Returns information about a specific file.

upload

Upload a file that contains document(s) to be used across various endpoints/features.

download

Returns the contents of the specified file.

FineTuning Resource

create job

Creates a job that fine-tunes a specified model from a given dataset.

list jobs

List your organization's fine-tuning jobs.

You can pass additional parameters to the listJobs method to narrow down the results.

retrieve job

Get info about a fine-tuning job.

cancel job

Immediately cancel a fine-tune job.

list job events

Get status updates for a fine-tuning job.

You can pass additional parameters to the listJobEvents method to narrow down the results.

FineTunes Resource (deprecated)

create

Creates a job that fine-tunes a specified model from a given dataset.

list

List your organization's fine-tuning jobs.

retrieve

Gets info about the fine-tune job.

cancel

Immediately cancel a fine-tune job.

list events

Get fine-grained status updates for a fine-tune job.

list events streamed

Get streamed fine-grained status updates for a fine-tune job.

Moderations Resource

create

Classifies if text violates OpenAI's Content Policy.

Images Resource

create

Creates an image given a prompt.

edit

Creates an edited or extended image given an original image and a prompt.

variation

Creates a variation of a given image.

Assistants Resource

Note: If you are creating the client manually from the factory. Make sure you provide the necessary header:

create

Create an assistant with a model and instructions.

retrieve

Retrieves an assistant.

modify

Modifies an assistant.

delete

Delete an assistant.

list

Returns a list of assistants.

Assistants Files Resource

create

Create an assistant file by attaching a file to an assistant.

retrieve

Retrieves an AssistantFile.

delete

Delete an assistant file.

list

Returns a list of assistant files.

Threads Resource

create

Create a thread.

createAndRun

Create a thread and run it in one request.

retrieve

Retrieves a thread.

modify

Modifies a thread.

delete

Delete a thread.

Threads Messages Resource

create

Create a message.

retrieve

Retrieve a message.

modify

Modifies a message.

list

Returns a list of messages for a given thread.

Threads Messages Files Resource

retrieve

Retrieves a message file.

list

Returns a list of message files.

Threads Runs Resource

create

Create a run.

retrieve

Retrieves a run.

modify

Modifies a run.

cancel

Cancels a run that is in_progress.

submitToolOutputs

When a run has the status: requires_action and required_action.type is submit_tool_outputs, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request.

list

Returns a list of runs belonging to a thread.

Threads Runs Steps Resource

retrieve

Retrieves a run step.

list

Returns a list of run steps belonging to a run.

Edits Resource (deprecated)

OpenAI has deprecated the Edits API and will stop working by January 4, 2024. https://openai.com/blog/gpt-4-api-general-availability#deprecation-of-the-edits-api

create

Creates a new edit for the provided input, instruction, and parameters.

Meta Information

On all response objects you can access the meta information returned by the API via the meta() method.

The toArray() method returns the meta information in the form originally returned by the API.

On streaming responses you can access the meta information on the reponse stream object.

For further details about the rates limits and what to do if you hit them visit the OpenAI documentation.

Troubleshooting

Timeout

You may run into a timeout when sending requests to the API. The default timeout depends on the HTTP client used.

You can increase the timeout by configuring the HTTP client and passing in to the factory.

This example illustrates how to increase the timeout using Guzzle.

Testing

The package provides a fake implementation of the OpenAI\Client class that allows you to fake the API responses.

To test your code ensure you swap the OpenAI\Client class with the OpenAI\Testing\ClientFake class in your test case.

The fake responses are returned in the order they are provided while creating the fake client.

All responses are having a fake() method that allows you to easily create a response object by only providing the parameters relevant for your test case.

In case of a streamed response you can optionally provide a resource holding the fake response data.

After the requests have been sent there are various methods to ensure that the expected requests were sent:

To write tests expecting the API request to fail you can provide a Throwable object as the response.

Services

Azure

In order to use the Azure OpenAI Service, it is necessary to construct the client manually using the factory.

To use Azure, you must deploy a model, identified by the {deployment-id}, which is already incorporated into the API calls. As a result, you do not have to provide the model during the calls since it is included in the BaseUri.

Therefore, a basic sample completion call would be:


OpenAI PHP is an open-sourced software licensed under the MIT license.


All versions of client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1.0
php-http/discovery Version ^1.19.2
php-http/multipart-stream-builder Version ^1.3.0
psr/http-client Version ^1.0.3
psr/http-client-implementation Version ^1.0.1
psr/http-factory-implementation Version *
psr/http-message Version ^1.1.0|^2.0.0
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 openai-php/client contains the following files

Loading the files please wait ....