Fix : Updated Anthropic-Beta header.

This commit is contained in:
decolua
2026-04-05 07:46:26 +07:00
parent d076c7d7f5
commit 67e0db77da
7 changed files with 143 additions and 27 deletions

View File

@@ -2,6 +2,7 @@
import { DEFAULT_THINKING_CLAUDE_SIGNATURE } from "../../config/defaultThinkingSignature.js";
import { adjustMaxTokens } from "./maxTokensHelper.js";
import { applyCloaking } from "../../utils/claudeCloaking.js";
import { deriveSessionId } from "../../utils/sessionManager.js";
// Check if message has valid non-empty content
export function hasValidContent(msg) {
@@ -81,7 +82,7 @@ export function fixToolUseOrdering(messages) {
// - Add thinking block for Anthropic endpoint (provider === "claude")
// - Fix tool_use/tool_result ordering
// - Apply cloaking (billing header + fake user ID) for OAuth tokens
export function prepareClaudeRequest(body, provider = null, apiKey = null) {
export function prepareClaudeRequest(body, provider = null, apiKey = null, connectionId = null) {
// 1. System: remove all cache_control, add only to last block with ttl 1h
if (body.system && Array.isArray(body.system)) {
body.system = body.system.map((block, i) => {
@@ -196,8 +197,10 @@ export function prepareClaudeRequest(body, provider = null, apiKey = null) {
}
// Apply cloaking for OAuth tokens (billing header + fake user ID)
// session_id in user_id must match X-Claude-Code-Session-Id for fingerprint consistency
if ((provider === "claude" || provider?.startsWith("anthropic-compatible")) && apiKey) {
body = applyCloaking(body, apiKey);
const sessionId = connectionId ? deriveSessionId(connectionId) : null;
body = applyCloaking(body, apiKey, sessionId);
}
return body;

View File

@@ -1,6 +1,7 @@
import { FORMATS } from "./formats.js";
import { ensureToolCallIds, fixMissingToolResponses } from "./helpers/toolCallHelper.js";
import { prepareClaudeRequest } from "./helpers/claudeHelper.js";
import { cloakClaudeTools } from "../utils/claudeCloaking.js";
import { filterToOpenAIFormat } from "./helpers/openaiHelper.js";
import { normalizeThinkingConfig } from "../services/provider.js";
import { AntigravityExecutor } from "../executors/antigravity.js";
@@ -67,7 +68,7 @@ function stripUnsupportedMultimodal(body, multimodal = {}) {
}
// Translate request: source -> openai -> target
export function translateRequest(sourceFormat, targetFormat, model, body, stream = true, credentials = null, provider = null, reqLogger = null, caps = null) {
export function translateRequest(sourceFormat, targetFormat, model, body, stream = true, credentials = null, provider = null, reqLogger = null, caps = null, connectionId = null) {
ensureInitialized();
let result = body;
@@ -122,7 +123,20 @@ export function translateRequest(sourceFormat, targetFormat, model, body, stream
// Final step: prepare request for Claude format endpoints
if (targetFormat === FORMATS.CLAUDE) {
const apiKey = credentials?.accessToken || credentials?.apiKey || null;
result = prepareClaudeRequest(result, provider, apiKey);
result = prepareClaudeRequest(result, provider, apiKey, connectionId);
}
// Claude cloaking: rename client tools with _cc suffix (anti-ban)
// Only for claude provider (not anthropic-compatible-*) with OAuth token
if (provider === "claude") {
const apiKey = credentials?.accessToken || credentials?.apiKey || null;
if (apiKey?.includes("sk-ant-oat")) {
const { body: cloakedBody, toolNameMap } = cloakClaudeTools(result);
result = cloakedBody;
if (toolNameMap?.size > 0) {
result._toolNameMap = toolNameMap;
}
}
}
// Antigravity cloaking: rename client tools + inject decoys (anti-ban)