/ChatGPT-api-vercel

Deploy ChatGPT API proxy on vercel.🎉 基于 vercel 和 Go 封装 ChatGPT API,支持 vercel 一键部署。

Primary LanguageGoMIT LicenseMIT

ChatGPT-api-vercel

Deploy ChatGPT API proxy using vercel serverless quickily.

Preparation

  1. Access to vercel and login with your github account.
  2. OpenAPI key for OpenAI and set it to OPENAPI_KEY in vercel environment variables.
  3. Fork this repository.
  4. Supported Languages for Serverless Functions | Vercel Docs

Create a project

On vercel dashboard, click New Project and select Import Git Repository.

Choose your forked repository, you don't need to change anything, and click Import and Deploy.

Now you can request vercel API endpoint, for example https://[name].vercel.app/api/hello.

Add ChatGPT Key to environment variables

You can add ChatGPT key to environment variables on vercel dashboard, or use vercel env command.

$cd [root of this repository]

# Add an Environment Variable
$vercel env add CHATGPT_KEY [your ChatGPT key]

#  List all variables for the specified Environment
$vercel env list

Deploy

You can deploy your project on vercel dashboard, or use vercel command.

# Deploy to vercel, and set the environment variable
$vercel

# Deploy to vercel, and set the environment variable for production
$vercel --prod

Develop locally

You can develop locally with vercel dev command.

⚠️Go version should be 1.20 or higher. Keep in mind that Go version should greater than @vercel/go go.mod version. refer to Getting package not found error when running vercel dev in my Go project

Structure

Vercel will use api directory as the entry point for your serverless functions. And the utils directory is used to store the common functions.

Function name can be any name, but should be capitalized. And function should respect type http.HandlerFunc`