Tencent/WeKnora · error

baidu API returned status %d: %s

Error message

baidu API returned status %d: %s

What it means

Returned by doSearch when the Baidu API responds with a non-200 status; the response body (up to 2MB read limit) is embedded in the message. Typically invalid/expired API key (401), quota exhausted (429), or Baidu-side errors (5xx).

Source

Thrown at internal/infrastructure/web_search/baidu.go:135

	return req, nil
}

func (p *BaiduProvider) doSearch(ctx context.Context, req *http.Request, includeDate bool) ([]*types.WebSearchResult, error) {
	resp, err := p.client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(io.LimitReader(resp.Body, 2<<20)) // 2MB limit
	if err != nil {
		return nil, err
	}

	if resp.StatusCode != http.StatusOK {
		logger.Warnf(ctx, "[WebSearch][Baidu] API returned status %d: %s", resp.StatusCode, string(body))
		return nil, fmt.Errorf("baidu API returned status %d: %s", resp.StatusCode, string(body))
	}

	var respData baiduSearchResponse
	if err := json.Unmarshal(body, &respData); err != nil {
		return nil, fmt.Errorf("failed to unmarshal response: %w", err)
	}

	// Check for API-level error (returned with 200 status)
	if respData.Code != 0 {
		return nil, fmt.Errorf("baidu API error (code %d): %s", respData.Code, respData.Message)
	}

	results := make([]*types.WebSearchResult, 0, len(respData.References))
	for _, ref := range respData.References {
		result := &types.WebSearchResult{
			Title:   ref.Title,
			URL:     ref.URL,
			Content: ref.Content,

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Read the embedded body for Baidu's error detail
  2. On 401 verify/rotate the API key
  3. On 429 apply backoff and reduce request rate
  4. On 5xx retry with backoff
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/infrastructure/web_search/baidu.go:135 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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