@@ -196,12 +196,9 @@ void dynamicApiKeyRestClient() throws InterruptedException {
196
196
197
197
@ Test
198
198
void dynamicApiKeyRestClientWithAdditionalApiKeyHeader () throws InterruptedException {
199
- AnthropicApi api = AnthropicApi .builder ()
200
- .apiKey (() -> {
201
- throw new AssertionFailedError ("Should not be called, API key is provided in headers" );
202
- })
203
- .baseUrl (mockWebServer .url ("/" ).toString ())
204
- .build ();
199
+ AnthropicApi api = AnthropicApi .builder ().apiKey (() -> {
200
+ throw new AssertionFailedError ("Should not be called, API key is provided in headers" );
201
+ }).baseUrl (mockWebServer .url ("/" ).toString ()).build ();
205
202
206
203
MockResponse mockResponse = new MockResponse ().setResponseCode (200 )
207
204
.addHeader (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE )
@@ -231,7 +228,8 @@ void dynamicApiKeyRestClientWithAdditionalApiKeyHeader() throws InterruptedExcep
231
228
.build ();
232
229
MultiValueMap <String , String > additionalHeaders = new LinkedMultiValueMap <>();
233
230
additionalHeaders .add ("x-api-key" , "additional-key" );
234
- ResponseEntity <AnthropicApi .ChatCompletionResponse > response = api .chatCompletionEntity (request , additionalHeaders );
231
+ ResponseEntity <AnthropicApi .ChatCompletionResponse > response = api .chatCompletionEntity (request ,
232
+ additionalHeaders );
235
233
assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .OK );
236
234
RecordedRequest recordedRequest = mockWebServer .takeRequest ();
237
235
assertThat (recordedRequest .getHeader (HttpHeaders .AUTHORIZATION )).isNull ();
@@ -248,8 +246,7 @@ void dynamicApiKeyWebClient() throws InterruptedException {
248
246
249
247
MockResponse mockResponse = new MockResponse ().setResponseCode (200 )
250
248
.addHeader (HttpHeaders .CONTENT_TYPE , MediaType .TEXT_EVENT_STREAM_VALUE )
251
- .setBody (
252
- """
249
+ .setBody ("""
253
250
{
254
251
"type": "message_start",
255
252
"message": {
@@ -278,9 +275,7 @@ void dynamicApiKeyWebClient() throws InterruptedException {
278
275
.messages (List .of (chatCompletionMessage ))
279
276
.stream (true )
280
277
.build ();
281
- api .chatCompletionStream (request )
282
- .collectList ()
283
- .block ();
278
+ api .chatCompletionStream (request ).collectList ().block ();
284
279
RecordedRequest recordedRequest = mockWebServer .takeRequest ();
285
280
assertThat (recordedRequest .getHeader (HttpHeaders .AUTHORIZATION )).isNull ();
286
281
assertThat (recordedRequest .getHeader ("x-api-key" )).isEqualTo ("key1" );
@@ -301,26 +296,25 @@ void dynamicApiKeyWebClientWithAdditionalApiKey() throws InterruptedException {
301
296
.build ();
302
297
303
298
MockResponse mockResponse = new MockResponse ().setResponseCode (200 )
304
- .addHeader (HttpHeaders .CONTENT_TYPE , MediaType .TEXT_EVENT_STREAM_VALUE )
305
- .setBody (
306
- """
307
- {
308
- "type": "message_start",
309
- "message": {
310
- "id": "msg_1nZdL29xx5MUA1yADyHTEsnR8uuvGzszyY",
311
- "type": "message",
312
- "role": "assistant",
313
- "content": [],
314
- "model": "claude-opus-4-20250514",
315
- "stop_reason": null,
316
- "stop_sequence": null,
317
- "usage": {
318
- "input_tokens": 25,
319
- "output_tokens": 1
320
- }
299
+ .addHeader (HttpHeaders .CONTENT_TYPE , MediaType .TEXT_EVENT_STREAM_VALUE )
300
+ .setBody ("""
301
+ {
302
+ "type": "message_start",
303
+ "message": {
304
+ "id": "msg_1nZdL29xx5MUA1yADyHTEsnR8uuvGzszyY",
305
+ "type": "message",
306
+ "role": "assistant",
307
+ "content": [],
308
+ "model": "claude-opus-4-20250514",
309
+ "stop_reason": null,
310
+ "stop_sequence": null,
311
+ "usage": {
312
+ "input_tokens": 25,
313
+ "output_tokens": 1
321
314
}
322
315
}
323
- """ .replace ("\n " , "" ));
316
+ }
317
+ """ .replace ("\n " , "" ));
324
318
mockWebServer .enqueue (mockResponse );
325
319
326
320
AnthropicApi .AnthropicMessage chatCompletionMessage = new AnthropicApi .AnthropicMessage (
@@ -334,9 +328,7 @@ void dynamicApiKeyWebClientWithAdditionalApiKey() throws InterruptedException {
334
328
MultiValueMap <String , String > additionalHeaders = new LinkedMultiValueMap <>();
335
329
additionalHeaders .add ("x-api-key" , "additional-key" );
336
330
337
- api .chatCompletionStream (request , additionalHeaders )
338
- .collectList ()
339
- .block ();
331
+ api .chatCompletionStream (request , additionalHeaders ).collectList ().block ();
340
332
RecordedRequest recordedRequest = mockWebServer .takeRequest ();
341
333
assertThat (recordedRequest .getHeader (HttpHeaders .AUTHORIZATION )).isNull ();
342
334
assertThat (recordedRequest .getHeader ("x-api-key" )).isEqualTo ("additional-key" );
0 commit comments