-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WHAT