{"record":{"id":"8ab62e0988c07964","repo":"Tencent/WeKnora","slug":"api-key-is-required-for-ollama-provider","errorCode":null,"errorMessage":"API key is required for Ollama provider","messagePattern":"API key is required for Ollama provider","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/web_search_provider.go","lineNumber":169,"sourceCode":"\tswitch provider {\n\tcase types.WebSearchProviderTypeBing:\n\t\tif params.APIKey == \"\" {\n\t\t\treturn fmt.Errorf(\"API key is required for Bing provider\")\n\t\t}\n\tcase types.WebSearchProviderTypeGoogle:\n\t\tif params.APIKey == \"\" {\n\t\t\treturn fmt.Errorf(\"API key is required for Google provider\")\n\t\t}\n\t\tif params.EngineID == \"\" {\n\t\t\treturn fmt.Errorf(\"engine ID is required for Google provider\")\n\t\t}\n\tcase types.WebSearchProviderTypeTavily:\n\t\tif params.APIKey == \"\" {\n\t\t\treturn fmt.Errorf(\"API key is required for Tavily provider\")\n\t\t}\n\tcase types.WebSearchProviderTypeOllama:\n\t\tif params.APIKey == \"\" {\n\t\t\treturn fmt.Errorf(\"API key is required for Ollama provider\")\n\t\t}\n\tcase types.WebSearchProviderTypeBaidu:\n\t\tif params.APIKey == \"\" {\n\t\t\treturn fmt.Errorf(\"API key is required for Baidu provider\")\n\t\t}\n\tcase types.WebSearchProviderTypeExa:\n\t\tif params.APIKey == \"\" {\n\t\t\treturn fmt.Errorf(\"API key is required for Exa provider\")\n\t\t}\n\tcase types.WebSearchProviderTypeZhipu:\n\t\tif err := infra_web_search.ValidateZhipuParameters(params); err != nil {\n\t\t\treturn err\n\t\t}\n\tcase types.WebSearchProviderTypeMetaso:\n\t\tif err := infra_web_search.ValidateMetasoParameters(params); err != nil {\n\t\t\treturn err\n\t\t}\n\tcase types.WebSearchProviderTypeDuckDuckGo:","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/web_search_provider.go#L151-L187","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nprovider := &types.WebSearchProvider{Type: types.WebSearchProviderTypeOllama} // APIKey missing\nsvc.CreateProvider(ctx, provider)\n// after\nprovider := &types.WebSearchProvider{Type: types.WebSearchProviderTypeOllama, APIKey: \"ollama-local\"}\nsvc.CreateProvider(ctx, provider)","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(provider.APIKey) == \"\" {\n\treturn errors.New(\"ollama provider requires a non-empty API key\")\n}","typeGuard":null,"tryCatchPattern":"if err := svc.CreateProvider(ctx, p); err != nil {\n\tif strings.Contains(err.Error(), \"API key is required\") {\n\t\t// surface a field-level error on the apiKey input\n\t}\n\treturn err\n}","preventionTips":["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."],"tags":["validation","web-search","api-key","config"],"backgroundTag":"missing-api-key","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}