With a web page, the browser papers over a lot: a spinner, a skeleton screen, a progressive render all make 500ms feel acceptable. An API has none of that. The thing on the other end is a machine that blocks until you answer, often inside a chain of three more calls, and every millisecond you spend lands directly in someone else's UX budget. That's why API latency targets are tighter than page targets, and why you judge an endpoint by the p95 its consumers see rather than by how fast it feels.
Latency targets by endpoint class
| Endpoint type | Good p95 | Acceptable | Problem |
|---|---|---|---|
| Auth (login, token refresh) | < 200ms | 200-500ms | > 500ms |
| UI-blocking read | < 200ms | 200-500ms | > 500ms |
| Search / filter | < 300ms | 300-500ms | > 500ms |
| Write (create / update) | < 500ms | 500ms-1s | > 1s |
| Background receipt (webhook) | < 500ms | 500ms-2s | > 2s |
Why API latency is tighter than page latency
Three reasons:
- No perceptual masking. A browser showing a loading spinner at 500ms feels fine. A mobile app waiting on your API at 500ms feels janky.
- Chained calls. A single screen in a client app often fires 3-5 API calls. Made one after another at 200ms each, they add up to 600-1000ms of perceived latency.
- Consumers can't batch for you. A web server can render server-side and send one response; a consumer SDK makes calls one at a time unless you offer batching endpoints.
Middleware for API-specific timing context
app/Http/Middleware/ApiTiming.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class ApiTiming
{
public function handle(Request $request, Closure $next): Response
{
$start = hrtime(true);
$response = $next($request);
$durationMs = (hrtime(true) - $start) / 1e6;
$response->headers->set('Server-Timing', 'total;dur='.round($durationMs, 1));
return $response;
}
}
Attach it to your API routes in bootstrap/app.php with $middleware->api(append: [ApiTiming::class]) inside withMiddleware(). Browser dev tools read the Server-Timing header (Chrome shows it on a request's Timing tab in the Network panel), which helps consumer-side debugging without exposing full trace data.
Per-endpoint trace drilldown
For a slow endpoint:
- Open the requests dashboard, filter to the route pattern
- Use the ≥P95 filter (or ≥P99) to list the route's slow requests
- Open a slow request's trace view
- Identify the dominant span, usually a DB query or outgoing HTTP call
- Fix that one thing (eager load, add index, move to async) and watch p95 drop
See our related guides: slow query monitoring, N+1 detection, outgoing HTTP tracking.
Budget for network
A consumer in Europe calling your US-East API can spend 70ms or more on each network round trip, before TLS setup. That's budget you can't compress with code. If your end-to-end API SLO is 300ms and network is 100ms, your server-side budget is 200ms. Plan accordingly.