{"id":29344350,"url":"https://github.com/kathleenwest/cloudflare-openai-worker","last_synced_at":"2026-04-29T21:03:20.198Z","repository":{"id":302723508,"uuid":"1002624458","full_name":"kathleenwest/cloudflare-openai-worker","owner":"kathleenwest","description":"A Cloudflare Worker with simple HTTP endpoints for generating Madlib stories and images using OpenAI APIs. Features /madlib for story creation and /image for AI-generated images. Built with itty-router and the OpenAI Node.js SDK.","archived":false,"fork":false,"pushed_at":"2025-07-13T22:11:48.000Z","size":1918,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-14T00:20:00.323Z","etag":null,"topics":["ai","api","artificial-intelligence","cloudflare","cloudflare-worker","cloudflare-workers","cors","dall-e","gateway","gpt","image-generation","itty","itty-router","itty-router-openapi","madlibs","nodejs","openai","serverless","story-generation","wrangler"],"latest_commit_sha":null,"homepage":"https://kathleenwest.github.io/wacky-madlib-frontend/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kathleenwest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-15T21:25:25.000Z","updated_at":"2025-07-13T22:11:51.000Z","dependencies_parsed_at":"2025-07-03T22:40:58.980Z","dependency_job_id":null,"html_url":"https://github.com/kathleenwest/cloudflare-openai-worker","commit_stats":null,"previous_names":["kathleenwest/cloudflare-openai-worker"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kathleenwest/cloudflare-openai-worker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kathleenwest%2Fcloudflare-openai-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kathleenwest%2Fcloudflare-openai-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kathleenwest%2Fcloudflare-openai-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kathleenwest%2Fcloudflare-openai-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kathleenwest","download_url":"https://codeload.github.com/kathleenwest/cloudflare-openai-worker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kathleenwest%2Fcloudflare-openai-worker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32443576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T20:22:27.477Z","status":"ssl_error","status_checked_at":"2026-04-29T20:22:26.507Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","api","artificial-intelligence","cloudflare","cloudflare-worker","cloudflare-workers","cors","dall-e","gateway","gpt","image-generation","itty","itty-router","itty-router-openapi","madlibs","nodejs","openai","serverless","story-generation","wrangler"],"created_at":"2025-07-08T14:00:46.153Z","updated_at":"2026-04-29T21:03:20.194Z","avatar_url":"https://github.com/kathleenwest.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenAI Worker on Cloudflare\n\nA Cloudflare Worker that exposes simple HTTP endpoints for generating Madlib stories and images using OpenAI APIs. \n\n![a dog with googles flying on a Cloudflare cloud](images/cloudflaredoggie.png)\n\nBuilt with [itty-router](https://github.com/kwhitley/itty-router) and the [OpenAI Node.js SDK](https://github.com/openai/openai-node).\n\n---\n## Table of Contents\n\n- [OpenAI Worker on Cloudflare](#openai-worker-on-cloudflare)\n  - [Table of Contents](#table-of-contents)\n  - [Features](#features)\n  - [Installation](#installation)\n  - [Configuration](#configuration)\n  - [Development](#development)\n  - [Deployment](#deployment)\n  - [Endpoints](#endpoints)\n    - [`GET /`](#get-)\n    - [`POST /madlib`](#post-madlib)\n    - [`POST /image`](#post-image)\n  - [Gateway Configuration](#gateway-configuration)\n  - [Project Structure](#project-structure)\n  - [Frontend Project](#frontend-project)\n  - [Demo Videos](#demo-videos)\n    - [Wacky Madlib App Marketing Video](#wacky-madlib-app-marketing-video)\n    - [Behind the Code, Architecture, and Demo](#behind-the-code-architecture-and-demo)\n\n## Features\n\n- **/madlib**: Generate a humorous Madlib story using OpenAI GPT-4.1-nano.\n- **/image**: Generate an image using OpenAI DALL-E.\n- CORS enabled for easy integration with web clients.\n\n---\n\n## Installation\n\n```sh\nnpm install\n```\n\n---\n\n## Configuration\n\n1. **Set your OpenAI API key as a secret:**\n\n   ```sh\n   npx wrangler secret put OPENAI_API_KEY\n   ```\n\n2. **Configure your Cloudflare OpenAI Gateway:**\n\n   - Replace `your_gateway_url_here` in [`src/index.js`](src/index.js) with your actual Cloudflare OpenAI Gateway URL.\n   - Replace `your_account_id` in [`wrangler.toml`](wrangler.toml) with your Cloudflare account ID.\n   - Update the `routes` pattern in [`wrangler.toml`](wrangler.toml) as needed.\n\n---\n\n## Development\n\nStart a local development server:\n\n```sh\nnpm run dev\n```\n\n---\n\n## Deployment\n\nDeploy to Cloudflare Workers:\n\n```sh\nnpm run deploy\n```\n\n---\n\n## Endpoints\n\n### `GET /`\n\n- Returns: `\"Hello!\"`  \n- Use to test connectivity.\n\n---\n\n### `POST /madlib`\n\n- **Body:** JSON array of words, e.g. `[\"cat\", \"banana\", \"run\"]`\n- **Returns:** A short, humorous Madlib story (≤ 50 words) using the provided words.\n\n**Example:**\n\n```sh\ncurl -X POST https://\u003cyour-worker-url\u003e/madlib \\\n  -H \"Content-Type: application/json\" \\\n  -d '[\"cat\", \"banana\", \"run\"]'\n```\n\n---\n\n### `POST /image`\n\n- **Body:** Plain text prompt describing the image.\n- **Returns:** JSON with a base64-encoded image.\n\n**Example:**\n\n```sh\ncurl -X POST https://\u003cyour-worker-url\u003e/image \\\n  -H \"Content-Type: text/plain\" \\\n  --data \"A cat running with a banana\"\n```\n\n**Response:**\n\n```json\n{\n  \"b64_json\": \"\u003cbase64-encoded-image\u003e\"\n}\n```\n\n---\n\n## Gateway Configuration\n\n- The worker uses a Cloudflare OpenAI Gateway for API calls.\n- Update the `baseURL` in [`src/index.js`](src/index.js) to your gateway URL.\n- See [Cloudflare OpenAI Gateway docs](https://developers.cloudflare.com/openai/gateway/) for setup instructions.\n\n---\n\n## Project Structure\n\n- [`src/index.js`](src/index.js): Worker source code and endpoint logic.\n- [`wrangler.toml`](wrangler.toml): Cloudflare Worker configuration.\n- [`wrangler.jsonc`](wrangler.jsonc): Additional Wrangler config.\n- [`package.json`](package.json): Project dependencies and scripts.\n\n---\n## Frontend Project\n\n[wacky-madlib-frontend](https://github.com/kathleenwest/wacky-madlib-frontend)\n\nA playful web app for generating wacky, AI-powered stories and images. Built with Vite and vanilla JS, it connects to an OpenAI backend via Cloudflare Workers and the Cloudflare AI Gateway for secure and efficient AI API usage. Great for fun, creativity, and demoing modern AI integration.\n\nTo be able to play with the app, you can visit the live demo at: https://kathleenwest.github.io/wacky-madlib-frontend/\n\n---\n## Demo Videos\n\n### Wacky Madlib App Marketing Video\n\n😂Wacky Madlib App Made THIS?! [Watch on YouTube](https://www.youtube.com/shorts/qyWQo9VDbt8 \"😂Wacky Madlib App Marketing Video\")\n\n🦝✨ Ever wondered what happens when you mix AI with total nonsense? Meet the Wacky Madlib App—where YOU choose the words (like “Disco Raccoon,” “Boogie,” and “Squishy”), and the AI turns them into a hilariously unhinged story… then generates an image to match. Yes, it’s as weird as it sounds—and yes, you’re going to love it.\n\n🎉 In this short demo, watch the magic unfold as our AI spins your wildest word combos into a story that makes zero sense and 100% joy. Bonus: You get to see a raccoon in bell-bottoms. You’re welcome.\n\n🧠 Built with Cloudflare Workers + AI wizardry\n🎨 Story + Image = Instant chaos\n😂 Try it. Share it. Confuse your friends.\n👉 Like, comment, and subscribe for more AI-powered absurdity!\n\nWatch the funny marketing demo video on [YouTube](https://www.youtube.com/shorts/qyWQo9VDbt8 \"😂Wacky Madlib App Marketing Video\")\n\n### Behind the Code, Architecture, and Demo\n\n🎬 Madlibs, Mayhem \u0026 Magic: Behind the Code and Demo of My AI Generator [Watch on Youtube](https://www.youtube.com/watch?v=LTxtzDpAH1A \"Behind the Code and Demo of My AI Generator\")\n\nReady for an AI-powered rollercoaster of absurdity and innovation? In this demo, I take you deep into the colorful chaos of my Madlib Generator web app, where users throw in wild nouns, quirky verbs, and eccentric adjectives to spark utterly ridiculous stories. Once a story is born, DALL·E jumps in to create matching visuals—unless you're stuck in cache déjà vu! 💥 This app is lightning-fast thanks to Cloudflare Workers and a strategically crafted AI Gateway that caches responses, reduces costs, and keeps the backend humming.\n\nBut it’s not just about the giggles—this walkthrough dives into the technical nuts and bolts. I break down the architecture from frontend to backend, show how token usage and caching strategies are logged in real time, and even zoom into analytics dashboards to analyze traffic patterns, response times, and OpenAI API usage legs. Whether you're here for the weird stories or the sleek design powered by vanilla JavaScript, it’s a wild blend of creativity, performance, and practical engineering. Buckle up, because this isn’t just a demo—it’s a celebration of playful problem-solving at the edge. 🚀🧠\n\nWatch the complete video on [Youtube](https://www.youtube.com/watch?v=LTxtzDpAH1A \"Behind the Code and Demo of My AI Generator\")\n\n---\nKeep the nonsense alive!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkathleenwest%2Fcloudflare-openai-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkathleenwest%2Fcloudflare-openai-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkathleenwest%2Fcloudflare-openai-worker/lists"}