A detailed account of the technical challenges and solutions when integrating with healthcare systems that lack proper APIs, exploring the trade-offs between different automation approaches.
The healthcare integration landscape presents a unique set of challenges that differ significantly from other industries. Over the past year, we've been building integrations with Electronic Health Records (EHRs) and payer portals that often don't expose real APIs. This experience has been both educational and frustrating, revealing fundamental issues with healthcare data accessibility and system interoperability.
The Problem: Fragmented Healthcare Data
Healthcare data is notoriously fragmented across numerous systems. The APIs that are accessible frequently lack essential functionality or simply don't exist. FHIR (Fast Healthcare Interoperability Resources) endpoints, while promising, often miss the specific data needed for practical applications and typically lack writeback capabilities. Direct integration with EHR vendors proves expensive and slow, with most payer portals offering no APIs at all, or only extremely limited ones. Third-party API companies, meanwhile, often have significant coverage gaps.
This fragmentation forces healthcare technology companies to adopt unconventional approaches. Like many healthcare startups before us, we found ourselves embracing browser automation as a necessary evil.
Initial Approach: Fully Agentic Browser Agents
Our first attempt involved fully AI-driven browser agents. This approach had the lowest implementation lift and appeared robust on the surface. We quickly discovered, however, that EHR workflows are often non-intuitive, requiring numerous specific clicks and interactions that agents struggled to perform correctly.
These approaches were not only unreliable but also slow and expensive, as they required LLM API calls for each action. More concerning was the lack of control—we were uncomfortable giving an agent full autonomy to click anywhere within these critical healthcare systems.
Second Attempt: Stagehand as a Middle Ground
Recognizing the limitations of fully autonomous agents, we moved to Stagehand, which seemed to offer a better balance of determinism and AI to catch errors when they occurred. Unfortunately, Stagehand introduced its own set of problems.
Stagehand relied heavily on the accessibility tree, which didn't always map correctly to the actions or selectors needed in EHR systems. It consistently failed on more complex DOM structures like those found in Athena Health. Moreover, we realized the errors we encountered weren't even the types of changes Stagehand was designed to handle.
Third Approach: Playwright with Custom Solutions
Our breakthrough came when we shifted to Playwright and began addressing specific error categories systematically:
- Nondeterministic popups: These appeared unpredictably and would break our workflows.
- Slow rendering: Elements would take varying amounts of time to appear on screen.
- Edge cases with internal logic: Situations like encountering duplicate patients with no clear way to determine which chart to access.
We improved reliability by building a lightweight popup detector and implementing smarter wait times and reload strategies. For edge cases, we determined that human oversight was essential—we didn't want an AI making decisions about potentially critical healthcare interactions without review.
Hybrid Approach: Direct API Calls Where Possible
For reliability, speed, and maintainability, we rebuilt some integrations as direct API/network calls. These proved quicker and more reliable than browser automation approaches. However, we encountered security setups that detected and blocked automated requests, forcing us to maintain both approaches depending on the target system.
The Mental Model Shift: Build-Time AI vs. Runtime AI
The most significant insight came from shifting our approach from runtime AI (agents making decisions during execution) to build-time AI (using AI to generate and iterate on Playwright scripts, then fixing errors).
As engineers, we needed full visibility and control over the actual code. We wanted to be in the loop for edge cases, allowing us to determine the appropriate handling rather than delegating these decisions to an LLM during execution. This approach gave us better reliability while maintaining the flexibility needed for the unpredictable nature of healthcare systems.
Our Current Stack
Script Creation
We use local development with Playwright and Claude Code. We step through and record workflows, add comments, then run the recorded flow while having Claude connect to the running script to inspect logs and network requests for building automations.
Robustness
For specific cases, we add AI fallbacks like popup detectors that take screenshots and use X/Y coordinates to close popups and retry the intended logic.
Infrastructure
Initially, we self-hosted everything on GCP as Cloud Run jobs, capturing screenshots and structured error logs on failure for easier debugging. Recently, we've moved to hosted platforms like Kernel and Browserbase, though we've found these sometimes make scripts more flaky.
Open Source Contribution: Libretto
To help others facing similar challenges, we've bundled our internal logic for building and maintaining these workflows into an open-source skill/CLI called libretto. This tool reflects our accumulated knowledge and provides a foundation for others building healthcare integrations.
Key Takeaways
- Healthcare integration requires pragmatic compromises: The ideal API-first approach often isn't feasible, forcing browser automation solutions.
- Deterministic beats autonomous: While AI is powerful, healthcare workflows benefit from deterministic approaches with human oversight for edge cases.
- Hybrid approaches are necessary: Sometimes the best solution combines direct API calls with browser automation, depending on the target system.
- Build-time AI improves reliability: Shifting AI decision-making to the development process rather than runtime execution provides better control and reliability.
The challenges of healthcare integration won't disappear overnight, but by sharing our experiences and tools like libretto, we hope to help others navigate this difficult landscape more effectively than we could have alone.

Comments
Please log in or register to join the discussion