Skip to main content
By default AnyAPI picks the cheapest source that can serve your request, and falls back to the next if it fails. On many APIs the cheapest source is also much slower. Use preferLatencyUnderMs when waiting costs you more than the price difference.

The default: cheapest serves

Without the field, the cheapest source serves and you are charged its price.

Prefer a faster source

Add preferLatencyUnderMs to the request body, in milliseconds:
AnyAPI then orders the sources for your request like this:
  1. Sources whose published median response time is under your target go first, and the cheapest of those serves.
  2. If none is that fast, the request is still served, by whichever source offers the best speed for its price.
  3. Sources we have not timed are tried last.
Your request is never refused for being slow. The field changes the order sources are tried in and removes none of them, so failover works as it does without it.

It can cost more

When the cheapest source misses your target, a faster and dearer one serves, and you are quoted and charged its price. You can compare before you call, without a key. GET /catalog publishes each source’s pricing next to health.latencyP50Ms, the median routing reads:
With no preference, Badger serves at 0.0009acallanda 10.8secondmedian.With‘preferLatencyUnderMs:1000‘,Tigerservesat0.0009 a call and a ~10.8 second median. With `preferLatencyUnderMs: 1000`, Tiger serves at 0.0012 and a ~0.5 second median, so you pay 33% more and wait about a twentieth as long. Giraffe has no median published, so it sorts last under a preference. On a few APIs that mix per-result and per-request sources, which source carries which price depends on how many results you ask for, so a source can charge the amount another source’s published price comes to for your request. That amount is fixed before the call and does not drop if fewer results come back. A price quote for your exact request is the authority. A target that no source beats costs you nothing extra, because the ordering you get is the cheapest-first one you already had.
The median describes past requests. It is not a ceiling on yours, and it excludes any waiting your own request asks for, such as a waitFor on a page render. Treat it as an observation, not a deadline.

When it does nothing

The field is accepted on every API and does nothing in these cases: A cursor pins the walk to one source. See Pagination.

Example

Compare costUsd on calls with and without the field to see the trade in your own numbers.