
548 F.3d 680 (2008)
Sadou Alious BAH, Petitioner-Appellant,
v.
Mark CANGEMI, District Director, United States Immigration & Customs Enforcement; Michael Chertoff, Secretary, Department of Homeland Security; Michael B. Mukasey, Attorney General; Eduardo Aguirre, Director, United States Citizenship & Immigration *681 Services, Enforcement; Denise Frazier, District Director, United States Citizenship & Immigration Services, Respondents-Appellees.
No. 08-1705.
United States Court of Appeals, Eighth Circuit.
Submitted: November 10, 2008.
Filed: November 28, 2008.
*682 Herbert A. Igbanugo, Dyan Williams, argued, Minneapolis, MN, for appellant.
David Gerald Wilhelm, argued, AUSA, Minneapolis, MN, for appellee.
Before MURPHY, RILEY, and GRUENDER, Circuit Judges.
MURPHY, Circuit Judge.
In 2005 United States Immigration and Customs Enforcement (ICE) determined that Sadou Bah was a removable alien and detained him for over a year while it sought the travel documents necessary to remove him. Bah successfully petitioned under 28 U.S.C. § 2241 for release from his detention. The district court[1] denied his subsequent request for attorney fees under the Equal Access to Justice Act, concluding that the government's position in the litigation had been substantially justified. Bah appeals, and we affirm.
Sadou Bah is a Liberian national who entered the United States in 1991 as a nonimmigrant visitor. He overstayed his visa and twice married and divorced United States citizens. On July 6, 2004, ICE commenced removal proceedings against Bah. Its removal order became final on May 23, 2005, when the Bureau of Immigration Appeals (BIA) denied Bah's appeal. Bah was placed in custody pending his removal. Because ICE was unable to obtain travel documents from Liberia, Bah remained in custody for approximately fourteen months. During that time Bah petitioned this court for review of the BIA's decision and also filed for and received Temporary Protective Status (TPS).
The Attorney General may grant an alien TPS if conditions in the alien's home country would pose a threat to the alien's safety if he were returned there. See 8 *683 U.S.C. § 1254a(b). Bah's TPS designation shielded him from removal for at most seven months, from June 21, 2005 until January 18, 2006.[2]
On August 7, 2006 Bah filed a petition in the district court for writ of habeas corpus under 28 U.S.C. § 2241.[3] Under Zadvydas v. Davis, 533 U.S. 678, 121 S.Ct. 2491, 150 L.Ed.2d 653 (2001), the government can detain an alien ordered removed for the initial 90 days allowed by 8 U.S.C. § 1231(a)(2), and thereafter only for the period reasonably necessary to secure the alien's removal. Id. at 682, 121 S.Ct. 2491. It is presumptively reasonable for the government to detain the alien for six months or less, but after that time the government must show a significant likelihood of removal in the reasonably foreseeable future. Id. at 701, 121 S.Ct. 2491.
This court granted Bah's petition for review of his BIA decision and remanded to the BIA for further proceedings on August 9, 2006.[4]Bah v. Gonzales, 457 F.3d 838 (8th Cir.2006) (per curiam). Subsequently, the district court granted Bah's habeas petition and ordered his release, Bah v. Cangemi, 489 F.Supp.2d 905, 914-23 (D.Minn.2007). The government did not appeal that order.
Bah then moved for an award of attorney fees and costs under the Equal Access to Justice Act (EAJA), which requires an "award to a prevailing party . . . [of] fees and other expenses . . . incurred by that party in any civil action . . . unless the court finds that the position of the United States was substantially justified or that special circumstances make an award unjust."[5] 28 U.S.C. § 2412(d). The district court concluded that Bah had been the prevailing party but that he was not entitled to a fee award because the government's position was substantially justified. Bah appeals, arguing that the government's position, both preceding the litigation and during litigation, was not substantially justified.
We review for abuse of discretion a district court's determination that the government's actions were substantially justified. See Pierce v. Underwood, 487 U.S. 552, 559-61, 108 S.Ct. 2541, 101 L.Ed.2d 490 (1988). Substantially justified means "justified to a degree that could satisfy a reasonable person." Id. at 565, 108 S.Ct. 2541. A substantially justified position need not be correct so long as "a reasonable person could think it correct, that is, if it has a reasonable basis in law *684 and fact." Id. at 566 n. 2, 108 S.Ct. 2541; see also Brouwers v. Bowen, 823 F.2d 273, 275 (8th Cir.1987) (holding that the government's position must be "clearly reasonable, well founded in law and fact, solid though not necessarily correct"). The government may also be justified in litigating a legal question that is unsettled in this circuit. See Cornella v. Schweiker, 741 F.2d 170, 172 (8th Cir.1984). The government bears the burden of showing that its position was substantially justified. Friends of the Boundary Waters Wilderness v. Thomas, 53 F.3d 881, 885 (8th Cir.1995).
The government had argued in response to Bah's habeas petition that our grant of review of his BIA decision meant that ICE's May 23, 2005 removal order was no longer final and therefore did not have the effect of starting the six month detention period recognized in Zadvydas as presumptively reasonable. The district court noted that novel legal issues had been raised in the case, which required extensive analysis of when Bah's detention period should be deemed to have commenced and whether any intervening time should be excluded from the calculation of his total detention time. The district court observed that the government's primary argument found some support in a Second Circuit decision, Wang v. Ashcroft, 320 F.3d 130, 147 (2d Cir.2003), and in several district court decisions.
Though it ultimately ruled against the government on Bah's habeas petition, the district court determined that the government's defense had been reasonable and denied Bah's request for attorney fees. We agree that the legal position advanced by the government in such an open area of the law had "a reasonable basis in law and fact," and conclude that the district court did not abuse its discretion in finding that the government's position during the litigation was substantially justified.
Bah also contends that the government's prelitigation conduct was unjustified. The EAJA requires courts to consider the government's conduct leading up to the litigation in addition to its subsequent conduct. See 28 U.S.C. § 2412(d)(2)(D) (defining "position of the United States" as not only "the position taken by the United States in the civil action, [but also] the action or failure to act by the agency upon which the civil action is based"). If the court finds that the government took an unjustified position in either of these stages, it must award fees under § 2412(d). See Comm'r v. Jean, 496 U.S. 154, 159, 110 S.Ct. 2316, 110 L.Ed.2d 134 (1990); Jackson v. Chater, 94 F.3d 274, 278 (7th Cir.1996). The district court did not analyze the reasonableness of the government's prelitigation conduct as distinct from its litigation position, but we conclude that the record supports a finding that the prelitigation conduct was substantially justified. See United States v. Sager, 743 F.2d 1261, 1263 n. 4 (8th Cir.1984); see also Zarcone v. Perry, 581 F.2d 1039, 1040 (2d Cir. 1978) (affirming denial of attorney fees under the Civil Rights Act on alternative grounds).
Bah claims that his fourteen month detention was unjustified because it exceeded the presumptively reasonable six month detention period recognized in Zadvydas v. Davis. Even if the government was justified in arguing during litigation that the appellate decision granting Bah's petition reset the Zadvydas clock, it could not have relied on that rationale to justify his detention prior to that point, he says.
Under Zadvydas an alien who has been detained for more than six months can obtain release by showing that there is "no significant likelihood of removal in the reasonably foreseeable future," which then requires *685 the government to respond with evidence sufficient to rebut that showing. 533 U.S. at 701, 121 S.Ct. 2491. The Zadvydas decision "does not mean that every alien not removed must be released after six months," but rather that "an alien may be held in confinement until it has been determined that there is no significant likelihood of removal in the reasonably foreseeable future." Id. During Bah's detention ICE was attempting to obtain travel documents from the Liberian government. It was not until the district court's ruling on Bah's habeas petition that there was a determination that prompt removal was unlikely despite these efforts. The government's continued detention of Bah up to that point was substantially justified, even if further detention was determined to be unreasonable.
Bah also argues that the government illegally prolonged his detention based on a vacated felony conviction for second degree criminal sexual conduct. Citizenship and Immigration Services (CIS) cited Bah's conviction as grounds for revoking his Temporary Protected Status. See 8 U.S.C. § 1254a(c)(2)(B)(i). Once Bah's TPS was revoked, he again became subject to removal. The day after he filed his habeas petition, Bah filed a separate request for a writ of mandamus[6] to compel CIS to disregard the vacated conviction and grant him TPS.
The decision to grant TPS is committed to the discretion of the Attorney General, see 8 U.S.C. § 1254a(a)(1)(A), and Congress has prohibited courts from reviewing any decision or action "the authority for which is specified under this title to be in the discretion of the Attorney General," id. § 1252(a)(2)(B). Based on these provisions, the district court determined that it lacked jurisdiction to review the government's decision to refuse Bah TPS. See also Rodas v. Chertoff, 399 F.Supp.2d 697 (E.D.Va.2005). The court of appeals may review "constitutional claims or questions of law," 8 U.S.C. § 1252(a)(2)(D), however, and Bah contended that CIS had committed legal error in ruling that his vacated conviction required revocation of his TPS designation. The district court transferred the mandamus request to this court under 28 U.S.C. § 1631. We dismissed it for lack of jurisdiction, Bah v. Mukasey, 521 F.3d 857 (8th Cir.2008), because we only have jurisdiction to review final orders of removal. 8 U.S.C. § 1252(a)(1). Since Bah's removal order had been vacated by our decision in Bah v. Gonzales, 457 F.3d 838, there was nothing to review.
In resolving Bah's EAJA motion, the district court did not evaluate whether the government's rejection of his TPS application had been substantially justified. This was appropriate because the district court lacked jurisdiction to review the government's discretionary action. The government's denial of Bah's TPS application was not "the action . . . by the agency upon which the civil action is based." See 28 U.S.C. § 2412(d)(2)(D). The civil action in which Bah had prevailed was his petition for a writ of habeas corpus; he was not the prevailing party in any sense on his request for a writ of mandamus. The relief Bah sought by his mandamus request was different from that sought by his habeas petition. If Bah had been granted TPS, he would have been protected from removal, but he would not necessarily have been entitled to be released from detention.[7]Cf. 8 U.S.C. § 1254a(f) *686 (listing the benefits to aliens granted TPS). The decision to revoke his TPS and deny his subsequent reapplication was therefore not the basis for Bah's habeas petition.
We conclude that the district court did not abuse its discretion in concluding that the government's position regarding Bah's detention and the subsequent litigation was substantially justified, and that Bah was therefore not entitled to attorney fees under 28 U.S.C. § 2412(d). The judgment of the district court is affirmed.
NOTES
[1]  The Honorable Patrick J. Schiltz, United States District Judge for the District of Minnesota.
[2]  Bah reapplied for TPS on March 22, 2006, and that application was denied on July 6, 2006.
[3]  The REAL ID Act of 2005, Pub.L. No. 109-13, § 106(a), 119 Stat. 231, 310 (2005) (codified at 8 U.S.C. § 1252(a)(5)), requires that habeas petitions seeking relief from a final order of removal be filed in the court of appeals. The Act does not affect a district court's jurisdiction over habeas petitions challenging the detention associated with a removal order, however. See H.R.Rep. No. 109-72, at 175 (2005), U.S.Code Cong. & Admin.News 2005, pp. 240, 300 (Conf.Rep.); see also Codina v. Chertoff, 283 Fed.Appx. 432, at *1 (8th Cir.2008) (per curiam); Gul v. Rozon, 163 Fed.Appx. 317, at *1 (5th Cir. 2006); Moallin v. Cangemi, 427 F.Supp.2d 908, 920-21 (D.Minn.2006).
[4]  The BIA had previously ruled that Bah had failed to present, in his brief to the BIA, his argument that he had not knowingly and intelligently waived his right to appeal from the Immigration Judge's determination. We concluded otherwise, granted his petition for review, and remanded to the BIA for it to determine whether or not Bah had waived his appellate rights. Bah, 457 F.3d at 838.
[5]  The EAJA also permits the court to award attorney fees in its discretion, 28 U.S.C. § 2412(b), which the district court declined to do. Bah was awarded his costs under 28 U.S.C. § 2412(a)(1).
[6]  These requests for relief were consolidated into a single amended pleading by Magistrate Judge Janie Mayeron.
[7]  Bah was granted TPS on June 21, 2005, and CIS did not finally withdraw it until January 18, 2006. Between those dates Bah remained in custody.
