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?', ]))->toModel(); 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.
Here is a short video showing what it is like building a request to the OpenAI completions endpoint:
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:
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.
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.
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.
The package includes detailed unit and functional integration tests, giving us (and you) the confidence that things will work as expected.
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.
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.
The OpenAI official documentation maintains a list of OpenAI Community Libraries, and we’re proud to be listed on that page.
You can find the tectalic/openai
package available on Packagist.org 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.
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.
We're actively building new API clients at the moment.
Please get in touch to register your interest.