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 API

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Set the API key in the parameters: params.APIKey = os.Getenv("TAVILY_API_KEY") or the tenant config value
  2. Verify the deployment env/config actually carries the key (kubectl describe pod / docker inspect / .env)
  3. Fix the config-loading path that builds WebSearchProviderParameters so the key field is populated
  4. 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

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


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/fc61a405c77dad7f. Report an issue: GitHub.