@@ -2,20 +2,16 @@ import { ProviderAPIConfig } from '../types';
22
33const AnthropicAPIConfig : ProviderAPIConfig = {
44 getBaseURL : ( ) => 'https://api.anthropic.com/v1' ,
5- headers : ( { providerOptions, fn, gatewayRequestBody } ) => {
5+ headers : ( { providerOptions, fn, headers : requestHeaders } ) => {
6+ const apiKey =
7+ providerOptions . apiKey || requestHeaders ?. [ 'x-api-key' ] || '' ;
68 const headers : Record < string , string > = {
7- 'X-API-Key' : ` ${ providerOptions . apiKey } ` ,
9+ 'X-API-Key' : apiKey ,
810 } ;
911
10- // Accept anthropic_beta and anthropic_version in body to support enviroments which cannot send it in headers.
1112 const betaHeader =
12- providerOptions ?. [ 'anthropicBeta' ] ??
13- gatewayRequestBody ?. [ 'anthropic_beta' ] ??
14- 'messages-2023-12-15' ;
15- const version =
16- providerOptions ?. [ 'anthropicVersion' ] ??
17- gatewayRequestBody ?. [ 'anthropic_version' ] ??
18- '2023-06-01' ;
13+ providerOptions ?. [ 'anthropicBeta' ] ?? 'messages-2023-12-15' ;
14+ const version = providerOptions ?. [ 'anthropicVersion' ] ?? '2023-06-01' ;
1915
2016 if ( fn === 'chatComplete' ) {
2117 headers [ 'anthropic-beta' ] = betaHeader ;
@@ -31,10 +27,12 @@ const AnthropicAPIConfig: ProviderAPIConfig = {
3127 return '/messages' ;
3228 case 'messages' :
3329 return '/messages' ;
30+ case 'messagesCountTokens' :
31+ return '/messages/count_tokens' ;
3432 default :
3533 return '' ;
3634 }
3735 } ,
3836} ;
3937
40- export default AnthropicAPIConfig ;
38+ export default AnthropicAPIConfig ;
0 commit comments