For developers

Medication autocomplete API

One endpoint for the medication field. Send what the person has typed so far and get back the medicines they mean, brand and generic, in the order they’d pick. Then two short questions for form and strength, and each answer carries the date it was true.

Sandbox keys come with 500 lookups a month, and getting one doesn’t take a card.

The call

GET https://api.pillwise.dev/v1/drugs/search?q=metfo&limit=8
Authorization: Bearer pw_test_…
Parameter What it does
q Required. What the person typed, up to 200 bytes.
limit Hits to return. Default 10, at most 50. Eight is plenty for a menu.
cabinet_only Default true: leaves out hits that can’t go on a member’s medication list. false returns those too, with cabinet_eligible: false.
intent suggest (default) returns names to pick. sku returns one row per product, with its form, strength and codes.
as_of, graph_version Answer as the catalog was on a past day, up to a year back, or from one exact snapshot. Older returns 410 gone_graph.

How it matches partial input

  • Every word has to match, and the last one can be a start. metfo finds metformin, and insulin glar narrows to glargine. A start needs three letters: below that, the last word has to be a whole word.
  • Case and punctuation don’t matter. Tylenol PM, tylenol-pm and TYLENOL pm are the same query.
  • One typo is forgiven. When nothing matches, each unknown word of four letters or more is corrected to a catalog word one edit away: a wrong, missing or extra letter, or two letters swapped. lisinoprill finds lisinopril.
  • Names people say. Brands, ingredients, everyday names (vitamin D3, NPH insulin) and brands still said after they left the market all find the medicine.
  • Ranked for picking. The medicine named exactly comes first, then its main forms (“Metformin tablet”), brands and other ingredients, combinations, salts, then single products. Within each, the most widely sold comes first.

curl

curl "https://api.pillwise.dev/v1/drugs/search?q=metfo&limit=8" \
  -H "Authorization: Bearer pw_test_YOUR_KEY"

JavaScript: a debounced typeahead

The browser waits for three characters and a 250 ms pause, then cancels the request before it. It calls your server, which holds the key and caches answers.

// In the browser: your own endpoint, never the key.
let pending;
let timer;

input.addEventListener("input", () => {
  clearTimeout(timer);
  const q = input.value.trim();
  if (q.length < 3) return render([]);
  timer = setTimeout(async () => {
    pending?.abort(); // a slow "metf" must not land after "metfo"
    pending = new AbortController();
    try {
      const res = await fetch(`/api/med-search?q=${encodeURIComponent(q)}`, {
        signal: pending.signal,
      });
      if (!res.ok) return showError();
      render((await res.json()).hits);
    } catch (e) {
      if (e.name !== "AbortError") showError();
    }
  }, 250);
});
// On your server (Node 18+). PILLWISE_KEY=pw_test_…
const cache = new Map(); // query -> { at, body }
const HOUR = 60 * 60 * 1000;

export async function medSearch(raw) {
  const q = String(raw ?? "").trim().toLowerCase().replace(/\s+/g, " ").slice(0, 60);
  if (q.length < 3) return { hits: [] }; // a blank or short query would still cost a lookup
  const hit = cache.get(q);
  if (hit && Date.now() - hit.at < HOUR) return hit.body;

  const res = await fetch(
    `https://api.pillwise.dev/v1/drugs/search?q=${encodeURIComponent(q)}&limit=8`,
    { headers: { Authorization: `Bearer ${process.env.PILLWISE_KEY}` } },
  );
  if (!res.ok) {
    const e = await res.json().catch(() => ({})); // a malformed query string is a plain-text 400
    throw new Error(e.error ?? `HTTP ${res.status}`); // too_long, quota_exceeded, …
  }
  const body = await res.json();
  if (cache.size > 10_000) cache.clear();
  cache.set(q, { at: Date.now(), body });
  return body;
}

// The route the browser calls, here with Express.
app.get("/api/med-search", async (req, res) => {
  try {
    res.json(await medSearch(req.query.q));
  } catch {
    res.status(502).json({ error: "search_failed" });
  }
});

Python

import os, requests

r = requests.get(
    "https://api.pillwise.dev/v1/drugs/search",
    params={"q": "lisinoprill", "limit": 5},  # one letter too many still finds it
    headers={"Authorization": f"Bearer {os.environ['PILLWISE_KEY']}"},
    timeout=5,
)
r.raise_for_status()
body = r.json()
for hit in body["hits"]:
    print(hit["id"], hit["display_name"], hit.get("form", ""), hit.get("subtitle", ""))
print("as of", body["as_of"])

For the field itself (combobox roles, keyboard, what to store), see Building a medication typeahead that members can use.

What comes back

A real answer for q=metfo, trimmed to the first four of eight hits and with label ids left out of codes. The next rows are combinations, starting with glyburide / metformin. No hits is a 200 with an empty hits, not a 404.

Example response
{
  "hits": [
    {
      "id": "pw_d_5a57be6fa9d1c63e",
      "display_name": "Metformin",
      "matched_term": "metformin",
      "match_kind": "preferred",
      "pick_level": "ingredient",
      "presentation_count": 9,
      "rxcui": "6809",
      "codes": { "rxcui": "6809" },
      "cabinet_eligible": true
    },
    {
      "id": "pw_d_5a57be6fa9d1c63e",
      "display_name": "Metformin tablet",
      "form": "tablet",
      "form_label": "Tablet",
      "matched_term": "metformin hydrochloride 1000 MG Oral Tablet [Glucophage]",
      "match_kind": "preferred",
      "pick_level": "ingredient",
      "presentation_count": 5,
      "rxcui": "6809",
      "codes": { "rxcui": "6809" },
      "cabinet_eligible": true
    },
    {
      "id": "pw_d_5a57be6fa9d1c63e",
      "display_name": "Metformin extended-release tablet",
      "form": "er_tablet",
      "form_label": "Extended-release tablet",
      "matched_term": "Metformin",
      "match_kind": "brand",
      "pick_level": "ingredient",
      "presentation_count": 3,
      "rxcui": "6809",
      "codes": { "rxcui": "6809" },
      "cabinet_eligible": true
    },
    {
      "id": "pw_d_5a57be6fa9d1c63e",
      "display_name": "Metformin liquid",
      "form": "oral_liquid",
      "form_label": "Liquid",
      "matched_term": "metformin hydrochloride 100 MG/ML Oral Solution [Riomet]",
      "match_kind": "preferred",
      "pick_level": "ingredient",
      "presentation_count": 1,
      "rxcui": "6809",
      "codes": { "rxcui": "6809" },
      "cabinet_eligible": true
    }
  ],
  "coverage": "cpc_current",
  "graph_version": "20261029T093227Z",
  "as_of": "2026-10-29T09:32:27.152275954Z",
  "jurisdiction": "us",
  "freshness": "current"
}
  • What to show. display_name, and subtitle when there is one: on a brand hit it names the ingredients, which settles names that could mean two things.
  • What to save. id. A pw_d_ id is a medicine; a pw_g_ id is a brand, for example:
{ "id": "pw_g_dfffed56651f757b", "display_name": "Zoloft", "subtitle": "sertraline",
  "pick_level": "brand", "match_kind": "brand", "presentation_count": 4, … }
  • The form the words chose. On a hit like “Metformin tablet”, form is what the person typed toward. Pass it on as ?form= to the next call.
  • Why it matched. matched_term and match_kind (preferred, synonym, brand, proprietary, identifier). presentation_count is how many form and strength combinations sit under the hit.
  • The date. as_of and graph_version say which catalog answered. freshness is pinned whenever you pass as_of or graph_version.

Errors from the search itself are JSON with a stable code:

Status error When
400 too_long q is over 200 bytes.
400 unsupported_jurisdiction jurisdiction is anything but us.
400 bad_as_of as_of isn’t a date (YYYY-MM-DD) or an RFC 3339 instant.
400 as_of_version_mismatch as_of and graph_version are both sent and name different snapshots.
410 gone_graph The date or graph_version is older than the catalog keeps.

Key and plan errors (401, 402, 403, 429) are the same on every path: see the API reference.

From a hit to the full record

  1. Form and strength. GET /v1/drugs/{id}/form-options?form={form} returns the forms and strengths that exist for the hit, each with a label to show and a value to send back. Leave out form when the hit has none.
  2. The exact product. GET /v1/drugs/{id}/presentations?form= lists each form, strength and route as a row with its own id and rxcui.
  3. Everything about it. GET /v1/drugs/{id} with that row’s id, or GET /v1/drugs/rxcui/{rxcui}, returns the drug: names, ingredients, packages and their NDCs, and recalls. It’s the same shape the NDC lookup API returns.

On a pw_g_ brand id, GET /v1/drugs/{id} returns just the brand (name, subtitle, count): go through form-options and presentations for the product. Each of these calls is one lookup.

Keep typeahead from burning lookups

Each search request is a lookup, and every request counts, including ones with no hits and errors. We do not count keystrokes, so the number you pay for is the number of requests your field sends. The meter has the rest.

  • Wait for three characters. Shorter input matches whole words only, so it rarely helps.
  • Debounce. Send after the typing pauses, about 250 ms. “metformin” typed at speed is one request instead of seven.
  • Cancel the request before. An AbortController keeps a slow answer from replacing a newer one. A request the API already received still counts, so debounce is what saves.
  • Cache answers. The catalog rebuilds once a day, and an answer can change only when graph_version does. Cache by query on your server, so ten people typing “metf” cost one lookup.
  • Ask for fewer. limit=8 fills a menu. The count is per request, not per hit, so this is for speed rather than price.
  • Watch the count. Successful Index responses carry x-quota-used and x-quota-limit, and x-quota-remaining when the plan has a limit.

Pitfalls

The same id on several rows

“Metformin”, “Metformin tablet” and “Metformin extended-release tablet” share one id and differ by form. Key menu rows by id and form together, and pass the form on.

Numbers are read as codes

A query that is only a code is looked up as one: one to eight digits as an RxCUI, 10 to 12 digits as an NDC, with match_kind: "identifier". cabinet_only doesn’t apply to code lookups. That’s handy for staff pasting a code. In a member’s field, don’t send digits alone.

A strength changes the answer

Type a strength (metformin 500 mg, metformin 500) and the hits become single products, the same rows intent=sku returns. Only intent=sku adds each row’s form and strength, though. Good for search boxes; for a pick-the-name field, ask for strength in the next step instead.

Spelling help is a fallback

Correction runs only when nothing matches as typed, and only one edit per word. A misspelled start that still begins some other name returns that name. Show the subtitle so people can tell.

No match is normal

Some people will type something the catalog doesn’t know. Keep the text, flag it and let them carry on. Store the id you picked, not the text (and graph_version if you need to show what was picked). An id stays the same while its drug is in the catalog; a retired one answers with superseded_by.

Questions

Does the medication search handle misspellings?

One typo per word, in words of four letters or more: a wrong, missing or extra letter, or two swapped. It kicks in only when the query as typed finds nothing.

Does every keystroke count as a lookup?

Every request does, keystrokes don’t. Wait for three characters, debounce, and cache on your server, and a typed name costs a few lookups.

Can I call it straight from the browser?

Don’t: a key in browser code is a key anyone can use. Proxy the search through your server, as in the example above.

How current are the names?

The catalog rebuilds every day, and each answer carries as_of. How freshness works.

What does it cost?

The sandbox is free, 500 lookups a month, no card. Each search request is one lookup. Plans for production.

Three letters in, the right medicine out. Scroll forty rows of package codes.

Sandbox is 500 lookups a month with no card. When you go live, Launch is $99 a month for one production app.