From fd559bbc8eae6103707177028c99583124e74482 Mon Sep 17 00:00:00 2001 From: Sreeram Date: Tue, 24 Mar 2026 20:10:54 -0500 Subject: [PATCH] Sending x-api-key instead of api-key as header for azure hosted anthropic service (#11517) * Fix for sending x-api-key instead of api-key as header for newer azure hosted anthropic service * Update packages/openai-adapters/src/apis/AnthropicUtils.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * fix: update test to expect x-api-key for Azure AI Foundry endpoints Azure AI Foundry (services.ai.azure.com) uses x-api-key, while only cognitiveservices.azure.com uses api-key. Update the test to match. --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> Co-authored-by: Dallin Romney --- packages/openai-adapters/src/apis/AnthropicUtils.test.ts | 6 +++--- packages/openai-adapters/src/apis/AnthropicUtils.ts | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/openai-adapters/src/apis/AnthropicUtils.test.ts b/packages/openai-adapters/src/apis/AnthropicUtils.test.ts index 7ed572c80..29e7f79c5 100644 --- a/packages/openai-adapters/src/apis/AnthropicUtils.test.ts +++ b/packages/openai-adapters/src/apis/AnthropicUtils.test.ts @@ -93,14 +93,14 @@ describe("getAnthropicHeaders", () => { expect(headers["api-key"]).toBeUndefined(); }); - it("uses api-key for Azure AI Foundry endpoint", () => { + it("uses x-api-key for Azure AI Foundry endpoint", () => { const headers = getAnthropicHeaders( "azure-key", false, "https://my-resource.services.ai.azure.com/anthropic", ); - expect(headers["api-key"]).toBe("azure-key"); - expect(headers["x-api-key"]).toBeUndefined(); + expect(headers["x-api-key"]).toBe("azure-key"); + expect(headers["api-key"]).toBeUndefined(); }); it("uses api-key for Azure Cognitive Services endpoint", () => { diff --git a/packages/openai-adapters/src/apis/AnthropicUtils.ts b/packages/openai-adapters/src/apis/AnthropicUtils.ts index 46b28e578..4e279a5ea 100644 --- a/packages/openai-adapters/src/apis/AnthropicUtils.ts +++ b/packages/openai-adapters/src/apis/AnthropicUtils.ts @@ -78,7 +78,10 @@ export function getAnthropicHeaders( ); } - const authHeaderName = isAzure ? "api-key" : "x-api-key"; + const authHeaderName = + isAzure && apiBase?.toLowerCase().includes("cognitiveservices.azure.com") + ? "api-key" + : "x-api-key"; const headers: Record = { "Content-Type": "application/json",