Anti-PD-1/L1 has been demonstrated for its efficacy when combined with cytotoxic chemotherapy in randomized phase 3 trials for advanced biliary tract cancer (BTC). However, no biomarker predictive of benefit has been established for anti-PD-1/L1 in BTC. Here, we evaluated tumor-infiltrating lymphocytes (TILs) using artificial intelligence-powered immune phenotype (AI-IP) analysis in advanced BTC treated with anti-PD-1. Pre-treatment H&E-stained whole-slide images from 339 advanced BTC patients who received anti-PD-1 as second-line treatment or beyond, were utilized for AI-IP analysis and correlative analysis between AI-IP and efficacy outcomes with anti-PD-1. Next, data and images of BTC cohort from The Cancer Genome Atlas (TCGA) were additionally analyzed to evaluate the transcriptomic and mutational characteristics of various AI-IPs in BTC. Overall, AI-IPs were classified as inflamed (high intratumoral TIL [iTIL]) in 40 patients (11.8%), immune-excluded (low iTIL and high stromal TIL) in 167 (49.3%), and immune-deserted (low TIL overall) in 132 (38.9%). The inflamed IP group showed a significantly higher overall response rate compared to the non-inflamed IP groups (27.5% vs. 7.7%, P<0.001). Median overall survival and progression-free survival were significantly longer in the inflamed IP group than in the non-inflamed IP group (OS: 12.6 vs. 5.1 months, P=0.002; PFS: 4.5 vs. 1.9 months, P<0.001). In the analysis using TCGA cohort, the inflamed IP showed increased cytolytic activity scores and an interferon-gamma signature compared to the non-inflamed IP. AI-powered IP based on spatial TIL analysis was effective in predicting the efficacy outcomes in patients with BTC treated with anti-PD-1.