Cloudflare Worker Template - ChatGPT API
This is a simple template to set up a Worker with a minimal, CORS-enabled API with an endpoint for demonstrating communication with ChatGPT. This is far from a feature complete API/implementation; consider it a barebones skeleton to get you started on your journey!
<3
Requirements
Getting Started
- Clone this repo
npm install(install the dependencies)- Rename
wrangler.toml.exampletowrangler.toml, and replace the placeholder values with your own. - With the OpenAI key copied to clipboard, run this:
wrangler secret put OPENAI_API_KEYthen paste the key. - You're ready to go!
Commands
npm run dev- launches dev mode to allow testing locally/in browserwrangler publish- publishes the Worker to Cloudflare
Exposed API
POST /gpt
Send a raw message (text or JSON encoded) to this endpoint, expecting the extracted response in reply.
Here's an example from the console (using itty-fetcher for simplification):
