@@ -23,7 +23,7 @@ describe('instantiate client', () => {
2323 const client = new Anthropic ( {
2424 baseURL : 'http://localhost:5000/' ,
2525 defaultHeaders : { 'X-My-Default-Header' : '2' } ,
26- apiKey : 'my api key' ,
26+ apiKey : 'my-anthropic- api- key' ,
2727 } ) ;
2828
2929 test ( 'they are used in the request' , ( ) => {
@@ -55,7 +55,7 @@ describe('instantiate client', () => {
5555 const client = new Anthropic ( {
5656 baseURL : 'http://localhost:5000/' ,
5757 defaultQuery : { apiVersion : 'foo' } ,
58- apiKey : 'my api key' ,
58+ apiKey : 'my-anthropic- api- key' ,
5959 } ) ;
6060 expect ( client . buildURL ( '/foo' , null ) ) . toEqual ( 'http://localhost:5000/foo?apiVersion=foo' ) ;
6161 } ) ;
@@ -64,7 +64,7 @@ describe('instantiate client', () => {
6464 const client = new Anthropic ( {
6565 baseURL : 'http://localhost:5000/' ,
6666 defaultQuery : { apiVersion : 'foo' , hello : 'world' } ,
67- apiKey : 'my api key' ,
67+ apiKey : 'my-anthropic- api- key' ,
6868 } ) ;
6969 expect ( client . buildURL ( '/foo' , null ) ) . toEqual ( 'http://localhost:5000/foo?apiVersion=foo&hello=world' ) ;
7070 } ) ;
@@ -73,7 +73,7 @@ describe('instantiate client', () => {
7373 const client = new Anthropic ( {
7474 baseURL : 'http://localhost:5000/' ,
7575 defaultQuery : { hello : 'world' } ,
76- apiKey : 'my api key' ,
76+ apiKey : 'my-anthropic- api- key' ,
7777 } ) ;
7878 expect ( client . buildURL ( '/foo' , { hello : undefined } ) ) . toEqual ( 'http://localhost:5000/foo' ) ;
7979 } ) ;
@@ -82,7 +82,7 @@ describe('instantiate client', () => {
8282 test ( 'custom fetch' , async ( ) => {
8383 const client = new Anthropic ( {
8484 baseURL : 'http://localhost:5000/' ,
85- apiKey : 'my api key' ,
85+ apiKey : 'my-anthropic- api- key' ,
8686 fetch : ( url ) => {
8787 return Promise . resolve (
8888 new Response ( JSON . stringify ( { url, custom : true } ) , {
@@ -99,7 +99,7 @@ describe('instantiate client', () => {
9999 test ( 'custom signal' , async ( ) => {
100100 const client = new Anthropic ( {
101101 baseURL : process . env [ 'TEST_API_BASE_URL' ] ?? 'http://127.0.0.1:4010' ,
102- apiKey : 'my api key' ,
102+ apiKey : 'my-anthropic- api- key' ,
103103 fetch : ( ...args ) => {
104104 return new Promise ( ( resolve , reject ) =>
105105 setTimeout (
@@ -124,56 +124,48 @@ describe('instantiate client', () => {
124124
125125 describe ( 'baseUrl' , ( ) => {
126126 test ( 'trailing slash' , ( ) => {
127- const client = new Anthropic ( { baseURL : 'http://localhost:5000/custom/path/' , apiKey : 'my api key' } ) ;
127+ const client = new Anthropic ( {
128+ baseURL : 'http://localhost:5000/custom/path/' ,
129+ apiKey : 'my-anthropic-api-key' ,
130+ } ) ;
128131 expect ( client . buildURL ( '/foo' , null ) ) . toEqual ( 'http://localhost:5000/custom/path/foo' ) ;
129132 } ) ;
130133
131134 test ( 'no trailing slash' , ( ) => {
132- const client = new Anthropic ( { baseURL : 'http://localhost:5000/custom/path' , apiKey : 'my api key' } ) ;
135+ const client = new Anthropic ( {
136+ baseURL : 'http://localhost:5000/custom/path' ,
137+ apiKey : 'my-anthropic-api-key' ,
138+ } ) ;
133139 expect ( client . buildURL ( '/foo' , null ) ) . toEqual ( 'http://localhost:5000/custom/path/foo' ) ;
134140 } ) ;
135141 } ) ;
136142
137143 test ( 'maxRetries option is correctly set' , ( ) => {
138- const client = new Anthropic ( { maxRetries : 1 , apiKey : 'my api key' } ) ;
144+ const client = new Anthropic ( { maxRetries : 1 , apiKey : 'my-anthropic- api- key' } ) ;
139145 expect ( client . maxRetries ) . toEqual ( 1 ) ;
140146
141147 // default
142- const client2 = new Anthropic ( { apiKey : 'my api key' } ) ;
148+ const client2 = new Anthropic ( { apiKey : 'my-anthropic- api- key' } ) ;
143149 expect ( client2 . maxRetries ) . toEqual ( 2 ) ;
144150 } ) ;
145151
146- test ( 'with minimal arguments' , ( ) => {
147- // set API Key via env var
148- process . env [ 'ANTHROPIC_API_KEY' ] = 'env var api key' ;
152+ test ( 'with environment variable arguments' , ( ) => {
153+ // set options via env var
154+ process . env [ 'ANTHROPIC_API_KEY' ] = 'my-anthropic- api- key' ;
149155 const client = new Anthropic ( ) ;
150- expect ( client . apiKey ) . toBe ( 'env var api key' ) ;
151- } ) ;
152-
153- test ( 'with apiKey argument' , ( ) => {
154- process . env [ 'ANTHROPIC_API_KEY' ] = 'env var api key' ;
155-
156- const client = new Anthropic ( { apiKey : 'another api key' } ) ;
157- expect ( client . apiKey ) . toBe ( 'another api key' ) ;
158- } ) ;
159-
160- test ( 'with options argument' , ( ) => {
161- process . env [ 'ANTHROPIC_API_KEY' ] = 'env var api key' ;
162-
163- // apiKey and custom options
164- const client = new Anthropic ( { apiKey : 'my api key' , authToken : 'my-auth-token' } ) ;
165- expect ( client . apiKey ) . toBe ( 'my api key' ) ;
156+ expect ( client . apiKey ) . toBe ( 'my-anthropic-api-key' ) ;
166157 } ) ;
167158
168- test ( 'with disabled authentication' , ( ) => {
169- process . env [ 'ANTHROPIC_API_KEY' ] = 'env var api key' ;
170- const client = new Anthropic ( { apiKey : null , authToken : 'my-auth-token' } ) ;
171- expect ( client . apiKey ) . toBeNull ( ) ;
159+ test ( 'with overriden environment variable arguments' , ( ) => {
160+ // set options via env var
161+ process . env [ 'ANTHROPIC_API_KEY' ] = 'another my-anthropic-api-key' ;
162+ const client = new Anthropic ( { apiKey : 'my-anthropic-api-key' } ) ;
163+ expect ( client . apiKey ) . toBe ( 'my-anthropic-api-key' ) ;
172164 } ) ;
173165} ) ;
174166
175167describe ( 'request building' , ( ) => {
176- const client = new Anthropic ( { apiKey : 'my api key' } ) ;
168+ const client = new Anthropic ( { apiKey : 'my-anthropic- api- key' } ) ;
177169
178170 describe ( 'Content-Length' , ( ) => {
179171 test ( 'handles multi-byte characters' , ( ) => {
@@ -199,7 +191,7 @@ describe('retries', () => {
199191 return new Response ( JSON . stringify ( { a : 1 } ) , { headers : { 'Content-Type' : 'application/json' } } ) ;
200192 } ;
201193
202- const client = new Anthropic ( { apiKey : 'my api key' , timeout : 2000 , fetch : testFetch } ) ;
194+ const client = new Anthropic ( { apiKey : 'my-anthropic- api- key' , timeout : 2000 , fetch : testFetch } ) ;
203195
204196 expect ( await client . request ( { path : '/foo' , method : 'get' } ) ) . toEqual ( { a : 1 } ) ;
205197 expect ( count ) . toEqual ( 2 ) ;
0 commit comments