"""ClinicalTrials.gov v2 async helper. Docs: https://clinicaltrials.gov/api/gui/ref/api_urls#v2 Provides `search_trials_v2` which returns a list of study dicts. """ import httpx, asyncio from typing import List, Dict _BASE = "https://clinicaltrials.gov/api/v2/studies" async def search_trials_v2(query: str, *, max_n: int = 20) -> List[Dict]: """Search CT.gov v2 endpoint and return list of studies.""" params = { "query": query, "pageSize": max_n, "fields": "nctId,briefTitle,phase,status,startDate,conditions,interventions", } async with httpx.AsyncClient(timeout=15) as client: resp = await client.get(_BASE, params=params) resp.raise_for_status() return resp.json().get("studies", [])