feat: anthropic cache support — preserve cache_control, forward anthropic-version header, report real usage tokens

- Add anthropicPassthrough flag to BackendConfig for native Anthropic backends
- Preserve cache_control on content blocks and system prompt (keep structured)
- Extract and forward anthropic-version header from client to backend
- Report actual token usage from backend response (input_tokens, output_tokens)
- Support native Anthropic passthrough (no translation) for compatible backends
- Wire anthropic-version through all entry points: index.ts, router.ts, worker.ts
This commit is contained in:
MythEclipse
2026-06-20 21:34:31 +07:00
parent ac19f8f30d
commit 7bb1b443be
5 changed files with 180 additions and 38 deletions
+2 -1
View File
@@ -453,7 +453,8 @@ export default {
if (authErr) return authErr;
try {
const body = await req.json();
return handleAnthropicMessages(body);
const anthropicVersion = req.headers.get("anthropic-version") ?? undefined;
return handleAnthropicMessages(body, undefined, undefined, undefined, undefined, anthropicVersion);
} catch {
return new Response(
JSON.stringify({ error: { message: "Invalid JSON body", type: "invalid_request_error" } }),