The supreme court or any district court within this state, or any judge of any such court, may issue a writ of habeas corpus to bring the body of any person confined in any jail in the state before such court or judge to testify or to be surrendered in discharge of bail. Where a writ is issued for any such purpose and the witness or principal sought is confined in any jail in a county other than the county in which such person is to be surrendered, or to which such person is to be removed, and where such writ is executed and returned by an officer to whom it is directed, the jailer from whose custody such person is taken shall be exonerated from liability for an escape if:
The party praying out such writ of habeas corpus shall pay to the officer executing the same such reasonable sum for the officer's services as shall be adjudged by the court.
N.D.C.C. § 32-22-43