Context. We present the analysis of the baryonic content of 52 X-ray luminous galaxy clusters observed with Chandra in the redshift range 0.3-1.273. Aims. Our study aims at resolving the gas mass fraction in these objects to place constraints on the cosmological parameters Ω m , Ω Λ and the ratio between the pressure and density of the dark energy, w. Methods. We deproject the X-ray surface brightness profiles to recover the gas mass profiles and fit a single thermal component to the spectrum extracted from a region around the cluster that maximizes the signal-to-noise ratios in the observation. The measured values of the gas temperature are used to evaluate the temperature profile with a given functional form and to estimate the total gravitating mass in combination with the gas density profiles. These measured quantities are then used to statistically estimate the gas fraction and the fraction of mass in stars. By assuming that galaxy clusters are representative of the cosmic baryon budget, the distribution of the cluster baryon fraction in the hottest (T gas > 4 keV) systems as a function of redshift is used to constrain the cosmological parameters. We discuss how our constraints are affected by several systematic effects, namely the isothermality, the assumed baryon fraction in stars, the depletion parameter and the sample selection. Results. By using only the cluster baryon fraction as a proxy for the cosmological parameters, we obtain that Ω m is very well constrained at the value of 0.35 with a relative statistical uncertainty of 11% (1σ level; w = −1) and a further systematic error of about (−6, +7)%. On the other hand, constraints on Ω Λ (without the prior of flat geometry) and w (using the prior of flat geometry) are definitely weaker due to the presence of greater statistical and systematic uncertainties (of the order of 40 per cent on Ω Λ and greater than 50 per cent on w). If the WMAP 5-year best-fit results are assumed to fix the cosmological parameters, we limit the contributions expected from non-thermal pressure support and ICM clumpiness to be lower than about 10 per cent, also leaving room to accommodate baryons not accounted for either in the X-ray emitting plasma or in stars of the order of 18 per cent of the total cluster baryon budget. This value is lowered to zero for a no-flat Universe with Ω Λ > 0.7.