An OpenAI API Client (SDK) for Your PHP Projects

24 Oct 2022


We are excited to announce our latest product: OpenAI PHP API Client

It is a downloadable PHP package that lets you connect your applications to the OpenAI API within minutes.

Leveraging GPT-3 or Codex-based Artificial Intelligence (AI) in your application is now as simple as:

$openaiClient = Manager::build(new \GuzzleHttp\Client(), new Authentication(getenv('OPENAI_API_KEY')));
$response = $openaiClient->completions()->create(
new CreateRequest([
'model' => 'text-davinci-002',
'prompt' => 'Will using a third party package save time?',
echo $response->choices[0]->text;
// Using a third party package can save time because you don't have to write the code yourself.

The package handles all the low-level details for you, so you can focus on delivering value in your application.

A Demo

Here is a short video showing what it is like building a request to the OpenAI completions endpoint:

What makes this package different?

Fully Typed Data Transfer Objects (DTOs)

All requests and responses are fully typed, with complete details of the OpenAI API request and response structures at your fingertips.

This has several advantages, including:

  • There’s no need for you to manually handle raw JSON-encoded responses - the package will automatically convert all API responses to fully typed Data Transfer Objects (DTOs).
  • No need to read complex API documentation because your IDE displays all the details for each request and response, including all the available properties.
  • Compatibility with PHP static analysis tools such as PHPStan and Psalm, which help detect typos or errors.

IDE Autocompletion

All API endpoints, requests and responses are fully documented within the package, allowing advanced IDEs (such as Visual Studio Code or PhpStorm) to understand all the endpoints, methods, parameters and properties.

All 17 Endpoints Supported

This package includes support for all of OpenAI’s publicly available endpoints, including the commonly used completions and moderation endpoints, as well as the fine tunes endpoint (if you wish to train your own unique AI model).

Please see the documentation for a full list of supported API methods.

Simplified Error Handling

Error handling is now as simple as adding a try/catch block to your code because the package automatically throws a ClientException if unexpected issues occur.

Please see here for an example.

Fully Tested

The package includes detailed unit and functional integration tests, giving us (and you) the confidence that things will work as expected.

Fully Supported

We want your integration experience to be seamless and trouble-free, which is why our Australian-based team of developers are here to help you.

Compatible with PHP versions 7.2 → 8.1

We have ensured that the package works as expected in all PHP versions from version 7.2.5 up to 8.1.x, allowing you to use it in new and older applications.

Listed on the OpenAI Community Libraries Page

The OpenAI official documentation maintains a list of OpenAI Community Libraries, and we’re proud to be listed on that page.

Getting Started

You can find the tectalic/openai package available on and GitHub.

Please see our getting started guide: how to build a PHP app using the OpenAI API, which includes full code snippets, videos and a full starter (skeleton) app.

We also have comprehensive documentation available.

Questions or Feedback?

We welcome your feedback, and we’re excited to see what you do with this package.

What do you like about it? What do you think could be improved?

You can reach out to us here, or via our contact form.