Skip to content

Easy-Email-Pro/easy-email-pro-ai-agent-worker

Repository files navigation

easy-email-pro-ai-worker

Cloudflare Worker for the Easy Email Pro AI agent. It exposes the Easy Email agent streaming API and forwards AI requests through Cloudflare AI Gateway.

Requirements

  • A Cloudflare account
  • A Cloudflare AI Gateway configured for the OpenAI-compatible provider
  • A Cloudflare API token that can call that gateway
  • Node.js and pnpm

This directory is intended to be usable as a standalone project. Run the commands below from inside the easy-email-pro-ai-worker directory.

Environment variables

Only two variables are required:

CLOUDFLARE_AI_GATEWAY_BASE_URL=https://gateway.ai.cloudflare.com/v1/<account_id>/<gateway_id>/openai
CF_TOKEN=<cloudflare_api_token>

Optional overrides:

AI_TEXT_MODEL=gpt-5.4-mini
AI_IMAGE_MODEL=openai/gpt-image-1-mini
AI_IMAGE_QUALITY=medium

If the optional values are not set, the worker uses the defaults shown above.

Local setup

Install dependencies:

pnpm install

Copy the example environment file:

cp .env.example .env

Fill in CLOUDFLARE_AI_GATEWAY_BASE_URL and CF_TOKEN, then start the worker:

pnpm dev

API

The worker exposes:

POST /v1/easy-email/respond-stream

The response is Server-Sent Events. The request body follows the Easy Email AI agent request shape used by the editor integration:

{
  "prompt": {
    "text": "Help me improve this email"
  },
  "template": {
    "subject": "Test",
    "content": {
      "type": "page",
      "children": []
    }
  },
  "images": [],
  "history": null
}

The worker does not require a public API bearer token or allowed-origin list. Protect access at your deployment boundary if the endpoint should not be public.

Cloudflare deployment

Build and deploy with:

pnpm deploy

For a dry run:

pnpm check:cf

Set the required environment variables in Cloudflare before deploying. For deployment, configure CLOUDFLARE_AI_GATEWAY_BASE_URL and CF_TOKEN in the Cloudflare dashboard, or set them with Wrangler:

printf '%s' 'https://gateway.ai.cloudflare.com/v1/<account_id>/<gateway_id>/openai' \
  | pnpm wrangler secret put CLOUDFLARE_AI_GATEWAY_BASE_URL

printf '%s' '<cloudflare_api_token>' \
  | pnpm wrangler secret put CF_TOKEN

Do not commit customer-specific Gateway URLs or tokens into wrangler.toml.

Verification

Run the worker tests:

pnpm test:worker

Run TypeScript checks:

pnpm typecheck

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors