智能體回答藥物問題不應只依賴網頁,作者實測四個官方 API
A drug question your agent shouldn't answer from a web page
AgentReady Tools 作者於 2026-11-16 實測 RxNorm/RxNav、ClinicalTrials.gov、PubMed/NCBI E-utilities 和 openFDA 四個官方 API,整理以結構化資料回答藥物問題的查詢方式。
This first appeared on 16 November 2026 at AgentReady Tools.
Suppose you ask an agent a narrow question about a drug. Is atorvastatin in a recruiting trial? What does PubMed return for it? Does FDA have labeling or adverse-event records? An agent that tries to answer from web pages will come back with a narrative. What you actually need is an identifier you can reuse, a status field you can check, and a timestamp for when the source last refreshed.
I called four official APIs on 16 November 2026 and wrote down what they returned. All four are listed in our Health and biomedical data category. None of them charged a fee for the calls I made. They also don't share a login model, a rate limit, or a common ID. That missing common ID is the part that breaks a workflow.
The data is already in JSON. The work is calling the right endpoint with an identifier that survives the next search, and not asking any source to do more than it claims to support.
Start with the name
If an agent searches "Lipitor" in one system and "atorvastatin" in another, it can miss records that belong to the same drug. NLM's RxNorm / RxNav APIs exist to resolve that. I called https://rxnav.nlm.nih.gov/REST/rxcui.json?name=atorvastatin and got a single RxCUI: 83367. The same host reported its dataset version as 02-Nov-2026 and apiVersion 3.1.357.
NLM's Terms of Service say the RxNorm, RxTerms, Prescribable RxNorm, and RxClass APIs may be used free of charge, at no more than 20 requests per second per IP address. Over that, the servers may stop servicing requests until the rate falls, and the official FAQ says the response is HTTP 429. A free UMLS license can raise the cap to 100 requests per second if you send your UTS API key as Authorization: Bearer <key>. NLM recommends caching results for 12 to 24 hours. The APIs are updated after each RxNorm full monthly release.
Most of these APIs need no license. The official FAQ makes one exception: /rxcui/{rxcui}/proprietary, which needs a UMLS license and a proxy granting ticket. RxNav's drug/drug interaction features were discontinued on 2 January 2024, so this is the wrong API for that question. The same FAQ also notes a rename to "RxNorm Tools" on 10 February 2027, with a new site URL, and says existing functionality will not be impacted.
On the morning I checked, the Terms of Service and FAQ pages carried NLM's notice that, because of a lapse in government funding, information on the website may not be up to date. The API calls above still returned HTTP 200. I can't say how that notice affects every field. An agent should surface it instead of hiding it.
The trial registry is a different API
Once you have a name or a condition, ClinicalTrials.gov is the official NLM registry API for registered studies. The current interface is version 2, documented as OpenAPI 3.0.3 at https://clinicaltrials.gov/api/oas/v2, with server URL https://clinicaltrials.gov/api/v2. The spec I fetched lists /studies, /studies/{nctId}, metadata and search-area helpers, a few /stats paths, and /version. It declares no security schemes, and I did not send a key.
A GET to /api/v2/version returned apiVersion 2.0.5 and dataTimestamp 2026-11-13T10:00:06. A GET to /api/v2/studies?pageSize=1&countTotal=true returned totalCount 611771, one study record, and a nextPageToken. I did not filter that studies call by drug name. Official pageSize defaults to 10 and is coerced down to 1,000 if you ask for more. Pages can come back with an empty studies array. If you query with only NCT IDs, filters are ignored. All of that is in the spec.
I also tried an older info path, /api/info/api_vrs, and got 404. A legacy path, /api/legacy/full-studies, still returned XML, with APIVrs 1.2.0 and a DataVrs that matched the v2 timestamp. If your agent was written against the classic /api/info/ or /api/query/ URLs, check it. I'd point it at /api/v2/ now. The official OpenAPI document does not publish a request quota, and I am not going to invent one.
PubMed is a third system, with a tighter cap
PubMed / NCBI E-utilities is the official programmatic interface for PubMed and the other Entrez databases. A single unauthenticated ESearch for atorvastatin (db=pubmed, retmode=json, retmax=1) returned count 13155. That number will move. The point is the shape of the response: a count, a translation of the query, and a list of PMIDs, not a page of snippets.
NCBI's official Insights post on E-utilities API keys, still on the site when I read it, is the clearest public statement of the rate limits I could fetch today. Without a key, more than three requests per second from one IP address receives an error. A free key from your NCBI account settings raises the default to 10 requests per second for that key. You pass it as api_key. If several machines share one key, they share that budget.
I did not treat that 2017 post as a stand-in for the full E-utilities usage-policy chapter. NCBI's Bookshelf pages presented a browser check from this network, so I could not re-read that chapter this session. If you run a heavy job, read the current policy before you loop.
openFDA will tell you not to trust it for care
openFDA is the FDA's Elasticsearch API for public data on drugs, devices, foods, and related records, returned as JSON. Every query goes through one endpoint for one kind of data. I called https://api.fda.gov/drug/event.json?limit=1 with no key and got HTTP 200. I did not filter that call by drug name. The meta object included last_updated 2026-10-28, a total of 21,054,159 matching records, and this disclaimer, quoted in full:
Do not rely on openFDA to make decisions regarding medical care. While we make every effort to ensure that data is accurate, you should assume all results are unvalidated. We may limit or otherwise restrict your access to the API in line with our Terms of Service.
A search of drug labels for openfda.generic_name:atorvastatin, limited to one record, also returned 200. That response said last_updated 2026-11-13, with 276 matching labels.
The official authentication page lists both of the following, on the same page: "An API key is required to make calls to the openFDA API," and standard limits for calls with no key (240 requests per minute and 1,000 per day per IP) versus calls with a free key (240 per minute and 120,000 per day per key). The key goes in the api_key query parameter, or as a basic-auth username. All queries are supposed to use https://api.fda.gov. Official query docs cap limit at 1,000 and skip at 25,000. The about page adds that not all openFDA data has been validated for clinical or production use, and that it does not include personally identifiable patient information.
If you're wiring this into an agent, the disclaimer in meta should stay visible. It is part of the record.
What I'd do with these four
I'd resolve the name first, then use the RxCUI or the generic name in the other calls, and I'd keep each source's identifier in the result: RxCUI, NCT ID, PMID, and whatever openFDA field you searched. I'd also cap concurrency to the strictest official limit you have a key for, and I wouldn't retry a 400. A 429 is a backoff. An empty page of studies is a valid answer.
These four listings are a slice of a larger set. As of 16 November 2026 our catalog at /tools.json has 174 tools, 20 of them in Health and biomedical data. I didn't re-verify the other 16 for this post. Some other directory links are affiliate links; these four are not.
None of this is medical advice, and none of these APIs asked me to treat it as such. If your agent is still answering that drug question from a pile of web pages, point it at the official JSON instead. Start with the name, and keep the disclaimers attached.
來源:DEV Community · dev.to