Skip to content

About

Deploy an OpenAI-compatible endpoint backed by Cloudflare Workers AI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

24 Commits

Folders and files

Repository files navigation

Cloudflare AI Deployer — open.notebooker.ai

Deploy an OpenAI-compatible endpoint backed by Cloudflare Workers AI to your own Cloudflare account — from your browser.

Use it hosted at open.notebooker.ai, or clone this repo and run the same app locally.

Pick models from the live Cloudflare catalog, deploy, and test everything in the browser: streaming chat, image generation, text-to-speech, speech-to-text (file upload), vision (image upload), and embeddings similarity — plus an estimated free-tier usage monitor and a downloadable credentials.txt for your endpoint.

Supports chat/completions (including vision models), images/generations, images/edits, images/variations, embeddings, audio/transcriptions, and audio/speech — each endpoint is enabled only if you pick a model for it.

How it works

  • No login, no database. You paste a scoped Cloudflare API token; it lives only in an AES-GCM-encrypted, expiring HttpOnly cookie. Every Cloudflare call is proxied server-side, so the token never reaches the browser. Delete the token in Cloudflare when you're done — a new one restores access later.
  • Config is remembered in your account. Worker name + models (never secrets) are stored in a KV namespace in your own Cloudflare account and rediscovered on your next visit.
  • The endpoint API key is never persisted anywhere. It exists as the worker's write-only secret and, transiently, in your session cookie. Save it when it's shown (or download credentials.txt); renewing replaces it. Model changes never touch the key (the redeploy uses an inherit binding).
  • Just testing? Upload your credentials.txt (or enter base URL + key) on the homepage to use the testers without any Cloudflare token — management stays locked until you provide one.

Using the app

  1. Open open.notebooker.ai (or your local instance).

  2. Follow the Before you start checklist: verify your Cloudflare account email, and visit Workers AI once so your workers.dev subdomain gets registered.

  3. Create a Custom API token at dash.cloudflare.com → API Tokens, scoped to your account:

    Resource Permission
    Workers Scripts Edit
    Workers KV Storage Edit
    Workers AI Read
    Account Analytics Read
  4. Paste it in, pick your models, deploy, test, and download your credentials.

Gated models: some Meta models (e.g. @cf/meta/llama-3.2-11b-vision-instruct) need a one-time license agreement per account — if chat replies with a license notice, send the single message agree once.

@cf/deepgram/flux is WebSocket-only and can't work through this request/response API (it's filtered from the picker).

Running locally

git clone https://github.com/Notebooker-ai/cloudflare-ai-deployer
cd cloudflare-ai-deployer/web
npm install
npm run dev            # http://localhost:4321

web/.dev.vars ships with a dev-only SESSION_SECRET. Paste your scoped token on the landing page and you get the full dashboard against your own account. See web/README.md for architecture, the security model, and deploying your own instance.

Using your endpoint

Point any OpenAI-compatible client at your base URL with your bearer key:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://<worker>.<your-subdomain>.workers.dev/v1",
  apiKey: "<your bearer key>",
});

const res = await client.chat.completions.create({
  model: "chat",
  messages: [{ role: "user", content: "Hello!" }],
});

Or with curl:

# Chat
curl $BASE_URL/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"chat","messages":[{"role":"user","content":"Hi"}]}'

# Image generation (base64 PNG/JPEG in data[0].b64_json)
curl $BASE_URL/images/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"text_to_image","prompt":"A red apple on a white table","n":1}'

# Image edit (image-to-image models; add -F mask=@mask.png to inpaint)
curl $BASE_URL/images/edits \
  -H "Authorization: Bearer $API_KEY" \
  -F "model=text_to_image" \
  -F "image=@room.png" \
  -F "prompt=add a sleeping cat on the desk"

# Embeddings
curl $BASE_URL/embeddings \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"embedding","input":"hello world"}'

# Text-to-speech (writes audio file)
curl $BASE_URL/audio/speech \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"text_to_speech","input":"Hello!"}' \
  --output speech.wav

# Speech-to-text
curl $BASE_URL/audio/transcriptions \
  -H "Authorization: Bearer $API_KEY" \
  -F "file=@sample.m4a" \
  -F "model=speech_to_text"

The model field accepts either the type alias (chat, text_to_image, embedding, text_to_speech, speech_to_text) or the full Cloudflare model id.

Images

All three OpenAI image routes are implemented:

Route What it needs Which models can serve it
POST /v1/images/generations prompt text-to-image models
POST /v1/images/edits image + prompt, optional mask image-to-image models
POST /v1/images/variations image, prompt optional image-to-image models

Diffusion models differ in what they accept, so the worker publishes each one's capabilities and only advertises the routes it can serve:

curl $BASE_URL/models -H "Authorization: Bearer $API_KEY"
# { "id": "text_to_image", "backend": "@cf/stabilityai/stable-diffusion-xl-base-1.0",
#   "capabilities": ["text-to-image", "image-to-image", "inpainting"] }

Ask a model for something it can't do and you get a 400 that says where to go instead — model_requires_image (inpainting models can't work from a prompt alone), model_no_image_input (Flux can't take a source image), model_no_mask_input (img2img models can't take a mask). The dashboard's image tester reads the same capabilities and only offers the modes that will work.

Caveats a storage-less worker implies, and the knobs it adds:

  • There's nowhere to host a generated file, so images always come back inline. response_format defaults to b64_json; "url" returns a data: URI so clients that only read data[].url keep working.
  • n is 1–4. Workers AI produces one image per inference call, so n images cost n calls (run sequentially) against your free-tier neurons.
  • size accepts auto or WIDTHxHEIGHT (each side 256–2048). Flux models generate at a fixed size and ignore it.
  • quality (low / medium / standard / high / hd) maps onto the model's diffusion step count — capped at 8 for Flux, 20 for Stable Diffusion.
  • Non-OpenAI extras: steps, negative_prompt, guidance, seed, and strength (Stable Diffusion family only). strength defaults to 0.75 for edits, 1 for masked edits, and 0.5 for variations, since Workers AI's own default of 1 discards the source image.
  • /edits and /variations take multipart/form-data like the OpenAI SDKs send, and also accept a JSON body with image/mask as base64 (or a data: URI) for convenience.
  • Variations have no prompt in the OpenAI spec but every Workers AI diffusion model requires one, so a neutral prompt is substituted; pass your own prompt to steer it.
const img = await client.images.generate({
  model: "text_to_image",
  prompt: "A neon terminal glowing in a dark room",
});
// Buffer.from(img.data[0].b64_json, "base64")

const edited = await client.images.edit({
  model: "text_to_image",
  image: fs.createReadStream("room.png"),
  mask: fs.createReadStream("mask.png"), // optional, inpainting models only
  prompt: "add a sleeping cat on the desk",
});

To use your endpoint inside Notebooker.ai, see the guide: Run your own AI provider.

Repo layout

workers/template-unified.js   the worker that gets deployed (single source of truth)
web/                          the Astro app (open.notebooker.ai)
test/                         vitest suite for the worker template

Tests

Unit tests run without credentials:

npm test

To run the integration suites against a deployed worker, create a .env with:

OPENAI_BASE_URL=https://<worker>.<your-subdomain>.workers.dev/v1
API_KEY=<your bearer key>

Then npm test again — integration tests auto-skip any endpoint type that isn't deployed.

About

Deploy an OpenAI-compatible endpoint backed by Cloudflare Workers AI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages