{"record":{"id":"0e3173d3fba59a6b","repo":"weaviate/weaviate","slug":"connection-to-cohere-api-failed-with-status-d-0e3173","errorCode":null,"errorMessage":"connection to Cohere API failed with status %d","messagePattern":"connection to Cohere API failed with status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/reranker-cohere/clients/ranker.go","lineNumber":146,"sourceCode":"\t\treturn nil, errors.Wrap(err, \"send POST request\")\n\t}\n\tdefer res.Body.Close()\n\n\tbodyBytes, err := io.ReadAll(res.Body)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"read response body\")\n\t}\n\n\tif res.StatusCode != 200 {\n\t\tvar apiError cohereApiError\n\t\terr = json.Unmarshal(bodyBytes, &apiError)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"unmarshal error from response body\")\n\t\t}\n\t\tif apiError.Message != \"\" {\n\t\t\treturn nil, errors.Errorf(\"connection to Cohere API failed with status %d: %s\", res.StatusCode, apiError.Message)\n\t\t}\n\t\treturn nil, errors.Errorf(\"connection to Cohere API failed with status %d\", res.StatusCode)\n\t}\n\n\tvar rankResponse RankResponse\n\tif err := json.Unmarshal(bodyBytes, &rankResponse); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse reranker response (status %d): %w\", res.StatusCode, err)\n\t}\n\treturn c.toDocumentScores(documents, rankResponse.Results), nil\n}\n\nfunc (c *client) chunkDocuments(documents []string, chunkSize int) [][]string {\n\tvar requests [][]string\n\tfor i := 0; i < len(documents); i += chunkSize {\n\t\tend := i + chunkSize\n\n\t\tif end > len(documents) {\n\t\t\tend = len(documents)\n\t\t}\n","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/modules/reranker-cohere/clients/ranker.go#L128-L164","documentation":"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.","triggerScenarios":"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.","commonSituations":"Proxies returning empty 502/504 bodies; Cohere returning error shapes the client's cohereApiError struct does not map; network devices intercepting TLS.","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"],"exampleFix":"// before: opaque error\nreturn nil, errors.Errorf(\"connection to Cohere API failed with status %d\", res.StatusCode)\n// after\nreturn nil, fmt.Errorf(\"connection to Cohere API failed with status %d: %s\", res.StatusCode, string(bodyBytes))","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isOpaqueCohereStatusError(err error) bool {\n    m := err.Error()\n    return strings.HasPrefix(m, \"connection to Cohere API failed with status\") && !strings.HasSuffix(m, \"\") && !strings.Contains(m, \": \")\n}","tryCatchPattern":"res, err := client.Rank(ctx, query, docs, cfg)\nif err != nil && strings.HasPrefix(err.Error(), \"connection to Cohere API failed with status\") {\n    // no provider message available; log, alert, and optionally retry 5xx\n}","preventionTips":["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"],"tags":["http-status","api-error","response-parsing","reranker-cohere"],"backgroundTag":"upstream-api-error","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}