# API Latency Breakdown API latency breakdown monitor showing network time vs processing time split, p95 latency tracking, and performance bottleneck detection for Claude Code sessions. --- ## Metadata **Title:** API Latency Breakdown **Category:** statuslines **Author:** JSONbored **Added:** October 2025 **Tags:** api-latency, performance, monitoring, bottleneck, network **URL:** https://claudepro.directory/statuslines/api-latency-breakdown ## Overview API latency breakdown monitor showing network time vs processing time split, p95 latency tracking, and performance bottleneck detection for Claude Code sessions. ## Content #!/usr/bin/env bash API LATENCY BREAKDOWN MONITOR FOR CLAUDE CODE SHOWS NETWORK/WAITING TIME VS ACTUAL API PROCESSING TIME READ JSON FROM STDIN read -r input EXTRACT VALUES totaldurationms=$(echo "$input" | jq -r '.cost.totaldurationms // 0') apidurationms=$(echo "$input" | jq -r '.cost.totalapiduration_ms // 0') CALCULATE NETWORK/WAITING TIME (TOTAL - API) networktime=$((totaldurationms - apiduration_ms)) AVOID NEGATIVE VALUES if [ $network_time -lt 0 ]; then network_time=0 fi CONVERT TO SECONDS FOR DISPLAY apiseconds=$(echo "scale=2; $apiduration_ms / " | bc) networkseconds=$(echo "scale=2; $networktime / " | bc) totalseconds=$(echo "scale=2; $totalduration_ms / " | bc) CALCULATE PERCENTAGE SPLIT if [ $totaldurationms -gt 0 ]; then apipercentage=$(( (apidurationms * ) / totalduration_ms )) networkpercentage=$(( - apipercentage )) else api_percentage=0 network_percentage=0 fi PERFORMANCE ASSESSMENT (NETWORK TIME SHOULD BE MINIMAL) if [ $network_time -lt ]; then # 5s network time) ? Visual ratio bar (blue = API processing, orange = network overhead) ? Helps identify network issues vs API performance problems ? Lightweight bash with bc for floating-point calculations CONFIGURATION Format: bash Refresh Interval: 1000ms Position: left USE CASES ? Performance debugging for slow Claude Code responses ? Identifying network bottlenecks vs API processing delays ? Optimizing API call efficiency in distributed teams ? Troubleshooting VPN/proxy latency issues ? Monitoring API performance degradation over time ? Production environment SLA monitoring TROUBLESHOOTING 1) Network time showing negative or zero despite slow responses Solution: Verify both cost.totaldurationms and cost.totalapidurationms fields exist: echo '$input' | jq .cost. Negative protection caps networktime at 0. If both values missing, script shows 0s - check Claude Code version supports these fields. 2) API percentage always showing % with no network time Solution: This indicates totaldurationms equals totalapidurationms (no measurable network overhead). Verify calculations: networktime = total - API. If consistently 0, either network is extremely fast or fields are identical in JSON. Check actual JSON values. 3) Performance status showing BOTTLENECK incorrectly Solution: Thresholds: 5s red (BOTTLENECK). Adjust thresholds in script if your network baseline differs. VPN users may see higher normal latency. Modify: network_time -lt to higher value for VPN environments. 4) Ratio bar not displaying or showing as empty Solution: Bar uses ANSI background colors (\[48;5;Xm). Ensure terminal supports -color mode: tput colors (should return ). If bars show as spaces only, verify ANSI escape codes working: echo -e '\[48;5;75m BLUE \[0m'. 5) bc: command not found when calculating percentages Solution: Install bc: brew install bc (macOS), apt install bc (Linux). Alternative: use integer math only: apipercentage=$((apidurationms * / totalduration_ms)) - removes decimal precision but works without bc. TECHNICAL DETAILS Documentation: https://docs.claude.com/en/docs/claude-code/statusline PREVIEW ✓ FAST | API: 2.34s (85%) | Network: 0.41s (15%) | █████████████████░░░ --- Source: Claude Pro Directory Website: https://claudepro.directory URL: https://claudepro.directory/statuslines/api-latency-breakdown This content is optimized for Large Language Models (LLMs). For full formatting and interactive features, visit the website.