Skip to main content

One post tagged with "chatgpt"

View All Tags

Deploy a ChatGPT API Server in no time

· 2 min read

Motivation

Need a ChatGPT API server for quick prototyping? Let's make an endpoint and deploy it with Vercel, for free!

TLDR:

  • you get an endpoint that you can POST JSON to
  • the endpoint will return JSON with the response from "ChatGPT"
  • it's done via OpenAI's official text completion API
  • using the "text-davinci-003" model
  • OpenAI API is not free, but you are given some free credits to try it out
  • you will need OPENAI_API_KEY

Pre-requisites

  • Get a OpenAI API key
  • Have a GitHub account and a Vercel account that is linked to your GitHub account

Steps

If the pre-requisites are met, you can simply click on the button below to deploy. It will guide you through the process of cloning the repository and filling in the environment variable.

Deploy with Vercel


The exact steps are as follows:

  1. Clone/fork my template repository
  2. Go to the Vercel dashboard and click on "Add New..." to import your new repository
  3. Enter the environment variable OPENAI_API_KEY
  4. Deploy the project

DONE!

  • The deployed API will be available at https://your-vercel-project-name.vercel.app/api/chat (or whatever domain that you have configured)

  • Send a POST request with a JSON body of {"message": "Something to ChatGPT"}

E.g. using curl:

curl -i -X POST \
-H "Content-Type:application/json" \
-d \
'{
"message": "Hello, how are you today?"
}' \
'https://your-vercel-project-name.vercel.app/api/chat'
  • The response will be a JSON with the key "response" containing the response from your API server.
{
"response": "I'm doing great! How are you?"
}

Conclusion

That's it! You've now deployed a "ChatGPT" API server with Vercel and OpenAI's official text completion API in no time. If you want to customize your API, you can modify the API code in the cloned repository.

References