musistudio/claude-code-router · error
The CCR artifact endpoint attempted a redirect.
Error message
The CCR artifact endpoint attempted a redirect.
What it means
Even though fetch was configured with redirect: 'error' (which normally makes redirects throw and produce error 50), some runtimes/servers can still yield a response flagged as redirected (e.g. non-standard redirect handling or a transparent proxy rewrite). This defensive check rejects any response whose final URL differs from the requested one.
Source
Thrown at packages/core/src/agents/codex/media-preview-bridge.ts:305
if (keys.length !== 1 || keys[0] !== "token" || !/^[A-Za-z0-9_-]{32}$/.test(token)) {
throw new Error("Artifact URL contains an invalid access token.");
}
return { artifactId, url };
}
async function loadCodexMediaArtifact(validated: ValidatedArtifactUrl, signal: AbortSignal): Promise<LoadedMediaArtifact> {
let response: Response;
try {
response = await fetch(validated.url, {
headers: { accept: "image/*, video/*" },
redirect: "error",
signal
});
} catch {
throw new Error("The CCR artifact request failed.");
}
if (!response.ok) throw new Error(`The CCR artifact endpoint returned HTTP ${response.status}.`);
if (response.redirected) throw new Error("The CCR artifact endpoint attempted a redirect.");
const declaredMimeType = (response.headers.get("content-type") || "").split(";", 1)[0].trim().toLowerCase();
const declaredKind = mediaKind(declaredMimeType);
if (!declaredKind) throw new Error("The CCR artifact endpoint returned a non-media content type.");
const maxBytes = declaredKind === "video" ? codexMediaPreviewMaxVideoBytes : codexMediaPreviewMaxImageBytes;
const declaredLength = Number(response.headers.get("content-length") || "0");
if (declaredLength && (!Number.isSafeInteger(declaredLength) || declaredLength < 1 || declaredLength > maxBytes)) {
throw new Error("The CCR media artifact exceeds the inline preview size limit.");
}
if (response.headers.get("content-encoding") && response.headers.get("content-encoding") !== "identity") {
throw new Error("Compressed CCR media artifacts are not accepted for inline preview.");
}
if (!response.body) throw new Error("The CCR artifact response had no body.");
const reader = response.body.getReader();
const chunks: Buffer[] = [];
let total = 0;
while (true) {
const part = await reader.read();
if (part.done) break;View on GitHub (pinned to 99f24806c6)
Solutions
- Identify what is redirecting: fetch the URL manually with curl -v and inspect for 3xx or Location headers
- Bypass or configure the proxy so the artifact URL is served directly
- Ensure the runtime's fetch honors redirect: 'error' (upgrade Node >= 18 native fetch rather than a polyfill)
- Use the final canonical URL of the artifact in the reference
Defensive patterns
Strategy: validation
Validate before calling
// Verify the URL serves directly without a redirect before calling artifact()
async function isRedirectFree(url: string): Promise<boolean> {
const res = await fetch(url, { method: 'HEAD', redirect: 'error' });
return !res.redirected;
} Type guard
function isRedirectRejection(e: unknown): boolean {
return e instanceof Error && e.message.includes('attempted a redirect');
} Try / catch
try {
const media = await bridge.artifact(ref);
} catch (e) {
if (isRedirectRejection(e)) return renderAsExternalLink(ref.url);
throw e;
} Prevention
- Store canonical, non-redirecting artifact URLs
- Avoid proxies that rewrite/redirect media requests
- Use native fetch implementations that honor redirect: 'error'
When it happens
Trigger: An intercepting proxy or service mesh silently rewrites the request to a different origin; a runtime whose fetch implementation follows redirects despite redirect: 'error'; an HTTP/2 server responding from a redirected location.
Common situations: Corporate proxies, local dev proxies (e.g. mitmproxy), or PaaS ingress layers that redirect artifact URLs; polyfilled fetch implementations (node-fetch versions with different redirect semantics) that follow redirects before the option is honored.
Related errors
- The CCR artifact request failed.
- HTTP + response.status + from CCR remote sync
- Artifact URL contains an invalid access token.
- The CCR artifact endpoint returned HTTP ${response.status}.
- The CCR artifact endpoint returned a non-media content type.
AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27).
Data as JSON: /api/errors/03a1d2ddac5f1344.
Report an issue: GitHub.