Nxivm’s accused cult leader had sex with “slaves’’ in a pal’s home library — which included a bed elevated over a hot tub, according to new court papers.

The creepy digs were detailed in grand jury testimony from two women who said they had sexual relations with Keith Raniere in the second-floor study of a home at 8 Hale Drive in upstate Halfmoon. The house is owned by Nxivm co-founder Nancy Salzman.

“The bed was elevated, and a hot tub was underneath the bed,” a former Nxivm member, Mark Vicente, also testified, the papers say.

One of Raniere’s alleged slaves said she also had sex with the 58-year-old leader in the home of “Smallville” TV actress and high-ranking Nxivm member Allison Mack.

The library was where the feds found a hard drive containing child pornography and additional sexually explicit images of other Nxivm members, including bookkeeper Kathy Russell and accused DOS slave master, Lauren Salzman, prosecutors say.

Both women have since pleaded guilty for their role in the group, as has Mack

Lawyers for Raniere are asking Brooklyn federal court Judge Nicholas Garaufis to bar jurors from hearing any evidence about the child porn.

They claim that a warrant was only issued for material relevant on or after Jan. 1, 2015 — and that the sexually explicit images of a then- 15-year-old were taken in 2005.

Raniere is accused of attempted sex trafficking, possession of child pornography, racketeering conspiracy and other charges.