OpenAI Domestic Proxy Tutorial

Published 2023-04-07 00:19 356 words 2 min read

Use a cloud function to build a domestic OpenAI reverse proxy API, enabling OpenAI usage without a VPN

This chapter documents how to use a domestic cloud to reverse-proxy OpenAI

Register a Tencent Cloud Account

Click to go to Tencent Cloud

Enter the Cloud Function Console

Click to go directly to the Cloud Function Console

Create a New Cloud Function

Basic Configuration

  1. Step 1
    • Click Create
    • Select web function as the function type
    • Any name is fine; here I named it: openAI
    • Choose Hong Kong or another overseas region
    • Time zone: Default

Function Code

  1. Step 2

Log Configuration

  1. Step 3
    • If you enable it, fees may be incurred — a few mao? About one yuan? It depends on your usage!!!

Advanced Configuration

  1. Step 4
    • Start with the environment configuration
    • Memory: 64MB
    • Initialization timeout: Default
    • Execution timeout: 900 seconds
  1. Step 5
  • Scroll down to Request concurrency
  • Enable it and choose 2 concurrent
  • Everything not mentioned: Default

Trigger Configuration

  1. Step 6
    • Type: Default
    • Alias: Default
    • Request method: select ANY
    • Release environment: Default
    • Authentication method: No authentication

This step may go like mine: the related server role is abnormal — just click to authorize. If that doesn't work, create a new trigger

Address

  • You need to remove the trailing /release
  • The resulting address is your API endpoint
  • Accessing it directly will return 404

How to Use the API

Use it in any software that supports configuring the OpenAI domain

Example:

  • Using a third party: CatGPT
  • Click the 🔑 icon in the top right corner, and enter the address we built in the API address field
  • Enjoy using OpenAI

OpenAI Node.js

Official usage

const configuration = new Configuration({
  apiKey: OPENAI_API_KEY,
  basePath: 'https://service-aaaaa.hk.apigw.tencentcs.com/v1'
})

Self-Hosting

Hosting steps

git clone https://github.com/Ice-Hazymoon/openai-scf-proxy
cd openai-scf-proxy
npm install
npm run start

Notes

You need to register your own OpenAI—key Someone else's OpenAI—key may require payment

If you enjoyed this, leave a comment~

... Page views
© 2021 - 2026 Vullfin @VV
Powered by theme astro-koharu · Inspired by Shoka