Skip to content

Commit 010f7c4

Browse files
committed
only map if body mapping is OPENAI
1 parent 4bf900f commit 010f7c4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/cost/models/providers/anthropic.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,22 @@ export class AnthropicProvider extends BaseProvider {
2323
_modelProviderConfig: ModelProviderConfig,
2424
userConfig: UserEndpointConfig
2525
): string {
26-
if (userConfig.gatewayMapping === "NO_MAPPING") {
27-
return "https://api.anthropic.com/v1/messages";
28-
}
2926
return "https://api.anthropic.com/v1/messages";
3027
}
3128

3229
authenticate(context: AuthContext): AuthResult {
3330
const headers: Record<string, string> = {};
3431
headers["x-api-key"] = context.apiKey || "";
35-
headers["anthropic-version"] = "2023-06-01";
32+
if (context.bodyMapping === "OPENAI") {
33+
headers["anthropic-version"] = "2023-06-01";
34+
} // if NO_MAPPING, then we can assume the header is already added (e.g by anthropic SDK)
3635
return { headers };
3736
}
3837

3938
buildRequestBody(endpoint: Endpoint, context: RequestBodyContext): string {
39+
if (context.bodyMapping === "NO_MAPPING") {
40+
return JSON.stringify(context.parsedBody); // return without mapping
41+
}
4042
const anthropicBody = context.toAnthropic(context.parsedBody);
4143
const updatedBody = {
4244
...anthropicBody,

0 commit comments

Comments
 (0)