🐛 fix(api): Fix the issue where custom AI Providers cannot use custom APIs (#11335)

* 🐛 fix(api): use provider instead of sdkType for API endpoints

Fixed custom AI Provider functionality by correcting API endpoint construction.
Previously used sdkType/runtimeProvider (e.g., 'azure', 'openai') as the API path,
causing server to query wrong provider configuration from database.

Now correctly uses the original provider identifier, allowing custom providers
to work with server-side APIs.

Changes:
- chat/index.ts: use provider for chat API endpoint
- models.ts: use provider for models and modelPull API endpoints

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

*  test(models): update test to match API endpoint fix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Hardy
2026-01-09 00:43:02 +08:00
committed by GitHub
parent 504b9d0aaa
commit 2c666b8723
3 changed files with 5 additions and 4 deletions

View File

@@ -82,7 +82,8 @@ describe('ModelsService', () => {
await modelsService.getModels('custom-provider');
expect(mockedResolveRuntimeProvider).toHaveBeenCalledWith('custom-provider');
expect(fetch).toHaveBeenCalledWith('/webapi/models/openai', { headers: {} });
// API endpoint uses original provider, allowing server to query correct config
expect(fetch).toHaveBeenCalledWith('/webapi/models/custom-provider', { headers: {} });
expect(mockedInitializeWithClientStore).not.toHaveBeenCalled();
});

View File

@@ -402,7 +402,7 @@ class ChatService {
responseAnimation,
].reduce((acc, cur) => merge(acc, standardizeAnimationStyle(cur)), {});
return fetchSSE(API_ENDPOINTS.chat(sdkType), {
return fetchSSE(API_ENDPOINTS.chat(provider), {
body: JSON.stringify(payload),
fetcher: fetcher,
headers,

View File

@@ -49,7 +49,7 @@ export class ModelsService {
return agentRuntime.models();
}
const res = await fetch(API_ENDPOINTS.models(runtimeProvider), { headers });
const res = await fetch(API_ENDPOINTS.models(provider), { headers });
if (!res.ok) return;
return res.json();
@@ -87,7 +87,7 @@ export class ModelsService {
});
res = (await agentRuntime.pullModel({ model }, { signal }))!;
} else {
res = await fetch(API_ENDPOINTS.modelPull(runtimeProvider), {
res = await fetch(API_ENDPOINTS.modelPull(provider), {
body: JSON.stringify({ model }),
headers,
method: 'POST',