router-for-me/CLIProxyAPI · error

decode Claude OAuth %s response: %w

Error message

decode Claude OAuth %s response: %w

What it means

The encoding was recognized and its reader constructed, but reading the decoded stream failed before EOF. The wrapping message includes which encoding was in play, and the underlying error is usually 'unexpected EOF', a corrupt stream, or a connection reset. It means the body started out decodable but broke partway through.

Source

Thrown at internal/auth/claude/oauth_response.go:66

		reader = gzipReader
	case "deflate":
		zlibReader, errZlib := zlib.NewReader(bytes.NewReader(encoded))
		if errZlib == nil {
			reader = zlibReader
		} else {
			reader = flate.NewReader(bytes.NewReader(encoded))
		}
	case "br":
		reader = io.NopCloser(brotli.NewReader(bytes.NewReader(encoded)))
	case "compress":
		reader = lzw.NewReader(bytes.NewReader(encoded), lzw.MSB, 8)
	default:
		return nil, fmt.Errorf("decode Claude OAuth response: unsupported content encoding %q", encoding)
	}
	decoded, errDecoded := io.ReadAll(reader)
	if errDecoded != nil {
		_ = reader.Close()
		return nil, fmt.Errorf("decode Claude OAuth %s response: %w", encoding, errDecoded)
	}
	if errClose := reader.Close(); errClose != nil {
		return nil, fmt.Errorf("close Claude OAuth %s decoder: %w", encoding, errClose)
	}
	return decoded, nil
}

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Retry the request with backoff — mid-stream truncation is usually transient.
  2. Send Accept-Encoding: identity to remove the decoding step entirely.
  3. Increase client read timeouts or disable keep-alive reuse for the OAuth endpoint if resets recur.
  4. Check the underlying error text (unexpected EOF vs corrupt input) to distinguish network truncation from proxy corruption.
Defensive patterns

Strategy: retry

Try / catch

body, err := decode(body, enc)
if err != nil && (errors.Is(err, io.ErrUnexpectedEOF) || strings.Contains(err.Error(), "connection reset")) {
    // truncated mid-stream: safe to retry the whole request once
    resp, _ = client.Do(req)
    body, err = decode(resp.Body, enc)
}

Prevention

When it happens

Trigger: Truncated OAuth response bodies (connection closed mid-body), corrupted deflate/zlib streams where the raw-flate fallback also fails, brotli streams interrupted mid-read, or a proxy re-chunking the body incorrectly.

Common situations: Mobile/unstable networks during token refresh; aggressive proxy buffering that cuts large responses; servers under load closing keep-alive connections early; snapshot-replay test data truncated at a fixed buffer size.

Related errors


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/3093034446c3e372. Report an issue: GitHub.