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
@@ -478,7 +478,8 @@ export async function handleRequest(
try {
const body = await req.json();
const sessionId = crypto.randomUUID();
return handleAnthropicMessages(body, proxyPool!, sessionPool!, sessionId);
const anthropicVersion = req.headers.get("anthropic-version") ?? undefined;
return handleAnthropicMessages(body, proxyPool!, sessionPool!, sessionId, undefined, anthropicVersion);
} catch {
return new Response(
JSON.stringify({