vxcontrol/pentagi · error · FatalError
failed to create google search service
Error message
failed to create google search service: %w
What it means
google.Handle fails to build the Custom Search JSON API client and wraps the cause in Fatal(fmt.Errorf("failed to create google search service: %w", err)). This is Fatal (not Retryable), so the web_search orchestrator will not retry Google for this query and will move on. The underlying cause is almost always the nested 'failed to create http client' or customsearch.NewService failure.
Solutions
- Read the wrapped cause: if it is 'failed to create http client', fix proxy/TLS settings (HTTPS_PROXY, CA bundle) used by system.GetHTTPClient
- Ensure GOOGLE_API_KEY and GOOGLE_CX_KEY are set — although IsAvailable() guards this, verify the config actually loaded
- If the context is canceled, check upstream cancellation/timeouts rather than Google config
- Retry the flow; since the error is Fatal the orchestrator skips Google, so fix the root cause to restore Google results
Defensive patterns
Strategy: try-catch
Validate before calling
// guard config before calling the engine
if cfg.GoogleAPIKey == "" || cfg.GoogleCXKey == "" {
// engine unavailable (IsAvailable() would return false)
} Try / catch
result, err := googleSearcher.Handle(ctx, req)
if err != nil {
if searchers.IsFatal(err) && strings.Contains(err.Error(), "failed to create google search service") {
log.Errorf("google client init failed: %v", err) // fix proxy/TLS, don't retry
return fallbackSearcher.Handle(ctx, req)
}
return "", err
} Prevention
- Validate GOOGLE_API_KEY/GOOGLE_CX_KEY and proxy env vars at startup
- Smoke-test system.GetHTTPClient during app init and fail fast on bad config
- Avoid canceling contexts passed into Handle before the service is built
When it happens
Trigger: g.newSearchService(ctx) errors: system.GetHTTPClient fails (proxy/TLS config invalid) or customsearch.NewService(ctx, option.WithHTTPClient(client)) fails to initialize the google.golang.org/api service.
Common situations: Invalid HTTPS_PROXY/HTTP_PROXY env vars or bad proxy CA certs on Google API search calls; corrupt google.golang.org/api module options; context already canceled when Handle is invoked.
Related errors
- failed to create google search service
- failed to do request
- google search failed
- could not create Google OpenID client
- could not verify Google ID Token
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/fcb0312fd9d15b99.
Report an issue: GitHub.
Appendix: source
Thrown at backend/pkg/tools/searchers/google.go:57
}
ctx, observation := obs.Observer.NewObservation(ctx)
numResults := int64(req.MaxResults)
if numResults < 1 || numResults > googleMaxResults {
numResults = googleMaxResults
}
logger := logrus.WithContext(ctx).WithFields(logrus.Fields{
"engine": "google",
"query": req.Query[:min(len(req.Query), 1000)],
"num_results": numResults,
})
svc, err := g.newSearchService(ctx)
if err != nil {
logger.WithError(err).Error("failed to create google search service")
return "", Fatal(fmt.Errorf("failed to create google search service: %w", err))
}
result, err := g.search(ctx, svc, req.Query, numResults)
if err != nil {
observation.Event(
langfuse.WithEventName("search engine error"),
langfuse.WithEventInput(req.Query),
langfuse.WithEventStatus(err.Error()),
langfuse.WithEventLevel(langfuse.ObservationLevelWarning),
langfuse.WithEventMetadata(langfuse.Metadata{
"engine": "google",
"query": req.Query,
"max_results": numResults,
"error": err.Error(),
}),
)
obs.LogErrorOrCancel(logger, err, "failed to search in google")View on GitHub (pinned to ea665308ba)