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 <dallinromney@gmail.com>
This commit is contained in:
Sreeram 2026-03-24 20:10:54 -05:00 • committed by GitHub
parent 6e0045e204
commit fd559bbc8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View file

@ -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", () => {

View file

@ -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<string, string> = {
"Content-Type": "application/json",