DaaS / Products / Deploy Notion AI Integration on Cloudflare Workers

Deploy Notion AI Integration on Cloudflare Workers

A developer builds a custom Notion AI integration (e.g., an AI agent that reads/writes Notion pages via MCP or OAuth), configures the Cloudflare Worker's environment variables and secrets for Notion API tokens and AI model endpoints, then deploys the worker to production.

Products involved

Scenario

Developers use this workflow when building a serverless AI agent that autonomously reads, summarizes, or updates Notion pages. Hosting the integration on Cloudflare Workers provides low-latency edge execution, encrypted secret management for Notion API tokens, and scalable routing for AI model requests without provisioning traditional infrastructure.

Integration steps

  1. Initialize the Worker: Run npm create cloudflare@latest notion-ai-agent -- --framework none and select TypeScript.
  2. Store Secrets: Securely inject credentials via Wrangler CLI: wrangler secret put NOTION_API_TOKEN, wrangler secret put AI_ENDPOINT, and wrangler secret put AI_API_KEY.
  3. Configure Environment: Add to wrangler.toml:
  4. ``toml [vars] NOTION_VERSION = "2022-06-28" AI_MODEL = "llama-3-8b" ``

  5. Implement Auth & Routing: In src/index.ts, attach Authorization: Bearer ${env.NOTION_API_TOKEN} and Notion-Version: ${env.NOTION_VERSION} to all fetch calls targeting https://api.notion.com/v1/pages/{page_id}.
  6. Wire AI Processing: Route page content to your LLM endpoint or @cloudflare/ai. Transform the response into Notion’s block schema: { type: "paragraph", paragraph: { rich_text: [{ text: { content: aiOutput } }] } }.
  7. Expose MCP/OAuth Endpoints: For MCP, validate JSON-RPC payloads at /mcp. For OAuth, redirect to https://api.notion.com/v1/oauth/authorize and exchange codes via POST https://api.notion.com/v1/oauth/token.
  8. Deploy: Run wrangler deploy --env production. Verify with curl -X POST https://<worker>.workers.dev/api/sync -H "Content-Type: application/json" -d '{"page_id":"..."}'.

Architecture

The Cloudflare Worker acts as the edge orchestration layer. It receives triggers, retrieves encrypted secrets from Cloudflare’s KV/Secrets store, and forwards authenticated REST calls to api.notion.com. AI inference executes either locally via Workers AI or externally. Processed outputs are serialized into Notion-compatible JSON blocks and written back, maintaining sub-100ms latency for standard operations.

Prerequisites

Common pitfalls

Typical questions

FAQ

Q: How do I build and deploy a Notion AI integration on Cloudflare Workers? A: You build and deploy the integration by combining the Notion AI build skill with Cloudflare project configuration and worker deployment skills. After setting up the required credentials, you push the worker to production. This workflow enables an AI agent to securely read and write Notion pages via MCP or OAuth.

Q: What environment variables and secrets should I configure for the worker? A: You must configure the Cloudflare Worker's environment variables and secrets specifically for your Notion API tokens and AI model endpoints. These values provide the authentication and routing information required for the integration to function. Setting them correctly ensures the deployed worker can handle production traffic securely.