Tencent/WeKnora · error
API key is required for Baidu provider
Error message
API key is required for Baidu provider
What it means
Same validation gate as the other providers: validateProviderParameters rejects a Baidu web-search provider whose params.APIKey is empty. Baidu's search API is authenticated with an API key, so a provider record cannot be created, updated, or tested without one.
Source
Thrown at internal/application/service/web_search_provider.go:173
}
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:
// No API key required
case types.WebSearchProviderTypeKeenable:
// No API key required (keyless by default; an optional key lifts the rate limit)
case types.WebSearchProviderTypeSearxng:View on GitHub (pinned to 988cbb0330)
Solutions
- Obtain a Baidu API key and populate params.APIKey before calling CreateProvider/UpdateProvider.
- Verify the environment variable or secret backing the key is set in the deployment and mapped to the APIKey field.
- Trim the input; if your client sends whitespace, send the real key.
- If key should be optional for some Baidu mode, adjust the validation case accordingly.
Example fix
// before
params.APIKey = os.Getenv("BAIDU_API_KEY") // unset -> ""
// after
key := os.Getenv("BAIDU_API_KEY")
if key == "" { return errors.New("BAIDU_API_KEY must be set before creating Baidu provider") }
params.APIKey = key Defensive patterns
Strategy: validation
Validate before calling
if provider.Type == types.WebSearchProviderTypeBaidu && strings.TrimSpace(provider.APIKey) == "" {
return errors.New("baidu provider requires an API key")
} Try / catch
if err := svc.UpdateProvider(ctx, id, params); err != nil {
var ve *ValidationError
if errors.As(err, &ve) { /* show apiKey field error */ }
return err
} Prevention
- Store the Baidu key in an env var and check os.Getenv != "" before provider save.
- Map the correct JSON field to APIKey in request DTOs.
- Run the provider's test/validate call after config changes.
- Trim pasted keys to avoid whitespace-only values.
When it happens
Trigger: CreateProvider/UpdateProvider with type 'baidu' and APIKey == ""; validation test paths that exercise the Baidu case with no key supplied.
Common situations: Users register a Baidu provider before obtaining a Baidu API key; the key env var is unset at deploy time and bound as empty string; a migration or import writes a Baidu provider row without credentials.
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 Ollama provider
- API key is required for Exa provider
- API key is required for Metaso provider
- query is empty
- API key is required for Exa provider
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/77adf801ee380e00.
Report an issue: GitHub.