Freshness and caching
Live fetch timeout: set it from your users' wait budget
Pick a total deadline for each live page read from how long your users can wait, set connect and read limits under it, and decide what happens when it runs out.
By Curtis Mccann, Live Web Data team · Published
This article was drafted with AI assistance from the sources listed below and edited and published by the Live Web Data team. Disclosure: the Live Web Data API, which this article mentions, is this site's own product.
- 1Start from the waitAbout 10 seconds is the limit for keeping a user's attention on one task.
- 2Subtract model timeWhat is left after your model's own answer time is the deadline for the page read.
- 3Check it against p95Compare that deadline with the 95th percentile of your own live reads.
- 4Enforce one total deadlineConnect and read timeouts measure waits, not the whole read; wrap the call in a deadline.
- 5Decide the expiry pathAnswer with a dated stored copy, or answer without the page and say so.
A live page read is the one step in an answer whose time you do not control. The site decides how fast it answers, and your user waits for both the site and the model. The timeout is where you decide how much of that wait the page gets.
The guide on live vs cached web data says to set a timeout that fits how long your users can wait. This post turns that into a number and a code path for when it runs out.
Start from the wait, not from the site
Decide the total wait first, then give the page its share. Nielsen Norman Group's response time limits are a useful frame: about 0.1 second feels instant, about 1 second keeps the user's flow of thought, and about 10 seconds is the limit for keeping attention on the task. Past 10 seconds, the same article says users need feedback on when the work will finish, such as a percent-done indicator, and a clear way to interrupt.
A chat answer that reads a live page rarely fits in 1 second, so 10 seconds is the ceiling that matters. A worked example, with assumptions labelled:
- Ceiling for the whole answer: 10 seconds.
- Your model's time to a complete answer, measured on your own prompts: assume 4 seconds.
- Left for the page read: 10 - 4 = 6 seconds.
Now hold those 6 seconds against what your sources actually do. The post on live fetch vs cache latency shows how to measure the 95th percentile of live reads per source. If your p95 is under 6 seconds, a 6-second deadline cuts off only the slow tail. If it is over 6 seconds, the deadline will fail more than 1 in 20 reads of that source: either stream progress to the user and allow more time, or plan to read that source ahead of the question.
Why client defaults do not give you a deadline
Check what your HTTP client does when you set nothing. The defaults differ widely:
- Python requests: no timeout at all. Its docs say requests do not time out unless a timeout value is set explicitly, and that without one your code may hang for minutes or more.
- HTTPX: raises a
TimeoutExceptionafter 5 seconds of network inactivity. - undici: its
ClientdocumentsheadersTimeoutandbodyTimeoutdefaults of300e3milliseconds, which is 300 seconds, and aconnectTimeoutdefault of10e3, which is 10 seconds.
The bigger issue is what these timeouts measure. In requests, the read timeout is the number of seconds the client waits between bytes from the server, and the docs state that neither the connect nor the read timeout is wall clock time. HTTPX splits its timeout into connect, read, write and pool, and its read timeout is the wait for one chunk of data. undici's bodyTimeout watches the time between body chunks. A page that keeps sending a few bytes at a time never trips any of them.
Connect timeouts have their own trap. The requests docs note that the connect timeout applies to each connection attempt, so a host with both IPv4 and IPv6 addresses that does not respond can take double the time you set. They also suggest a connect timeout slightly larger than a multiple of 3 seconds, the default TCP packet retransmission window, such as 3.05.
So set two layers: per-phase timeouts so a dead host fails fast, and one total deadline around the whole read.
Enforce one total deadline in code
In JavaScript, AbortSignal.timeout() returns a signal that aborts after the given number of milliseconds. MDN documents that it aborts with a TimeoutError DOMException, which lets you tell a deadline apart from other failures:
async function readPage(url, deadlineMs = 6000) {
try {
const res = await fetch(url, { signal: AbortSignal.timeout(deadlineMs) });
if (!res.ok) return { ok: false, reason: `http ${res.status}` };
return { ok: true, text: await res.text() };
} catch (err) {
if (err.name === "TimeoutError") return { ok: false, reason: "timeout" };
throw err;
}
}
console.log((await readPage("https://example.com/")).ok);
Two details from MDN matter here. The timer counts active time rather than elapsed time, so it pauses in a suspended worker or a page in the back-forward cache. And it cannot be cancelled; if you need that, use an AbortController with setTimeout() and call clearTimeout() when the read finishes.
Decide what happens when it runs out
A timeout is only useful if the next step is already decided. Pick one per source, before the first user hits it:
- Answer from a stored copy, with its date. If you keep copies and the copy is within the maximum age for that page type, use it and tell the model when it was fetched.
- Answer without the page, and say so. Give the model a plain note that the page could not be read in time, so it does not present memory as a fresh read.
- Show progress and keep waiting. For sources whose p95 is above your page deadline, show the user that a page is being read and let them stop it, as the 10-second guidance suggests.
Do not retry inside the same user wait by default. A second attempt after a 6-second timeout spends the budget a second time.
Where Live Web Data API fits
If you read pages through Live Web Data API, the same budget applies to the API call. "Every request fetches the page live; there is no cache." livecrawlTimeout caps the wait for the page, and statuses[].fetchedAt gives the fetch time per URL for the copy you pass to the model. "Failed fetches cost 0 credits." The parameter and its limits are in the API reference.
Frequently asked questions
Does the Python requests library have a default timeout?
No. Its docs say requests do not time out unless a timeout value is set explicitly, and that without one your code may hang for minutes or more. Pass timeout as a single number or as a (connect, read) tuple in seconds.
Is a read timeout the same as a limit on the whole page download?
No. In requests, the read timeout is the wait between bytes from the server, and the docs say neither the connect nor the read timeout is wall clock time. HTTPX measures read time per chunk of data as well. A slow page that keeps sending bytes can take far longer than the read timeout.
How long should a live page fetch be allowed to take in a user-facing app?
Work back from the wait. Nielsen Norman Group puts the limit for keeping a user's attention at about 10 seconds. Subtract the time your model needs to answer, then check the remainder against the 95th percentile of your own live reads.
What happens when AbortSignal.timeout() fires during fetch()?
The signal aborts with a TimeoutError DOMException, so the fetch rejects with an error whose name is TimeoutError. MDN notes the timer counts active time, not elapsed time, and that it cannot be cancelled.
Sources
- Response Times: The 3 Important Limits (Nielsen Norman Group) (Documentation)
- Requests: Advanced Usage (Timeouts) (Documentation)
- HTTPX: Timeouts (Documentation)
- undici Client API reference (Documentation)
- AbortSignal.timeout() (MDN) (Documentation)