siyuan-note/siyuan · error
provider not found
Error message
provider not found
What it means
resolveAIProvider scans model.Conf.AI.Providers for a provider whose ID matches request.Provider and returns this error when none matches. It is thrown because AI endpoints (chat, test model, list models) require an existing configured provider entry. An empty or misspelled provider ID never resolves.
Solutions
- List configured providers (GET /api/ai/getProvider or inspect conf) and pass one existing provider.ID
- Re-add the missing provider in 设置 - AI with the expected ID
- Fix the client/request to send request.Provider instead of a hardcoded stale ID
Example fix
// before
body := {"provider": "openai-old"}
// after
// fetch providers first, use an existing ID
body := {"provider": providers[0].id} Defensive patterns
Strategy: validation
Validate before calling
const conf = await fetchPost('/api/setting/getConf');
const ok = conf.data.conf.ai.providers.some(p => p && p.id === providerId);
if (!ok) throw new Error(`unknown provider: ${providerId}`); Try / catch
try { await aiChat({provider}) } catch (e) { if (e.msg === 'provider not found') await reloadAIConfig(); } Prevention
- Always fetch the current provider list before referencing a provider ID
- Never hardcode provider IDs in clients
- After renaming/deleting a provider in settings, update saved consumers
When it happens
Trigger: Calling the AI chat/test-model/list-models API with req.Provider set to an ID that is absent from the workspace config's AI.Providers list (or nil entries only).
Common situations: Client still uses a provider ID that was deleted or renamed in settings; config copied from another workspace without the AI section; typo in the ID; tests passing a draft provider ID that was never persisted.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- invalid provider config
- provider base URL is required
- A public HTTPS OIDC redirect URL is required for remote…
- AI configuration is unavailable
- AI editor action must not be empty
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/5f3d92f4bc66a73d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/api/ai.go:88
}
if err = util.ValidateAIProviderHeaders(provider.Headers); err != nil {
return nil, err
}
ai := &conf.AI{Providers: []*conf.Provider{provider}}
ai.Normalize()
if len(ai.Providers) != 1 {
return nil, errors.New("invalid provider config")
}
return ai.Providers[0], nil
}
providerID := request.Provider
for _, provider := range model.Conf.AI.Providers {
if provider != nil && provider.ID == providerID {
return provider, nil
}
}
return nil, errors.New("provider not found")
}
var chatGPT = contractHandler(apicontract.AIChatGPT, chatGPTContract)
func chatGPTContract(c *gin.Context, req apicontract.AIMessageRequest) apicontract.Response[string] {
return apicontract.Success(model.ChatGPT(req.Msg))
}
var chatGPTWithAction = contractHandler(apicontract.AIChatGPTWithAction, chatGPTWithActionContract)
func chatGPTWithActionContract(c *gin.Context, req apicontract.AIActionRequest) apicontract.Response[string] {
return apicontract.Success(model.ChatGPTWithAction(req.IDs, req.Action))
}
var aiEditorChat = contractHandler(apicontract.AIEditorChat, aiEditorChatContract, aiProviderAdmission)
View on GitHub (pinned to 9f775e8a12)