Build with an AI agent
These docs are written to be read by coding agents as well as people. Copy the prompt below into your agent and it knows the endpoints, the prices, the limits, when to search and when to ask, and where to look up the rest.
Before you paste it, set two environment variables in the shell your agent runs in. The agent reads the key from there, so it never appears in the conversation. See the Quickstart for how to create a key.
export OPH_API=http://localhost:4318export OPH_KEY=oph_your_key_hereCopy this to your agent
Section titled “Copy this to your agent”You are building against the Openpipe Health API: public data on US healthcare, mostly from CMS (clinicians, hospitals, health systems, care sites, group practices, procedures, drugs, Medicare payers, ACOs, trial investigators, industry payments). Use REST endpoints, a plain-English question endpoint that returns a dashboard as JSON, or MCP tools. Nothing accepts SQL: never send any.
DOCS (plain Markdown)- Index of pages and the full endpoint list: https://YOUR_DOCS_HOST/docs/llms.txt- Everything in one file: https://YOUR_DOCS_HOST/docs/llms-full.txt (shorter: llms-small.txt)- Any page: its path plus .md, for example https://YOUR_DOCS_HOST/docs/api/ask.mdFetch an endpoint's page for its full parameters.
SETUP- The base URL is in the environment variable OPH_API, the API key in OPH_KEY. Never ask me to paste the key, never print or commit it. If either is unset, stop and ask me.- Send on every request: Authorization: Bearer $OPH_KEY- Errors are JSON, {"error": "message"}. Branch on the HTTP status.- Results are in "rows". Some numbers arrive as JSON strings (npi, sums, money): parse them, but keep npi a string.
ENDPOINTS (relative to $OPH_API; GET and 1 credit unless noted)- Free: /api/health, /api/meta, /api/me (credits.used, credits.limit), /api/catalog (what each dataset and column means).- /api/procedures?q=knee: HCPCS/CPT codes.- /api/providers: clinicians and organizations that billed Medicare. Filters: q, state, city, specialty. hcpcs=CODE ranks by volume of that procedure; add specialty to keep assistants out of a surgeon list.- /api/facilities: hospitals. Filters: q, state, min_beds, private_equity=true. /api/groups: group practices.- /api/providers/:npi, /api/facilities/:ccn, /api/groups/:id: one full record.- /api/hospital-intel: hospitals by EHR vendor (ehr), star rating (min_rating), health system (system) or volume in one MS-DRG (drg). /api/health-systems: systems. One hospital: /api/facilities/:ccn/intel, /clinicians, /measures, /drgs. Where a clinician works: /api/providers/:npi/facilities.- /api/care-sites: nursing homes, home health, hospices, dialysis, surgery centers, clinics. Filters include type, state, chain, private_equity, min_stars. One site: /api/care-sites/:id, /:id/owners.- /api/market/drugs?drug=Eliquis: one drug by state, Medicare Part D next to Medicaid. /api/market/drugs/spending: national spending by year. drug is an exact brand or generic name.- /api/market/payers, /api/market/payers/counties/:fips, /api/market/plans: Medicare Advantage and Part D enrollment by parent company, and plans. /api/market/acos, /api/market/acos/:id: Shared Savings Program ACOs.- /api/market/experts?condition=melanoma&state=TX: clinicians ranked by trials led. /api/market/experts/:npi: trials, NIH grants, industry payments.- POST /api/ask, body {"question": "..."}, header Accept: application/json: 25. Takes 5 to 30 seconds. Returns id, title, summary, tiles (each with columns, rows, sources, sql), failed, usage.- /api/dashboards, /api/dashboards/:id: free. Every answer is stored; reopen it by id.- POST /api/exports: 10. A CSV of up to 500,000 rows. The body is a reference: {"list": "providers" | "facilities" | "groups", "params": {search filters as typed JSON}} or {"dashboard": "<id from ask>", "tile": 0}.Searches take limit (default 25) and offset. state is a two-letter code. A 400 or 404 is free; a search that returns zero rows is charged. /api/hospital-intel, /api/health-systems and /api/care-sites reject an unknown parameter with 400; other searches ignore it.
HOW TO CHOOSE- A filtered list or one record: a search or lookup (1). Try this first.- A count, total, breakdown, comparison, or a ranking the searches do not sort on: POST /api/ask (25). Name the procedure (with its HCPCS code), drug, specialty and state.- More rows than a page or a tile holds: POST /api/exports (10).
CREDITS AND LIMITS- Credits are a monthly workspace allowance. Metered responses carry "usage": {"credits", "creditsUsed", "creditsLimit"}. Ask me before calling /api/ask or /api/exports.- HTTP 502 with "charged": false from ask means nothing was charged: rephrase. If your connection drops, do not ask again: find the stored answer with GET /api/dashboards.- 402: out of credits. Do not retry; tell me.- 429: wait the seconds in the Retry-After header, then retry. Per minute: 300 requests, 10 asks, 10 exports, 120 over MCP.- 400: fix the request; the message says how. 401: bad key; ask me.
MCP (prefer it to REST if you support MCP)- Endpoint: $OPH_API/mcp. Streamable HTTP, the same key as a static header, no OAuth.- 27 tools: search_*, get_* and list_* tools for the routes above (1 each), ask (25), list_datasets and describe_data (free). tools/list has the schemas. Arguments are typed JSON: numbers and booleans, not strings. Exports are REST only.- Claude Code: claude mcp add --transport http openpipe "$OPH_API/mcp" --header "Authorization: Bearer $OPH_KEY"
RECEIPTSData responses include the SQL the server ran ("sql"), its values ("params") and the datasets read ("sources"). They are receipts. Show them with any number you show me. For an ask answer, also show its "summary".
DATA CAVEATS- Volumes, patients and payments are Medicare fee-for-service only, 2024. Rank and compare with them; never call them totals. Nothing is commercial insurance.- Market responses name their population in "population". Medicaid amounts are before rebates.- Small counts are withheld (under 11 patients, discharges or prescriptions). NULL is not zero.- Hospital EHR is a 2024 attestation; no value means unknown. Clinician-hospital affiliations come from claims, at most five hospitals each: not a staff roster.- NPIs on trials and NIH grants are name matches. Verify "match_confidence": "medium" before outreach.
FIRST TASK (2 credits). Run these now and show me the rows with their receipts:1. curl -s "$OPH_API/api/health"2. curl -s "$OPH_API/api/procedures?q=knee%20arthroplasty&limit=3" -H "Authorization: Bearer $OPH_KEY"3. curl -s "$OPH_API/api/providers?hcpcs=27447&state=TX&specialty=orthopedic&limit=3" -H "Authorization: Bearer $OPH_KEY"Then ask me what I want to build. If it needs /api/ask, tell me the question and that it costs 25 credits, and wait for my go-ahead.The same text is served on its own at /docs/agent-prompt.txt, so you can also pipe it:
curl -s https://YOUR_DOCS_HOST/docs/agent-prompt.txtWhat the prompt asks the agent to do first costs 2 credits: two searches. The health check is free. The agent is told to check with you before it spends 25 credits on a question.
Use the MCP server
Section titled “Use the MCP server”If your agent speaks the Model Context Protocol, connect it to the MCP server and it gets 27 tools over the same data, at the same prices, with no HTTP code to write. Two of them are free and worth calling first: list_datasets shows what is loaded, and describe_data says what every dataset and column means. For anything the search tools cannot express, the ask tool takes a plain-English question and returns a finished dashboard as JSON for 25 credits.
claude mcp add --transport http openpipe "$OPH_API/mcp" \ --header "Authorization: Bearer $OPH_KEY"The server takes an API key in a static header. It does not support OAuth sign-in, and exports are not available over MCP.
Give your agent the whole docs
Section titled “Give your agent the whole docs”Three files follow the llms.txt convention. All are plain Markdown, generated from these pages on every build.
| File | Contents | Use it when |
|---|---|---|
/docs/llms.txt |
An index: one line per page, linking to its Markdown version | The agent can fetch pages as it needs them |
/docs/llms-small.txt |
The essentials in one file: quickstart, authentication, credits, errors and rate limits, every endpoint, MCP, Ask and exports, the tables and the caveats | You want one paste that fits comfortably in context |
/docs/llms-full.txt |
Every page, in reading order | You want nothing left out |
curl -s https://YOUR_DOCS_HOST/docs/llms-full.txtFetch one page as Markdown
Section titled “Fetch one page as Markdown”Every page has a Markdown version at the same path with .md in place of the trailing slash. The home page is /index.md. Each page links to its own under the title.
| Page | Markdown |
|---|---|
/quickstart/ |
/quickstart.md |
/api/ask/ |
/api/ask.md |
/data/tables/ |
/data/tables.md |
/ |
/index.md |
curl -s https://YOUR_DOCS_HOST/docs/api/providers.mdPages also declare it in their HTML, for tools that look there:
<link rel="alternate" type="text/markdown" href="/docs/api/providers.md">Set up your tool
Section titled “Set up your tool”Claude Code
Section titled “Claude Code”Add the MCP server once, from the shell where OPH_API and OPH_KEY are set:
claude mcp add --transport http openpipe "$OPH_API/mcp" \ --header "Authorization: Bearer $OPH_KEY"Then add this to the CLAUDE.md at the root of your project, so every session starts with the rules:
## Openpipe Health API
- Docs index: https://YOUR_DOCS_HOST/docs/llms.txt (every page is Markdown; fetch what you need). What every column means: https://YOUR_DOCS_HOST/docs/data/tables.md- Base URL is in `OPH_API`, the key in `OPH_KEY`. Read them from the environment. Never print, log or commit the key.- Use the `openpipe` MCP tools when they are connected. Otherwise call REST with `Authorization: Bearer $OPH_KEY`.- Search and lookup first. For a count, ranking or comparison they cannot give, use `ask` (REST: `POST /api/ask` with `Accept: application/json`). Never send SQL: nothing accepts it.- Costs: search and lookup 1 credit, export 10, Ask 25. Check with me before using Ask or exports.- `402` is out of credits: stop and tell me. `429`: wait `Retry-After` seconds, then retry.- Exports take a reference, not SQL: `{"list", "params"}` or `{"dashboard", "tile"}`.- Show the `sql` and `sources` from the response next to any number you report.- Volumes are Medicare fee-for-service only, and counts under 11 are withheld. Never call them totals.Cursor
Section titled “Cursor”Save the rules as .cursor/rules/openpipe.mdc:
---description: Rules for calling the Openpipe Health APIalwaysApply: true---
- Docs index: https://YOUR_DOCS_HOST/docs/llms.txt (every page is Markdown; fetch what you need). What every column means: https://YOUR_DOCS_HOST/docs/data/tables.md- Base URL is in `OPH_API`, the key in `OPH_KEY`. Read them from the environment. Never print, log or commit the key.- Use the `openpipe` MCP tools when they are connected. Otherwise call REST with `Authorization: Bearer $OPH_KEY`.- Search and lookup first. For a count, ranking or comparison they cannot give, use `ask` (REST: `POST /api/ask` with `Accept: application/json`). Never send SQL: nothing accepts it.- Costs: search and lookup 1 credit, export 10, Ask 25. Check with me before using Ask or exports.- `402` is out of credits: stop and tell me. `429`: wait `Retry-After` seconds, then retry.- Exports take a reference, not SQL: `{"list", "params"}` or `{"dashboard", "tile"}`.- Show the `sql` and `sources` from the response next to any number you report.- Volumes are Medicare fee-for-service only, and counts under 11 are withheld. Never call them totals.And the MCP server in .cursor/mcp.json. Replace YOUR_HOST with the host of your base URL:
{ "mcpServers": { "openpipe": { "url": "https://YOUR_HOST/mcp", "headers": { "Authorization": "Bearer ${env:OPH_KEY}" } } }}${env:OPH_KEY} tells Cursor to read the key from its environment. If your version of Cursor does not fill it in, put the key in the file and keep the file out of git.
Any other agent
Section titled “Any other agent”Paste the prompt at the start of the session. If the agent cannot browse, paste the contents of /docs/llms-small.txt after it. If it has no shell, give it an HTTP tool and the two values some other way than the conversation, such as its secrets or environment settings.
The API itself needs nothing agent-specific. It is plain HTTPS and JSON:
curl "$OPH_API/api/providers?hcpcs=27447&state=TX&limit=3" \ -H "Authorization: Bearer $OPH_KEY"What an agent must get right
Section titled “What an agent must get right”The prompt covers these. They are the rules worth checking in whatever your agent builds.
| Rule | Why | Details |
|---|---|---|
Read the key from OPH_KEY |
A key in a chat or a commit can spend your workspace’s credits | Authentication |
Do not retry 402 |
The workspace is out of credits until the month resets or the limit is raised | Credits |
On 429, wait Retry-After seconds |
Limits are per minute, and a request that is rejected still counts | Rate limits |
| Search first, ask second, never send SQL | A search is 1 credit and a question 25, and no endpoint accepts SQL | Ask |
| Do not ask again after a dropped connection | The answer is charged and stored whether or not the client is listening | Ask |
Show sql and sources with each number |
That is how a person checks the answer | Receipts |
| Never present a volume as a total | The data is Medicare fee-for-service only | Caveats |