OpenAI API : Integration of ChatGPT API in PHP

OpenAI API: ChatGPT has really evolved as the next base for building AI based applications and made a rather bigger boost for itself, since Microsoft has announced to invest heavily into the technology.

The basic concept of ChatGPT was developed by San Francisco startup OpenAI and after foreseeing its prominence impact towards the AI based applications, the Tech world has really given their nod on this.

From automation, business campaign to customer support, ChatGPT has shown its applicability to a wide range of applications.

OpenAI ChatGPT API Integration in PHP

Let’s start the tutorial for a basic integration with ChatGPT OpenAI API:

1) Create an account with OpenAI by going to URL https://openai.com/api/ and login.

2) Get your keys by clicking the “Personal” at the top of the page on the right hand side.

openai api account

3) Now let’s start developing an application using the API. One can start a basic integration by choosing any of the example (application type) by going to URL:

https://platform.openai.com/examples

Let’s say, we want to create a basic application of the type say, English to Other Languages.

Just click on “English to Other Languages” section.

english to other language chat gpt

4) Just scroll down the pop-up box to reach the section as shown below:

Select library from the options as per your suitability. I chose curl.

openapi chatgpt api request

5) Copy this code to make into a file (say translate_from_eng.php).

6) Run the translate_from_eng.php to get the output as follows:

chat gpt api response

A brief guide to use the API, particularly the terms used inside the code can be better understood by visiting the OpenAI API documentation available at the link:

https://platform.openai.com/docs/introduction/overview

Download Script

Recommended Posts For You

About Manish Kumar

I am PHP web developer and blogger.

View all posts by Manish Kumar