@@ -345,6 +345,16 @@ describe('chat()', () => {
345345 expect ( headers [ 'Authorization' ] ) . toBe ( 'Bearer sk-test-key' ) ;
346346 } ) ;
347347
348+ it ( 'uses v1/chat/completions when baseUrl has no version suffix' , async ( ) => {
349+ const mockFetch = vi . fn ( ) . mockResolvedValueOnce ( makeOpenAIResponse ( 'ok' ) ) ;
350+ globalThis . fetch = mockFetch ;
351+
352+ await chat ( MOCK_MESSAGES , [ ] , MOCK_OPENAI_CONFIG ) ;
353+
354+ const headers = mockFetch . mock . calls [ 0 ] [ 1 ] . headers as Record < string , string > ;
355+ expect ( headers [ 'X-LLM-Target-URL' ] ) . toBe ( 'https://api.openai.com/v1/chat/completions' ) ;
356+ } ) ;
357+
348358 it ( 'includes tools in body when tools array is non-empty' , async ( ) => {
349359 const mockFetch = vi . fn ( ) . mockResolvedValueOnce ( makeOpenAIResponse ( 'ok' ) ) ;
350360 globalThis . fetch = mockFetch ;
@@ -421,6 +431,20 @@ describe('chat()', () => {
421431 expect ( headers [ 'x-api-key' ] ) . toBe ( 'ant-test-key' ) ;
422432 } ) ;
423433
434+ it ( 'uses /messages when baseUrl already includes /v1' , async ( ) => {
435+ const mockFetch = vi . fn ( ) . mockResolvedValueOnce ( makeAnthropicResponse ( 'Anthropic response' ) ) ;
436+ globalThis . fetch = mockFetch ;
437+
438+ const configWithVersion : LLMConfig = {
439+ ...MOCK_ANTHROPIC_CONFIG ,
440+ baseUrl : 'https://api.anthropic.com/v1' ,
441+ } ;
442+ await chat ( MOCK_MESSAGES , [ ] , configWithVersion ) ;
443+
444+ const headers = mockFetch . mock . calls [ 0 ] [ 1 ] . headers as Record < string , string > ;
445+ expect ( headers [ 'X-LLM-Target-URL' ] ) . toBe ( 'https://api.anthropic.com/v1/messages' ) ;
446+ } ) ;
447+
424448 it ( 'extracts system message to top-level system field' , async ( ) => {
425449 const messages : ChatMessage [ ] = [
426450 { role : 'system' , content : 'You are helpful.' } ,
0 commit comments