fix(provider): support unversioned API roots in model fetch

This commit is contained in:
zhefox
2026-05-26 15:39:56 +08:00
parent c4927162b7
commit d28a389a93
11 changed files with 525 additions and 41 deletions
@@ -3,9 +3,11 @@ import { describe, expect, it } from 'vitest'
import { getDefaultEndpointPath } from '../endpoint-default-paths'
const apiFormats = [
{ value: 'openai:chat', default_path: '/v1/chat/completions' },
{ value: 'gemini:generate_content', default_path: '/v1beta/models/{model}:{action}' },
{ value: 'gemini:embedding', default_path: '/v1beta/models/{model}:{action}' },
{ value: 'openai:responses', default_path: '/v1/responses' },
{ value: 'openai:embedding', default_path: '/v1/embeddings' },
]
describe('endpoint default paths', () => {
@@ -44,4 +46,20 @@ describe('endpoint default paths', () => {
apiFormats,
})).toBe('/responses')
})
it('drops /v1 from OpenAI-compatible defaults when base URL ends with /api', () => {
expect(getDefaultEndpointPath({
apiFormat: 'openai:chat',
providerType: 'custom',
baseUrl: 'https://proxy.example.com/api',
apiFormats,
})).toBe('/chat/completions')
expect(getDefaultEndpointPath({
apiFormat: 'openai:embedding',
providerType: 'custom',
baseUrl: 'https://proxy.example.com/api?tenant=demo',
apiFormats,
})).toBe('/embeddings')
})
})