A FHIR search against an Epic organization can return a handful of results or thousands: every observation for a patient with a long history, every appointment in a department, every document in a chart. Servers do not send all of that in one response. They send a page and a link to the next one, and an integration that handles that link carelessly will miss data, repeat it or stall halfway through.
This guide explains pagination in Epic FHIR APIs for developers: how FHIR paging works, how to follow it safely, how to choose page sizes, how to handle errors and large pulls, and the mistakes we see in production integrations. It follows the FHIR standard and tells you where to test behaviour against your own Epic endpoints.
What is pagination in Epic FHIR APIs?
Building against Epic's FHIR APIs?
Agnotic builds Epic FHIR integrations that handle paging, limits and errors in production.
Pagination in Epic FHIR APIs is how search results too large for one response are split into pages. Each response is a FHIR Bundle holding one page of results and, when more remain, a link with the relation "next" that the client calls to get the following page. The client keeps following next links until a response has none.
This is standard FHIR behaviour rather than an Epic invention, which is good news: code written to the standard works across EHRs, as long as it does not rely on any one server's quirks.
How does FHIR paging work?
FHIR defines paging in its RESTful API and search specifications, and both points below come straight from them.
- Bundle links: In FHIR R4, search results come back as a Bundle of type searchset, and paging links such as first, previous, next and last are carried in Bundle.link.
- Page size: The _count search parameter tells the server how many results the client wants per page. Under FHIR R4, servers must not return more than requested but may return fewer.
Two consequences follow. A short page does not mean the results are finished, and the server, not the client, decides how pages are formed.
How should a client follow next links?
A client should call the next link exactly as the server returned it, process the page, and repeat until no next link appears. The link is opaque: do not parse it, change it or build your own.
- 1. Send the search: With the parameters and page size you want.
- 2. Process entries: Handle each resource in the Bundle, skipping any that are not search matches.
- 3. Find the next link: Look for the link whose relation is next.
- 4. Call it as given: Use the full URL, with the same access token rules.
- 5. Stop correctly: End only when a response has no next link.
Entries in a searchset can include resources added by _include or outcome messages. Check each entry's search mode so included resources are not counted as matches.
How should you choose a page size?
Choose a page size that balances fewer requests against response time and memory, then test it against your Epic environment. Treat your requested size as a ceiling, not a promise.
- Start moderate: A mid-sized page is a safe default while you test.
- Measure: Record response times and payload sizes for your real queries.
- Respect limits: Large pages can hit timeouts or server caps, so watch for errors.
- Do not assume: Never treat a short page as the end of results.
Why should you not rely on totals?
Bundle.total is optional in FHIR, and servers may leave it out or give an estimate. Code that loops a fixed number of times based on a total can stop early or run past the end.
- Loop on links: Use the presence of a next link, not a count, to control paging.
- Totals for display only: If a total appears, use it for progress bars, not logic.
- Count what you receive: Track resources processed so you can compare runs.
How should errors and retries work?
Errors in the middle of a paged search are common in production: expired tokens, rate limits, timeouts and temporary server errors. Design so a failure on page twelve does not restart the whole pull or lose pages.
- Token refresh: Refresh access tokens before they expire during long pulls.
- Rate limits: Back off and retry when the server signals too many requests.
- Transient errors: Retry with increasing delays, up to a limit.
- Checkpoints: Record the last completed page so a job can resume.
- Idempotent processing: Make processing safe to repeat if a page is fetched twice.
Paging links may expire after some time on some servers. If a resume fails because a link is no longer valid, restart the search and rely on idempotent processing to skip duplicates.
What about very large data pulls?
Paging through FHIR search is meant for interactive and moderate workloads. For whole populations or very large histories, consider bulk export where the server supports it, or narrow searches with filters.
- Filter first: Use date ranges, categories and status filters to reduce result sets.
- Split by patient: Page through per-patient searches rather than one huge query.
- Bulk export: For populations, use FHIR bulk data export where it is available to your app.
- Schedule: Run large pulls off-peak and within agreed limits.
How should incremental syncs use paging?
Most integrations do not need every record every time. An incremental sync asks only for what changed since the last run, which means fewer pages, faster runs and less load on the customer's Epic environment.
- Date filters: Use search parameters on dates or last updated values where the resource and server support them.
- Watermarks: Store the time each successful run started, and use it as the lower bound for the next run.
- Overlap window: Start each run a little before the last watermark to catch late updates, and rely on idempotent processing to ignore repeats.
- Periodic full check: Run a full reconciliation now and then to catch anything incremental runs missed.
Check which date parameters each resource supports in your Epic environment before designing around them. Support varies by resource and version.
What should you monitor in production?
Monitor paged jobs per customer and per resource type, so a problem in one Epic environment does not hide in overall numbers.
- Pages per run: A sudden change can signal a filter or configuration problem.
- Resources per run: Compared with previous runs to spot missing data.
- Run duration: Long runs may hit token expiry or off-peak limits.
- Errors by type: Authentication, rate limit and server errors tracked separately.
- Incomplete runs: Jobs that stopped before the last page, with alerts.
How do you test paging against Epic?
Test paging in Epic's sandbox and then in each customer's environment, since data volumes and configuration differ. Build tests that force multiple pages.
- Small page size: Force paging on small result sets to exercise your loop.
- Short pages: Confirm your code continues when a page has fewer results than requested.
- Interrupted runs: Simulate token expiry and errors mid-pull.
- Included resources: Test searches with _include to check match counting.
- Real volumes: Test with realistic patient histories before go-live.
What are the common pagination mistakes?
The common mistakes come from assuming one response holds everything and from building page URLs by hand.
- Ignoring next links: Reading only the first page and missing data.
- Stopping on short pages: Ending when a page has fewer results than requested.
- Building URLs: Constructing offsets instead of following the server's link.
- Looping on totals: Using Bundle.total to control the loop.
- No resume: Restarting large pulls from page one after any error.
- Counting included resources: Treating _include results as matches.
What are best practices for Epic FHIR pagination?
The practices that hold up are simple and standard: follow links, never assume, and design for interruption.
- Follow next links as returned until none remain.
- Treat page size as a ceiling and short pages as normal.
- Ignore totals for control flow.
- Checkpoint progress and make processing idempotent.
- Use filters, per-patient searches or bulk export for large data.
- Test with forced paging and interrupted runs.
How Agnotic can help
Agnotic Technologies builds Epic FHIR integrations for digital health companies and health systems. We build paging, retry, checkpoint and monitoring into the integration layer, so your product gets complete data without duplicate or missing records, even when pulls are interrupted.
If you have an existing integration that misses data or times out, we can review how it pages and fix it.
Get complete data from Epic, every time
Talk to our engineers about Epic FHIR integration, or read more FHIR articles in the hub.
Related reading on Agnotic
See how Epic's FHIR APIs work, how SMART on FHIR scopes are set, how FHIR integration is planned and how Epic scheduling APIs behave.


