This retrospective study aimed to explore the relationships between electrolytes and osmotic pressure homeostasis with contrast-associated acute kidney injury (CA-AKI) risk in patients with percutaneous coronary intervention or coronary angiography. We totally enrolled 4386 hospitalized patients, who were categorized into five groups based on the predetermined cutoff values of electrolytes and osmotic pressure. CA-AKI was defined as an increase in serum creatine by 0.5 mg/dL (44.2 mol/L) or a 25% increase of the highest level post-operation compared to baseline. Multivariable logistic analysis was used to examine the association of CA-AKI incidence with electrolytes and osmotic pressure levels. Piecewise linear regression models and restricted cubic spline analysis were further utilized to determine the nonlinear relationship. The results showed U-shaped relationships between sodium, chloride, magnesium, and osmotic pressure levels and CA-AKI incidence. The lowest incidence was observed in the categories of 139–141.9 mmol/L, 107.0–109.9 mmol/L, 0.91–1.07 mmol/L, and 290.0–299.9 mOsm/kg, respectively. J-shaped associations were observed for potassium and phosphate levels and CA-AKI incidence, with the lowest incidence in the categories of 3.50–4.09 mmol/L and 0.96–1.28 mmol/L, respectively. A negative correlation was observed between calcium level and CA-AKI incidence, with the lowest CA-AKI risk in the category of ≥ 2.58 mmol/L. In conclusion, abnormally higher or lower sodium, chloride, magnesium, phosphate, and osmotic pressure levels on admission were associated with increased risks of CA-AKI. While for potassium and calcium, the status of hyperkalemia and hypocalcemia on admission showed more susceptibility for CA-AKI.