Skip to content

OpenGG/openai-proxy-worker

Repository files navigation

openai-proxy-worker

Proxy OpenAI api requests through cloudflare workers.

Usage

  1. Prepare project.
pnpm i

cp wrangler.toml.example wrangler.toml
cp .dev.vars.example .dev.vars
  1. Change worker name with your own.
vi wrangler.toml
  1. (optional) Fill SECRET_OPENAI_API_KEY for local development.
vi .dev.vars

pnpm run dev
  1. Put secrets into worker. This step can be done via web. See: Add environment variables via the dashboard
  • SECRET_AUTH_KEYS: Auth keys for incoming requests. Make sure it is STRONGGGGGGGG enough.
  • SECRET_OPENAI_API_KEY: Api key for invoking OpenAI API. See: API keys on OpenAI
  • ENV_OPENAI_ALLOWED_MODELS: Allowed list of models. See: Model endpoint compatibility
  1. Deploy worker.
pnpm run deploy
  1. Request with an auth key
curl --verbose --request POST 'https://your-worker.workers.dev/v1/chat/completions' \
--header 'Authorization: KEY your_auth_key' \
--header 'Content-Type: application/json' \
--data-raw '{
 "model": "gpt-3.5-turbo",
 "messages": [{
    "role": "user",
    "content": "Tell me who you are"
 }]
}'

Notes:

  • Suggestion for ENV_OPENAI_ALLOWED_MODELS: gpt-3.5-turbo, gpt-3.5-turbo-0301, text-curie-001, text-babbage-001, text-ada-001

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors