Tencent/WeKnora · error
API key is required for Ollama provider
Error message
API key is required for Ollama provider
What it means
validateProviderParameters in the web search provider service enforces that every provider configuration carries a non-empty API key. For the Ollama provider type, an empty params.APIKey causes this error, blocking CreateProvider, UpdateProvider and validation tests. Ollama typically needs no auth, but this codebase requires a key (e.g. a placeholder or proxy token) for uniform config handling.
Source
Thrown at internal/application/service/web_search_provider.go:169
switch provider {
case types.WebSearchProviderTypeBing:
if params.APIKey == "" {
return fmt.Errorf("API key is required for Bing provider")
}
case types.WebSearchProviderTypeGoogle:
if params.APIKey == "" {
return fmt.Errorf("API key is required for Google provider")
}
if params.EngineID == "" {
return fmt.Errorf("engine ID is required for Google provider")
}
case types.WebSearchProviderTypeTavily:
if params.APIKey == "" {
return fmt.Errorf("API key is required for Tavily provider")
}
case types.WebSearchProviderTypeOllama:
if params.APIKey == "" {
return fmt.Errorf("API key is required for Ollama provider")
}
case types.WebSearchProviderTypeBaidu:
if params.APIKey == "" {
return fmt.Errorf("API key is required for Baidu provider")
}
case types.WebSearchProviderTypeExa:
if params.APIKey == "" {
return fmt.Errorf("API key is required for Exa provider")
}
case types.WebSearchProviderTypeZhipu:
if err := infra_web_search.ValidateZhipuParameters(params); err != nil {
return err
}
case types.WebSearchProviderTypeMetaso:
if err := infra_web_search.ValidateMetasoParameters(params); err != nil {
return err
}
case types.WebSearchProviderTypeDuckDuckGo:View on GitHub (pinned to 988cbb0330)
Solutions
- Set a non-empty APIKey in the provider params (for local Ollama any placeholder value satisfies validation, or the token for an authenticated gateway in front of Ollama).
- If Ollama truly should be keyless, change validateProviderParameters to skip the APIKey check for WebSearchProviderTypeOllama.
- Trim/normalize the incoming config so an accidentally whitespace-only key becomes either a valid value or a clear validation message.
- Check that the request body field name matches the expected JSON binding so APIKey is actually populated.
Example fix
// before
provider := &types.WebSearchProvider{Type: types.WebSearchProviderTypeOllama} // APIKey missing
svc.CreateProvider(ctx, provider)
// after
provider := &types.WebSearchProvider{Type: types.WebSearchProviderTypeOllama, APIKey: "ollama-local"}
svc.CreateProvider(ctx, provider) Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(provider.APIKey) == "" {
return errors.New("ollama provider requires a non-empty API key")
} Try / catch
if err := svc.CreateProvider(ctx, p); err != nil {
if strings.Contains(err.Error(), "API key is required") {
// surface a field-level error on the apiKey input
}
return err
} Prevention
- Always set APIKey in provider params, even for keyless backends (use a placeholder).
- Validate the full provider config with the service's validate/test endpoint before persisting.
- Keep secrets in env/secret-manager and assert presence at startup.
- Trim user input so whitespace-only keys don't pass client checks but fail server checks.
When it happens
Trigger: Calling CreateProvider or UpdateProvider with provider type 'ollama' and an empty/whitespace APIKey in params; or running validation tests (TestValidateProviderParametersZhipu/Exa/Metaso paths) that pass an Ollama config without a key.
Common situations: Operators migrate a local Ollama setup that worked without authentication and omit the key field; UI forms leave the API key blank because Ollama is thought to be keyless; config import from another tool drops the field.
Understand the failure class
Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.
Related errors
- API key is required for Metaso provider
- API key is required for Baidu provider
- API key is required for Exa provider
- API key is required for Exa provider
- invalid Metaso search scope: %s
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/8ab62e0988c07964.
Report an issue: GitHub.