pokon548 / ai-gateway-openai-wrapper

Provide OpenAI compatible, cost effective and proxied api endpoints on Cloudflare Worker. Foolproof considered
GNU Affero General Public License v3.0
134 stars 40 forks source link
chatgpt cloudflare-workers openai-api

AI Gateway (OpenAI) Wrapper

Provide you OpenAI compatible, cost effective and proxied api endpoints on Cloudflare Worker. Foolproof considered.

Deploy to Cloudflare Workers

Features

Getting Started

  1. Create your OpenAI API key on OpenAI Platform. For best foolproof effect, we recommend you do not reuse old one and create fresh new key solely used by this worker.
  2. Create AI Gateway in Cloudflare.
  3. Deploy this worker by Clicking Here.
  4. Add following environment variables to your newly created worker (Encrypting these variables is strongly advised!):
    • AI_GATEWAY_ENDPOINT_URL: Your AI Gateway endpoint url. Should looks like: https://gateway.ai.cloudflare.com/v1/ACCOUNT_TAG/GATEWAY/openai.
    • DUMMY_WRAPPER_KEY: Your API key supplied when you calling the wrapper endpoint. Can be any string. This cannot be the the same with your real OpenAI key. Otherwise your request will be rejected by worker for foolproof reason.
    • REAL_OPENAI_KEY: Your real OpenAI API key. Should looks like: sk-123456789012345678901234567890123456789012345678.
  5. Use your worker domain as endpoint and DUMMY_WRAPPER_KEY as api key. Profit.