{"record":{"id":"59b3d1d32321262b","repo":"Tencent/WeKnora","slug":"api-key-is-required-for-ollama-provider-59b3d1","errorCode":null,"errorMessage":"API key is required for Ollama provider","messagePattern":"API key is required for Ollama provider","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/ollama.go","lineNumber":36,"sourceCode":"\t// defaultOllamaWebSearchURL is the hardcoded Ollama web search API URL.\n\t// Not configurable by tenants — prevents SSRF.\n\tdefaultOllamaWebSearchURL = \"https://ollama.com/api/web_search\"\n\tdefaultOllamaTimeout      = 10 * time.Second\n\tdefaultOllamaResults      = 5\n\tmaxOllamaResults          = 10 // Ollama限制最多10个结果\n)\n\n// OllamaProvider implements web search using Ollama Cloud API\ntype OllamaProvider struct {\n\tclient  *http.Client\n\tbaseURL string\n\tapiKey  string\n}\n\n// NewOllamaProvider creates a new Ollama web search provider from parameters.\nfunc NewOllamaProvider(params types.WebSearchProviderParameters) (interfaces.WebSearchProvider, error) {\n\tif params.APIKey == \"\" {\n\t\treturn nil, fmt.Errorf(\"API key is required for Ollama provider\")\n\t}\n\tclient, err := NewSearchHTTPClient(defaultOllamaTimeout, params.ProxyURL)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create Ollama HTTP client: %w\", err)\n\t}\n\treturn &OllamaProvider{\n\t\tclient:  client,\n\t\tbaseURL: defaultOllamaWebSearchURL, // Hardcoded — not tenant-configurable\n\t\tapiKey:  params.APIKey,\n\t}, nil\n}\n\n// Name returns the provider name\nfunc (p *OllamaProvider) Name() string {\n\treturn \"ollama\"\n}\n\n// Search performs a web search using Ollama Cloud API","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/ollama.go#L18-L54","documentation":"Constructor validation in NewOllamaProvider: params.APIKey is empty, but the Ollama Cloud web search API requires a key. The provider refuses construction, preventing an unauthenticated call to the hardcoded (SSRF-safe) ollama.com endpoint from ever being attempted.","triggerScenarios":"Thrown at internal/infrastructure/web_search/ollama.go:36 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Configure the Ollama API key in the tenant's provider settings","Select another search provider if no Ollama credentials exist"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}