Niobium metal foils were heat-treated at 900°C under different conditions and in situ investigated with time-resolved X-ray absorption fine-structure (EXAFS and XANES) measurements. The present study aims to mimic the conditions usually applied for heat treatments of Nb materials used for superconducting radiofrequency cavities, in order to better understand the evolving processes during vacuum annealing as well as for heat treatments in controlled dilute gases. Annealing in vacuum in a commercially available cell showed a substantial amount of oxidation, so that a designated new cell was designed and realized, allowing treatments under clean high-vacuum conditions as well as under well controllable gas atmospheres. The experiments performed under vacuum demonstrated that the original structure of the Nb foils is preserved, while a detailed evaluation of the X-ray absorption fine-structure data acquired during treatments in dilute air atmospheres (10−5 mbar to 10−3 mbar) revealed a linear oxidation with the time of the treatment, and an oxidation rate proportional to the oxygen (air) pressure. The structure of the oxide appears to be very similar to that of polycrystalline NbO. The cell also permits controlled exposures to other reactive gases at elevated temperatures; here the Nb foils were exposed to dilute nitrogen atmospheres after a pre-conditioning of the studied Nb material for one hour under high-vacuum conditions, in order to imitate typical conditions used for nitrogen doping of cavity materials. Clear structural changes induced by the N2 exposure were found; however, no evidence for the formation of niobium nitride could be derived from the EXAFS and XANES experiments. The presented results establish the feasibility to study the structural changes of the Nb materials in situ during heat treatments in reactive gases with temporal resolution, which are important to better understand the underlaying mechanisms and the dynamics of phase formation during those heat treatments in more detail.