Sample edge worker implementations for Adobe LLM Optimizer - Optimize at Edge Bring Your Own CDN (BYOCDN) integration. These samples show how to route agentic bot traffic (AI/LLM user agents) through your existing CDN to the Edge Optimize backend for optimized content delivery.
Adobe Edge Optimize improves how AI-powered agents and LLM bots consume your website content. When you manage your own CDN, you can use these edge worker samples to transparently intercept agentic bot requests and route them to Edge Optimize — while serving all other visitors (humans and SEO bots) from your origin as usual.
┌──────────────┐
│ Incoming │
│ Request │
└──────┬───────┘
│
┌──────▼───────┐
│ Edge Worker │
│ (Bot Check) │
└──┬────────┬──┘
│ │
Agentic Bot Human / SEO Bot
│ │
┌──────▼──┐ ┌──▼──────────┐
│ Edge │ │ Origin │
│ Optimize│ │ Server │
└─────────┘ └─────────────┘
- An edge worker intercepts every incoming request.
- The User-Agent header is checked against a configurable list of known agentic bots.
- Agentic bots are routed to the Edge Optimize backend (
live.edgeoptimize.net). - All other traffic passes through to your origin unchanged.
- If Edge Optimize returns an error, the request fails over to your origin automatically.
Both samples ship with the following default bot list (easily configurable):
| Bot | User-Agent String |
|---|---|
| Adobe Edge Optimize Test | AdobeEdgeOptimize-AI |
| OpenAI (browsing) | ChatGPT-User |
| OpenAI (crawler) | GPTBot |
| OpenAI (search) | OAI-SearchBot |
| Perplexity (crawler) | PerplexityBot |
| Perplexity (browsing) | Perplexity-User |
| Claude (crawler) | ClaudeBot |
| Claude (browsing) | Claude-User |
| Claude (search) | Claude-SearchBot |
A single Cloudflare Worker that handles routing, failover, and loop protection.
File: cloudflare/worker.js
- Routes agentic bot traffic to Edge Optimize
- Automatic failover to origin on any 4XX or 5XX error
- Loop protection via
x-edgeoptimize-requestheader - Caching support via Cloudflare's
cf.cacheEverything - Configurable targeted paths (all HTML pages by default)
| Variable | Description |
|---|---|
EDGE_OPTIMIZE_API_KEY |
Your Adobe-provided API key |
EDGE_OPTIMIZE_TARGET_HOST |
Your origin domain (falls back to the request host) |
Edit the constants at the top of worker.js:
// Add or remove bot user agents
const AGENTIC_BOTS = ['ChatGPT-User', 'GPTBot', ...];
// Set to null to route all HTML pages, or specify an array of paths
const TARGETED_PATHS = null; // e.g., ['/', '/page.html', '/products']
// Failover behavior
const FAILOVER_ON_4XX = true;
const FAILOVER_ON_5XX = true;A two-layer setup using CloudFront Functions (viewer request) and Lambda@Edge (origin request + origin response).
Viewer Request (CloudFront Function)
→ Detects agentic bots, sets headers, creates origin group with failover
Origin Request (Lambda@Edge)
→ Sets host header for Edge Optimize origin; marks failover requests
Origin Response (Lambda@Edge)
→ Prevents caching of failover responses
| File | Purpose |
|---|---|
cloudfront/cloudfront-function/viewer-request.js |
CloudFront Function — viewer request handler that detects bots and sets up origin group routing with failover |
cloudfront/lambda/origin-request-response.js |
Lambda@Edge — handles both origin-request and origin-response events |
cloudfront/lambda/trust-policy.json |
IAM trust policy for the Lambda execution role |
cloudfront/lambda/cloudwatch-policy.json |
IAM policy granting CloudWatch Logs permissions |
- Create a CloudFront Origin named
EdgeOptimize_Originpointing tolive.edgeoptimize.net(HTTPS, port 443). - Deploy the CloudFront Function (
viewer-request.js) and associate it with your distribution's Viewer Request event. - Create a Lambda@Edge function with the code from
origin-request-response.js. - Attach the IAM policies (
trust-policy.jsonandcloudwatch-policy.json) to the Lambda execution role. ReplaceACCOUNT_IDandFUNCTION_NAMEwith your values. - Associate the Lambda@Edge function with both the Origin Request and Origin Response events on your distribution.
Edit the constants in viewer-request.js:
// Add or remove bot user agents
var AGENTIC_BOTS = ['ChatGPT-User', 'GPTBot', ...];
// Set to null to route all HTML pages, or specify an array of paths
var TARGETED_PATHS = null; // e.g., ['/', '/products', '/about']Update the origin IDs in the cf.createRequestOriginGroup call to match your CloudFront distribution:
cf.createRequestOriginGroup({
"originIds": [
{ "originId": "EdgeOptimize_Origin" }, // Your Edge Optimize origin
{ "originId": "YOUR_DEFAULT_ORIGIN" } // Your default/fallback origin
],
"failoverCriteria": {
"statusCodes": [400, 403, 404, 416, 500, 502, 503, 504]
}
});| Header | Direction | Description |
|---|---|---|
x-forwarded-host |
→ Edge Optimize | The original site domain |
x-edgeoptimize-api-key |
→ Edge Optimize | Your Adobe-provided API key |
x-edgeoptimize-url |
→ Edge Optimize | The original request URL path and query |
x-edgeoptimize-config |
→ Edge Optimize | Configuration flags (e.g., LLMCLIENT=TRUE;) |
x-edgeoptimize-request |
Internal | Loop/failover protection marker |
x-edgeoptimize-request-id |
← Edge Optimize | Present when Edge Optimize processed the request |
x-edgeoptimize-fo |
← Response | Set to 1 when failover to origin occurred |
This project is licensed under the Apache License 2.0.