Skip to content

Instantly share code, notes, and snippets.

@MOHU9527
Forked from paicha/openai-proxy.js
Created November 9, 2023 05:54
Show Gist options
  • Save MOHU9527/cf404e0a1e58de74216cea7a1aa9126e to your computer and use it in GitHub Desktop.
Save MOHU9527/cf404e0a1e58de74216cea7a1aa9126e to your computer and use it in GitHub Desktop.
Create an OpenAI API proxy using only 10 lines of code on Cloudflare Worker.
async function handleRequest(request) {
const url = new URL(request.url)
url.host = "api.openai.com"
return fetch(url, { headers: request.headers, method: request.method, body: request.body })
}
addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request))
})
@MOHU9527
Copy link
Author

MOHU9527 commented Nov 9, 2023

WHAT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment