Tencent/WeKnora · error

Zhipu API error (%s): %s

Error message

Zhipu API error (%s): %s

What it means

Zhipu returned a parseable JSON body containing an application-level error object (non-empty error.code or error.message) while the HTTP status was 200. The provider surfaces the API's own error code and message to the caller.

Source

Thrown at internal/infrastructure/web_search/zhipu.go:162

	if err != nil {
		return nil, fmt.Errorf("failed to execute Zhipu request: %w", err)
	}
	defer resp.Body.Close()

	respBody, err := readZhipuResponseBody(resp.Body)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode != http.StatusOK {
		return nil, zhipuHTTPError(resp.StatusCode, respBody)
	}

	var response zhipuSearchResponse
	if err := json.Unmarshal(respBody, &response); err != nil {
		return nil, fmt.Errorf("failed to unmarshal Zhipu response: %w", err)
	}
	if response.Error.Message != "" || response.Error.Code != "" {
		return nil, fmt.Errorf("Zhipu API error (%s): %s", response.Error.Code, response.Error.Message)
	}

	results := make([]*types.WebSearchResult, 0, len(response.SearchResult))
	for _, item := range response.SearchResult {
		if strings.TrimSpace(item.Title) == "" && strings.TrimSpace(item.Link) == "" {
			continue
		}
		result := &types.WebSearchResult{
			Title:   item.Title,
			URL:     item.Link,
			Snippet: item.Content,
			Source:  "zhipu",
		}
		if includeDate {
			if publishedAt, ok := parseZhipuDate(item.PublishDate); ok {
				result.PublishedAt = &publishedAt
			}
		}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Check response.Error.Code against Zhipu docs (e.g. auth vs quota errors) and act accordingly
  2. Verify the API key is valid, active, and has remaining quota
  3. Validate the search_engine and request parameters match the current Zhipu API spec
  4. Regenerate the API key if it was rotated or revoked

Example fix

// before
if response.Error.Message != "" || response.Error.Code != "" {
    return nil, fmt.Errorf("Zhipu API error (%s): %s", response.Error.Code, response.Error.Message)
}
// after (caller side)
var apiErr *ZhipuAPIError
if errors.As(err, &apiErr) && apiErr.Code == "1301" {
    // refresh API key and retry once
}
Defensive patterns

Strategy: try-catch

Validate before calling

if apiKey == "" || len(apiKey) < 10 { return errors.New("zhipu api key missing or malformed") }

Type guard

func isZhipuAppError(err error) (code, msg string, ok bool) {
    if !strings.Contains(err.Error(), "Zhipu API error (") { return "", "", false }
    ok = true; return
}

Try / catch

results, err := provider.Search(ctx, q)
if err != nil {
    var apiErr ZhipuAPIError
    if errors.As(err, &apiErr) && apiErr.Code == authCode { return refreshKeyAndRetry(ctx) }
    return err
}

Prevention

When it happens

Trigger: Calling Search() with an invalid/over-quota API key or malformed search params when Zhipu signals the failure inside a 200 body instead of an error HTTP status.

Common situations: Expired or revoked Zhipu API key; exceeded rate limit/quota; unsupported search_engine value passed in the request payload.

Related errors


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