Tencent/WeKnora · error
API key is required for Tavily provider
Error message
API key is required for Tavily provider
What it means
NewTavilyProvider requires a Tavily API key in params.APIKey; Tavily's search API is authenticated and there is no anonymous mode. The constructor fails fast rather than letting every Search call later fail with an HTTP 401.
Source
Thrown at internal/infrastructure/web_search/tavily.go:37
// Not configurable by tenants — prevents SSRF.
defaultTavilySearchURL = "https://api.tavily.com/search"
)
var (
defaultTavilyTimeout = 15 * time.Second
)
// TavilyProvider implements web search using Tavily Search API
type TavilyProvider struct {
client *http.Client
baseURL string
apiKey string
}
// NewTavilyProvider creates a new Tavily provider from parameters (no environment variables).
func NewTavilyProvider(params types.WebSearchProviderParameters) (interfaces.WebSearchProvider, error) {
if params.APIKey == "" {
return nil, fmt.Errorf("API key is required for Tavily provider")
}
client, err := NewSearchHTTPClient(defaultTavilyTimeout, params.ProxyURL)
if err != nil {
return nil, err
}
return &TavilyProvider{
client: client,
baseURL: defaultTavilySearchURL,
apiKey: params.APIKey,
}, nil
}
// Name returns the provider name
func (p *TavilyProvider) Name() string {
return "tavily"
}
// Search performs a web search using Tavily Search APIView on GitHub (pinned to 988cbb0330)
Solutions
- Set the API key in the parameters: params.APIKey = os.Getenv("TAVILY_API_KEY") or the tenant config value
- Verify the deployment env/config actually carries the key (kubectl describe pod / docker inspect / .env)
- Fix the config-loading path that builds WebSearchProviderParameters so the key field is populated
- Validate key presence at startup and fail configuration load early with a clear message
Example fix
// before
provider, err := NewTavilyProvider(types.WebSearchProviderParameters{ProxyURL: proxy})
// after
provider, err := NewTavilyProvider(types.WebSearchProviderParameters{
APIKey: os.Getenv("TAVILY_API_KEY"),
ProxyURL: proxy,
}) Defensive patterns
Strategy: validation
Validate before calling
if os.Getenv("TAVILY_API_KEY") == "" {
return fmt.Errorf("TAVILY_API_KEY must be set before constructing the Tavily provider")
} Prevention
- Fail fast at startup when required credentials are absent
- Keep API keys in a secrets manager and inject them into the environment
- Validate WebSearchProviderParameters before constructing providers
When it happens
Trigger: Calling NewTavilyProvider(types.WebSearchProviderParameters{ProxyURL: ...}) without setting APIKey — e.g. tenant config missing the key, env var not loaded into the parameters struct, or a provider-type mismatch sending Tavily params without a key.
Common situations: TAVILY_API_KEY not set in the deployment environment and never copied into WebSearchProviderParameters; config file with an empty api_key field; rotating keys and temporarily blanking the value.
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
- E2BAPIKey is required for the E2B backend
- API key is required for Ollama provider
- API key is required for Exa provider
- API key is required for Metaso provider
- failed to create request: %w
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/fc61a405c77dad7f.
Report an issue: GitHub.