Azathioprine in combination with N-acetylcysteine (NAC) and steroids is a standard therapy for idiopathic pulmonary fibrosis (IPF). Its use, however, is limited by its side effects, principally leukopenia. A genotypic assay, thiopurine S-methyltransferase (TPMT), has been developed that can potentially identify those at risk for developing leukopenia with azathioprine, and thereby limit its toxicity. In those with abnormal TPMT activity, azathioprine can be started at lower dose or an alternate regimen selected. Determine the cost-effectiveness of a treatment strategy using TPMT testing before initiation of azathioprine, NAC, and steroids in IPF by performing a computer-based simulation. We developed a decision analytic model comparing three strategies: azathioprine, NAC and steroids with and without prior TPMT testing, and conservative therapy, consisting of only supportive measures. Prevalence of abnormal TPMT alleles and complication rates of therapy were taken from the literature. We assumed a 12.5% incidence of abnormal TPMT alleles, 4% overall incidence of leukopenia while taking azathioprine, and that azathioprine, NAC, and steroids in combination reduced IPF disease progression by 14% during 12 months. TPMT testing before azathioprine, NAC, and steroids was the most effective and most costly strategy. The marginal cost-effectiveness of the TPMT testing strategy was $49,156 per quality adjusted life year (QALY) gained versus conservative treatment. Compared with azathioprine, NAC and steroids without prior testing, the TPMT testing strategy cost only $29,662 per QALY gained. In sensitivity analyses, when the prevalence of abnormal TPMT alleles was higher than our base case, TPMT was "cost-effective." At prevalence rates lower than our base case, it was not. TPMT testing before initiating therapy with azathioprine, NAC, and steroids is a cost-effective treatment strategy for IPF.