{"record":{"id":"77adf801ee380e00","repo":"Tencent/WeKnora","slug":"api-key-is-required-for-baidu-provider","errorCode":null,"errorMessage":"API key is required for Baidu provider","messagePattern":"API key is required for Baidu provider","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/web_search_provider.go","lineNumber":173,"sourceCode":"\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:\n\t\t// No API key required\n\tcase types.WebSearchProviderTypeKeenable:\n\t\t// No API key required (keyless by default; an optional key lifts the rate limit)\n\tcase types.WebSearchProviderTypeSearxng:","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/web_search_provider.go#L155-L191","documentation":"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.","triggerScenarios":"CreateProvider/UpdateProvider with type 'baidu' and APIKey == \"\"; validation test paths that exercise the Baidu case with no key supplied.","commonSituations":"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.","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."],"exampleFix":"// before\nparams.APIKey = os.Getenv(\"BAIDU_API_KEY\") // unset -> \"\"\n// after\nkey := os.Getenv(\"BAIDU_API_KEY\")\nif key == \"\" { return errors.New(\"BAIDU_API_KEY must be set before creating Baidu provider\") }\nparams.APIKey = key","handlingStrategy":"validation","validationCode":"if provider.Type == types.WebSearchProviderTypeBaidu && strings.TrimSpace(provider.APIKey) == \"\" {\n\treturn errors.New(\"baidu provider requires an API key\")\n}","typeGuard":null,"tryCatchPattern":"if err := svc.UpdateProvider(ctx, id, params); err != nil {\n\tvar ve *ValidationError\n\tif errors.As(err, &ve) { /* show apiKey field error */ }\n\treturn err\n}","preventionTips":["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."],"tags":["validation","web-search","api-key","baidu"],"backgroundTag":"missing-api-key","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}