On this page
- Break latency into network and model phases
- What “connection reuse” means
- DNS can be cached separately from the connection
- TLS handshakes have real cost
- HTTP/1.1 keep-alive can reuse a connection
- HTTP/2 changes concurrency behavior
- HTTP/3 uses QUIC
- One origin does not imply one permanent connection
- Do not rely on connection identity for application state
- Mobile networks make reuse less predictable
- App backgrounding can break warm-state assumptions
- Custom endpoints can create many connection pools
- Base URL normalization matters
- Redirects can add latency and alter trust boundaries
- Session/client reuse matters at the application layer
- Do not keep broken connections alive manually
- Connection reuse can improve TTFT, not just total duration
- Keep TTFT and network setup separately observable
- Large uploads can dominate before generation starts
- HTTP multiplexing does not remove provider concurrency limits
- Too much concurrency can hurt one shared connection
- Keep-alive is not a reason for synthetic ping traffic by default
- Local LAN connections have their own cold costs
- TLS session resumption is an optimization, not a correctness dependency
- Connection pooling and credentials
- Custom protected headers must survive retries/reconnections correctly
- Connection reuse interacts with benchmarks
- Do not overfit to localhost benchmarks
- A useful request timing model
- Test cold and warm paths
- A connection-reuse checklist
- Where BYOKchat fits
- Further reading
Two requests to the same AI model can have noticeably different latency even when the model behaves identically.
One reason is connection setup.
A cold request may need to perform work such as:
DNS lookup
transport connection
TLS handshake
HTTP session establishment
request transmission
A later request can sometimes reuse an existing healthy connection and skip much of that setup.
For latency-sensitive streaming chat, that can improve the time before the provider even begins model work.
Break latency into network and model phases
A simplified request timeline is:
DNS
+ connect
+ TLS
+ request upload
+ provider queue/prompt processing
+ first token
+ generation
Connection reuse mainly affects the early network phases.
It does not make the model itself reason faster.
This distinction is important when diagnosing TTFT.
What “connection reuse” means
HTTP is semantically stateless, but clients and servers can reuse transport connections for multiple requests.
Instead of:
request 1 -> open connection -> send -> close
request 2 -> open connection -> send -> close
an HTTP client can often do:
open connection
request 1
request 2
request 3
...
subject to protocol, server, network, and connection-pool behavior.
DNS can be cached separately from the connection
Even if a prior connection is gone, the system may still have a usable DNS result.
That means latency phases can be partially reused:
DNS cached
new TCP/TLS required
or:
connection already healthy
no new DNS/connect/TLS on this request
Do not treat “warm connection” as one all-or-nothing state.
TLS handshakes have real cost
HTTPS requires authenticated secure transport before ordinary API data can flow.
A new secure connection can therefore add round trips and cryptographic work.
Modern TLS and transport protocols have optimizations, but a fresh connection still has more setup than reusing an already-established one in many cases.
For BYOK clients, disabling TLS to chase lower latency on public networks is not an acceptable optimization.
See Certificate Validation for Custom AI Endpoints.
HTTP/1.1 keep-alive can reuse a connection
With persistent HTTP/1.1 connections, sequential requests can often reuse the same connection instead of reconnecting each time.
However, concurrency on one HTTP/1.1 connection has limitations, so networking stacks may maintain a pool of connections.
Applications should generally let the platform HTTP client manage this rather than manually implementing sockets.
HTTP/2 changes concurrency behavior
HTTP/2 can multiplex multiple streams over one connection.
That means several independent requests to the same eligible origin can share one underlying connection rather than requiring one connection per request.
This can reduce connection setup overhead and improve connection utilization.
It does not guarantee that every request has identical latency: provider queues, stream flow control, network conditions, and model work still vary.
HTTP/3 uses QUIC
HTTP/3 runs over QUIC rather than TCP.
It changes transport setup and multiplexing characteristics and can behave better under some packet-loss/path-change conditions.
But application code should not assume:
HTTP/3 always faster
Actual benefit depends on network, server support, connection reuse, cache state, and workload.
Use platform networking and measure real request phases.
One origin does not imply one permanent connection
Connections can close because of:
server idle timeout
client pool policy
network path change
app suspension
load balancer behavior
NAT timeout
proxy/VPN change
errors
A connection pool is dynamic.
Your AI client should be correct whether a request uses a reused connection or a new one.
Do not rely on connection identity for application state
HTTP semantics do not guarantee:
same TCP/QUIC connection = same user/session
Authentication and request state belong in appropriate protocol/application fields.
This matters for custom AI proxies that are tempted to keep hidden state tied only to a socket.
Mobile networks make reuse less predictable
A phone can move between:
Wi-Fi
cellular
VPN
private relay/proxy paths
hotspot
The old connection may become unusable when the path changes.
Networking frameworks can establish a new connection on the new route.
Do not interpret that setup cost as a provider performance regression without considering network context.
App backgrounding can break warm-state assumptions
An iOS app may be suspended after moving to the background.
By the time it resumes, previously warm connections may have closed or become stale.
The first request after foregrounding can therefore behave like a cold request.
See How to Handle App Backgrounding During AI Generation.
Custom endpoints can create many connection pools
A BYOK client may connect to:
api.openai-like provider A
provider B
OpenRouter
local Mac server
private Tailscale host
custom company proxy
Each origin/network path has separate connection behavior.
Switching providers can incur a fresh connection even if the previous provider was warm.
This is one reason provider switching can change TTFT independent of model speed.
Base URL normalization matters
Accidentally varying semantically equivalent endpoint origins can defeat reuse or create confusing pools.
Examples to handle carefully include:
host casing
explicit default ports
redirecting base URLs
multiple aliases for same server
The platform HTTP stack determines actual reuse behavior, but your connection model should keep canonical endpoint configuration stable.
Redirects can add latency and alter trust boundaries
If every API request starts at one URL that redirects to another, the client may pay extra round trips.
For credential-bearing AI APIs, redirects also require security review because forwarding protected headers to a different origin can leak secrets.
Prefer the final documented API endpoint rather than relying on redirects for custom provider configuration.
See How to Handle Untrusted AI-Generated URLs for broader URL trust principles.
Session/client reuse matters at the application layer
A common performance mistake is creating a brand-new HTTP client/session object for every AI request when the platform expects sessions to be reused.
A long-lived networking layer can let the platform maintain:
connection pools
DNS cache integration
TLS session state
HTTP/2 or HTTP/3 negotiation
proxy configuration
The exact mechanics are framework-dependent, but the architectural rule is simple:
Reuse the platform networking client for compatible requests instead of rebuilding the entire stack per token stream.
Do not keep broken connections alive manually
Connection reuse is an optimization owned by the transport stack.
If a connection is unhealthy, the stack should replace it.
Avoid homegrown logic such as:
force every request through this socket forever
That creates brittle failure recovery and often duplicates work the HTTP implementation already handles.
Connection reuse can improve TTFT, not just total duration
For streaming generation, the first visible token cannot arrive until request setup and provider processing are complete.
If a cold connection adds 200ms of setup, TTFT includes that 200ms.
A warm request can remove some setup and reach the provider sooner.
That does not change token generation speed after the stream starts.
See Measuring Time to First Token Correctly.
Keep TTFT and network setup separately observable
If possible, measure:
DNS duration
connect duration
TLS duration
request upload
first response
first token
Then a slow request can be attributed more accurately.
Examples:
slow DNS, normal model
normal network, slow provider TTFT
fast TTFT, slow decoding
Without phase metrics, all three look like “AI is slow.”
Large uploads can dominate before generation starts
Attachments, images, audio, or a very large JSON context can make request upload time nontrivial.
Connection reuse cannot eliminate payload transmission.
When investigating TTFT, account for:
request body size
attachment upload strategy
provider file-upload phase
Some APIs upload files separately and then reference provider file IDs; others accept inline data.
These workflows have different network profiles.
HTTP multiplexing does not remove provider concurrency limits
Even if HTTP/2 can send many requests over one connection, the provider can still enforce:
account rate limits
model concurrency
quota
capacity controls
Transport concurrency and service concurrency are different layers.
A request queue should still enforce appropriate policy.
See How to Build an AI Request Queue.
Too much concurrency can hurt one shared connection
Multiplexing avoids some connection overhead, but it does not create infinite bandwidth.
Large concurrent streams share network capacity and can interact through flow control and device resources.
If ten generations stream simultaneously on a constrained mobile network, each may become less responsive.
Bound concurrency based on product needs rather than assuming multiplexing is free.
Keep-alive is not a reason for synthetic ping traffic by default
Some applications send frequent pings just to keep a connection warm.
For ordinary HTTPS AI APIs, that can waste:
battery
bandwidth
provider quota if using real API calls
radio wakeups
Let the networking stack manage idle connections unless the protocol explicitly defines heartbeat requirements.
For a stream already in progress, provider heartbeat events are a different concept from artificial client traffic.
Local LAN connections have their own cold costs
A local AI server avoids internet distance but may still have:
DNS/mDNS resolution
LAN connection setup
TLS if configured
model cold load
prompt processing
Often the model load dominates more than the network.
Do not assume:
local = zero latency
See Local AI on Apple Silicon: What Client Developers Need to Know.
TLS session resumption is an optimization, not a correctness dependency
TLS implementations can reduce handshake work for returning connections through resumption mechanisms.
Applications generally should not build product logic around whether resumption happened.
Treat it as a transport optimization and measure actual timing rather than assuming availability.
Connection pooling and credentials
A multi-account client can send different authenticated HTTP requests over pooled transport connections as allowed by the HTTP stack.
Application credentials remain per request.
Do not bind API-key identity to a connection object and assume every future request on that connection uses the same account.
Keep credentials isolated in the request/auth layer.
Custom protected headers must survive retries/reconnections correctly
If the transport opens a new connection, request construction should still add the correct protected headers for that connection configuration.
Secrets should not be cached in debug logs simply because network reconnection is being diagnosed.
See How Mobile Apps Should Store AI API Keys.
Connection reuse interacts with benchmarks
If you compare two models/providers, decide whether you are measuring:
cold first request
warm steady-state requests
mixed real-world traffic
A test that warms provider A but not provider B is not a fair network-latency comparison.
Record enough request phase data to explain the setup conditions.
Do not overfit to localhost benchmarks
A web or desktop test against localhost may show negligible connection cost.
That says little about:
mobile cellular path
cross-region provider
corporate proxy
VPN
public Wi-Fi
Performance architecture should remain correct across network environments.
A useful request timing model
On a reused connection, some early phases may collapse or become effectively zero for that request.
The later model phases still remain.
Test cold and warm paths
Useful tests include:
first request after launch
second request to same provider
parallel requests to same provider
request after idle period
request after Wi-Fi/cellular switch
request after app background/resume
request after TLS/network error
request to custom provider alias
request to local LAN server
Verify correctness first, then compare phase timing.
A connection-reuse checklist
- The app reuses a long-lived platform HTTP client/session where appropriate.
- Correctness does not depend on one connection staying alive.
- DNS/connect/TLS timing is separated from model TTFT where possible.
- HTTP/2/HTTP/3 are treated as transport capabilities, not magic latency guarantees.
- Mobile network changes and backgrounding invalidate warm assumptions.
- Redirects do not leak protected credentials across origins.
- Provider/account concurrency remains bounded independently from transport multiplexing.
- Local model load time is not confused with LAN setup time.
- Benchmarks distinguish cold and warm paths.
- Credentials remain request-scoped rather than connection-identity state.
Where BYOKchat fits
A multi-provider client benefits from one shared networking layer per platform that can reuse connections naturally while provider adapters remain responsible for request/stream semantics. Sanitized timing can separate network setup from provider TTFT and generation speed, making performance comparisons far more useful than one total-duration number.
For custom and local endpoints, the same design remains valid: ordinary platform TLS and connection pooling where applicable, explicit private-network exceptions only when configured, and no dependence on a particular socket surviving.