From 4536205026063eb2d8c9a9037c29a6a5450b51dd Mon Sep 17 00:00:00 2001 From: windmemory Date: Thu, 21 Nov 2024 22:46:04 +0800 Subject: [PATCH] fix anthropic completion endpoint --- src/anthropic/anthropic-proxy.controller.ts | 2 +- src/anthropic/anthropic-proxy.service.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/anthropic/anthropic-proxy.controller.ts b/src/anthropic/anthropic-proxy.controller.ts index bd54ce1..b5b974b 100644 --- a/src/anthropic/anthropic-proxy.controller.ts +++ b/src/anthropic/anthropic-proxy.controller.ts @@ -17,7 +17,7 @@ export class AnthropicProxyController { @Inject() private readonly service: AnthropicProxyService; - @Post('/anthropic/v1/chat/completions') + @Post('/anthropic/v1/messages') @HttpCode(200) async chatCompletion(@Body() body: any, @Headers() headers: any) { const result = await this.service.chatCompletion(body, headers); diff --git a/src/anthropic/anthropic-proxy.service.ts b/src/anthropic/anthropic-proxy.service.ts index a05d3bb..d0eb21a 100644 --- a/src/anthropic/anthropic-proxy.service.ts +++ b/src/anthropic/anthropic-proxy.service.ts @@ -13,7 +13,7 @@ export class AnthropicProxyService { private readonly configService: ConfigService; async chatCompletion(body: any, headers: any) { - const url = 'https://api.anthropic.com/v1/chat/completions'; + const url = 'https://api.anthropic.com/v1/messages'; return this.makeRequest(url, headers, body, body.stream); } @@ -58,8 +58,9 @@ export class AnthropicProxyService { httpsAgent, method: 'POST', headers: { - ...headers, - Host: 'api.anthropic.com', + 'Content-Type': 'application/json', + 'anthropic-version': headers['anthropic-version'], + 'x-api-key': headers['x-api-key'], }, responseType: stream ? 'stream' : 'json', data: body,