Invalid Account ID" Error (ERROR 9426)
I am experiencing a persistent "Invalid Account ID" error (ERROR 9426) when attempting to deliver images via Cloudflare Images using a Worker on my domain, mrlipx.com. I have been troubleshooting this extensively without success, and it appears the issue lies outside of the Worker's code logic.
My Cloudflare Images Account Hash is: HUDbG83RTduFMklKurMDw
The exact error message I receive is:
ERROR 9426: The URL of imagedelivery.net has invalid account id invalid and remove the file ecschon
The full URL that my Worker constructs and attempts to fetch from imagedelivery.net is (example from logs):
https://imagedelivery.net/HUDbG83RTduFMklKurMDw/c1b39c74-1984-48ac-fcf7-a578b8ee1d00/ (Please replace c1b39c74-1984-48ac-fcf7-a578b8ee1d00 with the actual image ID you are testing, and provide the specific URL from your Worker logs if it's different).
My Cloudflare Worker's code (stripped down for clarity) is attached below. This code correctly constructs the imagedelivery.net URL based on your documentation, and includes error handling.
Despite verifying the Account Hash directly from my Cloudflare Images dashboard and confirming the URL structure ( https://imagedelivery.net/<ACCOUNT_HASH>/<IMAGE_ID>/ or /<VARIANT_NAME>), this error persists. This suggests a potential issue with my account's image delivery configuration or how my specific account hash is being processed by the imagedelivery.net endpoint.
1 Reply
const CLOUDFLARE_IMAGES_ACCOUNT_HASH = "HUDbG83RTduFMklKurMDw";
const MAX_OUTPUT_WIDTH = 2500;
const MAX_OUTPUT_HEIGHT = 2500;
const DEFAULT_IMAGE_OPTIONS = {
width: 1200,
fit: "scale-down",
quality: 85
};
function parseTransformationSlug(slug) {
let options = {};
const widthMatch = slug.match(/w(\d+)/);
if (widthMatch) {
options.width = Math.min(parseInt(widthMatch[1]), MAX_OUTPUT_WIDTH);
}
const heightMatch = slug.match(/h(\d+)/);
if (heightMatch) {
options.height = Math.min(parseInt(heightMatch[1]), MAX_OUTPUT_HEIGHT);
}
const fitMatch = slug.match(/f(scale-down|contain|cover|crop|pad|squeeze)/);
if (fitMatch) {
options.fit = fitMatch[1];
} else if (options.width options.height) {
options.fit = "scale-down";
}
const qualityMatch = slug.match(/q(\d{1,3})/);
if (qualityMatch) {
options.quality = Math.max(0, Math.min(100, parseInt(qualityMatch[1])));
}
const gravityMatch = slug.match(/g(auto|top|bottom|left|right|center)/);
if (gravityMatch) {
options.gravity = gravityMatch[1];
}
return options;
}
export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
const pathSegments = url.pathname.split('/').filter(Boolean);
if (pathSegments.length < 2) {
return new Response("Invalid Image URL Structure.", { status: 400 });
}
const transformationSlugWithExt = pathSegments[pathSegments.length - 1];
const uniqueImageId = pathSegments[pathSegments.length - 2];
const lastDotIndex = transformationSlugWithExt.lastIndexOf('.');
const transformationSlug = lastDotIndex !== -1
? transformationSlugWithExt.substring(0, lastDotIndex)
: transformationSlugWithExt;
const cloudflareImageId = uniqueImageId;
if (!cloudflareImageId) { return new Response("Image Not Found or ID Invalid.", { status: 404 }); } let imageOptions = {}; let usePredefinedVariant = null; if (transformationSlug === 'original') { imageOptions = {}; } else if (transformationSlug === 'public' transformationSlug === 'thumbnail' || transformationSlug === 'medium') { usePredefinedVariant = transformationSlug; } else { imageOptions = parseTransformationSlug(transformationSlug); if (Object.keys(imageOptions).length === 0) { imageOptions = DEFAULT_IMAGE_OPTIONS; } } let cfDeliveryUrl; const headers = new Headers(request.headers); if (usePredefinedVariant) { cfDeliveryUrl =
const imageRequest = new Request(cfDeliveryUrl, { headers: headers, cf: { image: imageOptions } }); try { const response = await fetch(imageRequest); if (!response.ok) { // If Cloudflare Images returns an error, pass its status and potentially its body const errorText = await response.text(); return new Response(
if (!cloudflareImageId) { return new Response("Image Not Found or ID Invalid.", { status: 404 }); } let imageOptions = {}; let usePredefinedVariant = null; if (transformationSlug === 'original') { imageOptions = {}; } else if (transformationSlug === 'public' transformationSlug === 'thumbnail' || transformationSlug === 'medium') { usePredefinedVariant = transformationSlug; } else { imageOptions = parseTransformationSlug(transformationSlug); if (Object.keys(imageOptions).length === 0) { imageOptions = DEFAULT_IMAGE_OPTIONS; } } let cfDeliveryUrl; const headers = new Headers(request.headers); if (usePredefinedVariant) { cfDeliveryUrl =
https://imagedelivery.net/${CLOUDFLARE_IMAGES_ACCOUNT_HASH}/${cloudflareImageId}/${usePredefinedVariant}
;
} else {
cfDeliveryUrl = https://imagedelivery.net/${CLOUDFLARE_IMAGES_ACCOUNT_HASH}/${cloudflareImageId}/
;
}
const imageRequest = new Request(cfDeliveryUrl, { headers: headers, cf: { image: imageOptions } }); try { const response = await fetch(imageRequest); if (!response.ok) { // If Cloudflare Images returns an error, pass its status and potentially its body const errorText = await response.text(); return new Response(
Image Delivery Error: ${errorText}
, { status: response.status, headers: response.headers });
}
return response;
} catch (error) {
// Catch network or other fetch-related errors
return new Response(Internal Server Error: Could not fetch image.
, { status: 500 });
}
}
};