The invention relates to the in vitro and in cellulo detection of the cofactors nicotinamide adenine dinucleotide (NAD) and nicotinamide adenine dinucleotide phosphate (NADP). Provided is a sensor molecule for fluorescence or luminescence-based detection of a nicotinamide adenine dinucleotide analyte, in particular for detecting the concentrations of NAD+, NADP' and/or the ratios of the concentrations of NAD '/NAD H and NADP '/NADPH, the sensor comprising (i) a binding protein (BP) for the nicotinamide adenine dinucleotide analyte, the BP being derived from sepiapterin reductase (SPR; EC 1.1.1.153) (ii) a SPR ligand (SPR-L) capable of intramolecular binding to said BP in the presence of the oxidized form of said analyte; and (iii) at least one fluorophore.