Tencent/WeKnora · error
API key is required for Zhipu provider
Error message
API key is required for Zhipu provider
What it means
Configuration validation for the Zhipu web search provider fails when the APIKey parameter is empty or whitespace-only. ValidateZhipuParameters is called at provider construction (NewZhipuProvider), so this fails fast at startup rather than at search time.
Source
Thrown at internal/infrastructure/web_search/zhipu.go:73
}
client, err := NewSearchHTTPClient(defaultZhipuTimeout, params.ProxyURL)
if err != nil {
return nil, err
}
searchEngine, contentSize := zhipuOptions(params.ExtraConfig)
return &ZhipuProvider{
client: client,
baseURL: defaultZhipuSearchURL,
apiKey: strings.TrimSpace(params.APIKey),
searchEngine: searchEngine,
contentSize: contentSize,
}, nil
}
// ValidateZhipuParameters validates credentials and provider-specific options.
func ValidateZhipuParameters(params types.WebSearchProviderParameters) error {
if strings.TrimSpace(params.APIKey) == "" {
return fmt.Errorf("API key is required for Zhipu provider")
}
searchEngine, contentSize := zhipuOptions(params.ExtraConfig)
if _, ok := validZhipuSearchEngines[searchEngine]; !ok {
return fmt.Errorf("invalid Zhipu search engine: %s", searchEngine)
}
if _, ok := validZhipuContentSizes[contentSize]; !ok {
return fmt.Errorf("invalid Zhipu content size: %s", contentSize)
}
return nil
}
func zhipuOptions(extraConfig map[string]string) (searchEngine, contentSize string) {
searchEngine = defaultZhipuSearchEngine
contentSize = defaultZhipuContentSize
if value := strings.TrimSpace(extraConfig["search_engine"]); value != "" {
searchEngine = value
}
if value := strings.TrimSpace(extraConfig["content_size"]); value != "" {View on GitHub (pinned to 988cbb0330)
Solutions
- Set the API key in the provider parameters before calling NewZhipuProvider.
- Load the key from the correct env var or config path and confirm it is actually read (log length, not the value).
- Trim whitespace and re-validate; strings.TrimSpace must yield a non-empty string.
- Verify the deployment/CI environment injects the secret correctly.
Example fix
// before
provider, err := NewZhipuProvider(types.WebSearchProviderParameters{ExtraConfig: cfg})
// after
provider, err := NewZhipuProvider(types.WebSearchProviderParameters{
APIKey: os.Getenv("ZHIPU_API_KEY"),
ExtraConfig: cfg,
}) Defensive patterns
Strategy: validation
Validate before calling
func validateZhipuConfig(p types.WebSearchProviderParameters) error {
if strings.TrimSpace(p.APIKey) == "" {
return errors.New("zhipu API key missing; set ZHIPU_API_KEY")
}
return nil
}
// call before NewZhipuProvider Type guard
func hasZhipuKey(p types.WebSearchProviderParameters) bool {
return strings.TrimSpace(p.APIKey) != ""
} Try / catch
provider, err := NewZhipuProvider(params)
if err != nil {
if strings.Contains(err.Error(), "API key is required") {
return fmt.Errorf("startup failed: set ZHIPU_API_KEY env var (%w)", err)
}
return err
} Prevention
- Load the API key from a secret manager or env at startup
- Fail fast with a clear message when the key is absent
- Check that deployment/CI actually injects the secret
- Never pass the key inline in code or commit it
When it happens
Trigger: Constructing a Zhipu provider via NewZhipuProvider (or calling ValidateZhipuParameters directly) with types.WebSearchProviderParameters.APIKey unset, empty, or containing only whitespace.
Common situations: Missing ZHIPU_API_KEY env var, config file lacking the api-key field, environment variable not propagated into the container/deployment, or passing credentials under the wrong config key.
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
- invalid Zhipu search engine: %s
- invalid Zhipu content size: %s
- invalid sandbox type
- timeout cannot be negative
- memory limit cannot be negative
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/b425b05604f5b5a2.
Report an issue: GitHub.