  We introduce, for any bipartite Bell scenario, a measure that quantifies both
the amount of nonlocality and the efficiency in device-independent quantum key
distribution of a set of measurement outcomes probabilities. It is a proper
measure of nonlocality as it vanishes when this set is Bell local and does not
increase under the allowed transformations of the nonlocality resource theory.
This device-independent key rate $R$ is defined by optimizing over a class of
protocols, to generate the raw keys, in which each legitimate party does not
use just one preselected measurement but randomly chooses at each round one
among all the measurements at its disposal. A common and secret key can
certainly be established when $R$ is positive but not when it is zero. For any
continuous proper measure of nonlocality $N$, $R$ is tightly lower bounded by a
nondecreasing function of $N$ that vanishes when $N$ does. There can thus be a
threshold value for the amount of nonlocality as quantified by $N$ above which
a secret key is surely achievable. A readily computable measure with such a
threshold exists for two two-outcome measurements per legitimate party.
