weaviate/weaviate · error
connection to Cohere API failed with status %d
Error message
connection to Cohere API failed with status %d
What it means
A formatted error raised when the Cohere rerank endpoint returned a non-200 status and the body either had no parseable message (the variant without %s). It means the client could not obtain any descriptive message from Cohere for the failure.
Source
Thrown at modules/reranker-cohere/clients/ranker.go:146
return nil, errors.Wrap(err, "send POST request")
}
defer res.Body.Close()
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
return nil, errors.Wrap(err, "read response body")
}
if res.StatusCode != 200 {
var apiError cohereApiError
err = json.Unmarshal(bodyBytes, &apiError)
if err != nil {
return nil, errors.Wrap(err, "unmarshal error from response body")
}
if apiError.Message != "" {
return nil, errors.Errorf("connection to Cohere API failed with status %d: %s", res.StatusCode, apiError.Message)
}
return nil, errors.Errorf("connection to Cohere API failed with status %d", res.StatusCode)
}
var rankResponse RankResponse
if err := json.Unmarshal(bodyBytes, &rankResponse); err != nil {
return nil, fmt.Errorf("failed to parse reranker response (status %d): %w", res.StatusCode, err)
}
return c.toDocumentScores(documents, rankResponse.Results), nil
}
func (c *client) chunkDocuments(documents []string, chunkSize int) [][]string {
var requests [][]string
for i := 0; i < len(documents); i += chunkSize {
end := i + chunkSize
if end > len(documents) {
end = len(documents)
}
View on GitHub (pinned to 75aa4b6d11)
Solutions
- Log bodyBytes on non-200 statuses to capture what was actually returned
- Check status code in the message: 401/403 -> fix API key; 429 -> backoff; 5xx -> retry or check Cohere status page
- Bypass intermediaries by testing directly against https://api.cohere.com
- Update the module/client so cohereApiError matches Cohere's current error schema
Example fix
// before: opaque error
return nil, errors.Errorf("connection to Cohere API failed with status %d", res.StatusCode)
// after
return nil, fmt.Errorf("connection to Cohere API failed with status %d: %s", res.StatusCode, string(bodyBytes)) Defensive patterns
Strategy: try-catch
Type guard
func isOpaqueCohereStatusError(err error) bool {
m := err.Error()
return strings.HasPrefix(m, "connection to Cohere API failed with status") && !strings.HasSuffix(m, "") && !strings.Contains(m, ": ")
} Try / catch
res, err := client.Rank(ctx, query, docs, cfg)
if err != nil && strings.HasPrefix(err.Error(), "connection to Cohere API failed with status") {
// no provider message available; log, alert, and optionally retry 5xx
} Prevention
- Capture raw bodies on non-200 to compensate for missing provider messages
- Distinguish 4xx (config problem) from 5xx (retryable) by parsing the status from the error
- Keep the module updated to match current provider error schemas
When it happens
Trigger: Cohere or an intermediary returns a non-200 with a JSON body lacking the expected message field (empty body, error object with different shape), or a bare gateway 5xx with empty payload.
Common situations: Proxies returning empty 502/504 bodies; Cohere returning error shapes the client's cohereApiError struct does not map; network devices intercepting TLS.
Related errors
- unmarshal error from response body
- connection to Cohere API failed with status %d: %s
- connection to Google failed with status: %v error: %v
- connection to Cohere API failed with status: %d
- connection to NVIDIA API failed with status: %d error: %s: %
AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04).
Data as JSON: /api/errors/0e3173d3fba59a6b.
Report an issue: GitHub.