File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -961,14 +961,16 @@ export const ensurePresent = <T>(value: T | null | undefined): T => {
961961/**
962962 * Read an environment variable.
963963 *
964+ * Trims beginning and trailing whitespace.
965+ *
964966 * Will return undefined if the environment variable doesn't exist or cannot be accessed.
965967 */
966968export const readEnv = ( env : string ) : string | undefined => {
967969 if ( typeof process !== 'undefined' ) {
968- return process . env ?. [ env ] ?? undefined ;
970+ return process . env ?. [ env ] ?. trim ( ) ?? undefined ;
969971 }
970972 if ( typeof Deno !== 'undefined' ) {
971- return Deno . env ?. get ?.( env ) ;
973+ return Deno . env ?. get ?.( env ) ?. trim ( ) ;
972974 }
973975 return undefined ;
974976} ;
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ export class Anthropic extends Core.APIClient {
104104 apiKey,
105105 authToken,
106106 ...opts ,
107- baseURL : baseURL ?? `https://api.anthropic.com` ,
107+ baseURL : baseURL || `https://api.anthropic.com` ,
108108 } ;
109109
110110 super ( {
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ describe('instantiate client', () => {
140140 } ) ;
141141
142142 afterEach ( ( ) => {
143- process . env [ 'SINK_BASE_URL ' ] = undefined ;
143+ process . env [ 'ANTHROPIC_BASE_URL ' ] = undefined ;
144144 } ) ;
145145
146146 test ( 'explicit option' , ( ) => {
@@ -153,6 +153,18 @@ describe('instantiate client', () => {
153153 const client = new Anthropic ( { apiKey : 'my-anthropic-api-key' } ) ;
154154 expect ( client . baseURL ) . toEqual ( 'https://example.com/from_env' ) ;
155155 } ) ;
156+
157+ test ( 'empty env variable' , ( ) => {
158+ process . env [ 'ANTHROPIC_BASE_URL' ] = '' ; // empty
159+ const client = new Anthropic ( { apiKey : 'my-anthropic-api-key' } ) ;
160+ expect ( client . baseURL ) . toEqual ( 'https://api.anthropic.com' ) ;
161+ } ) ;
162+
163+ test ( 'blank env variable' , ( ) => {
164+ process . env [ 'ANTHROPIC_BASE_URL' ] = ' ' ; // blank
165+ const client = new Anthropic ( { apiKey : 'my-anthropic-api-key' } ) ;
166+ expect ( client . baseURL ) . toEqual ( 'https://api.anthropic.com' ) ;
167+ } ) ;
156168 } ) ;
157169
158170 test ( 'maxRetries option is correctly set' , ( ) => {
You can’t perform that action at this time.
0 commit comments