Standardize the Network,
Not the HTTP Client
Why OkHttp is a strong default on the JVM, how it compares with Apache HttpClient 5, Netty, HTTPX and aiohttp, and why a platform of many services should standardize timeouts, retries and tracing rather than one library.
By Serverless Ventures
Published: November 9, 2026 · Read time: ~8 minutes
The short version
- OkHttp is not just fast. It handles the hard parts of HTTP reliably and the same way every time: connection pooling, HTTP/2, recovery from common network failures, interceptors and streaming.
- The right client depends on the language. On the JVM, OkHttp is an excellent default. In Python, start with HTTPX. In Go, use the standard
net/http. Reach for Netty only when you are building networking infrastructure. - For a multi-service AI platform, standardize the behaviour, not the library. Timeouts, retries, circuit breakers, tracing, auth and streaming matter more than OkHttp versus HTTPX.
- Never blindly retry a POST or an agent action. It may already have run. Use idempotency keys and explicit retry policies.
Why would anyone choose OkHttp?
Picture an AI platform with twenty services talking to each other. Between them they make thousands of HTTP requests: agent-to-agent calls, model inference requests, streamed responses, calls to outside APIs, file uploads and downloads, and long-running connections.
Every one of those requests pays an overhead before any useful work happens. A good HTTP client's job is to pay as little of it as possible, as rarely as possible.
OkHttp optimizes several of these steps, and adds the features you end up building yourself otherwise:
| Feature | Why you care |
|---|---|
| Connection pooling | You stop paying for DNS, TCP and TLS on every request |
| HTTP/2 multiplexing | Many requests share one connection |
| Modern TLS | Connections are secure and efficient, with sensible defaults |
| Automatic recovery | It recovers quietly from common connection problems, such as trying a host's other addresses |
| Interceptors | Authentication, logging and metrics live in one place |
| Streaming | Large responses are read in pieces, not loaded into memory all at once |
| WebSockets | Persistent, two-way connections |
| Response caching | It skips network calls the cache can answer |
HTTP/2 multiplexing deserves a special mention. Instead of opening twenty connections to talk to one service, OkHttp can send twenty concurrent requests over a single HTTP/2 connection. That means fewer handshakes, fewer sockets and better use of the connections you already have.
What are the alternatives?
These are the clients worth considering, across the languages an AI platform tends to use:
| HTTP client | Language | Main strength | Best fit |
|---|---|---|---|
| OkHttp | Java, Kotlin | Connection management, HTTP/2 | JVM and Android applications |
| Apache HttpClient 5 | Java | Deep HTTP configuration | Enterprise Java systems |
| Java HttpClient | Java | Built into the JDK | Standard Java applications |
| Ktor Client | Kotlin | Multiplatform, coroutine-first | Kotlin applications |
| Netty | Java | Asynchronous networking framework | High-performance network software |
| HTTPX | Python | Sync and async in one API | Python services |
| aiohttp | Python | Async client and server | High-concurrency Python services |
| Requests | Python | Simplicity | Straightforward API integrations |
| net/http | Go | Standard library, HTTP/2 built in | Go microservices |
| reqwest | Rust | Async HTTP on Tokio | Rust applications |
OkHttp against its closest competitors
OkHttp vs. Apache HttpClient 5
Both are mature JVM clients. The difference is in how much they ask of you.
| Dimension | OkHttp | Apache HttpClient 5 |
|---|---|---|
| HTTP/2 | Yes | Yes, in the async client |
| Connection pooling | Yes | Yes |
| Async | Yes, with callbacks (enqueue) beside the blocking execute | Yes |
| Configuration | Relatively simple | Extensive |
| Interceptors | Yes | Yes |
| Android | Excellent | Not its focus |
| Enterprise customization | Good | Excellent |
| Complexity | Lower | Higher |
Our preference: OkHttp for straightforward, efficient HTTP. Apache when you need deep enterprise networking customization.
OkHttp vs. Netty
These are not really competitors. Netty is a lower-level asynchronous networking framework; OkHttp is an HTTP client.
| Dimension | OkHttp | Netty |
|---|---|---|
| Abstraction | HTTP client | Networking framework |
| HTTP handling | Built in | Assembled from codecs and handlers |
| Connection management | Built in | More control, more of your code |
| Custom protocols | Limited | Excellent |
| Development effort | Lower | Higher |
Our preference: do not use Netty when all you need is an HTTP client. Use it when you are building networking infrastructure or a custom protocol.
HTTPX vs. aiohttp
Most agent and model code is Python, so this comparison often matters more than any JVM one.
| Dimension | HTTPX | aiohttp |
|---|---|---|
| Synchronous | Yes | No, async only |
| Asynchronous | Yes | Yes |
| HTTP/2 | Yes, with the httpx[http2] extra | No, HTTP/1.1 only |
| API design | Close to Requests | Its own |
| Streaming | Yes | Yes |
| WebSockets | Through add-ons such as httpx-ws | Built in, client and server |
| Also a web server | No | Yes |
| Ease of adoption | Excellent | Good |
Our preference: HTTPX for general-purpose Python. aiohttp when you specifically want its async client and server together, or its built-in WebSockets.
What we would use across an AI platform
Across a platform like the ones we build, with agent apps, media services, a model runtime and Go infrastructure, we would not standardize everything on OkHttp. We would standardize the networking behaviour and pick the natural client for each language.
| Component | Client | Why |
|---|---|---|
| Agentic applications (Python) | HTTPX | Async APIs and streaming |
| Content and media applications | HTTPX | External APIs and media services |
| Agent and tool runtime | Whatever its language uses | Agent and tool calls follow the shared standard |
| Model runtime | HTTPX or the serving stack's native client | Model-serving APIs |
| Infrastructure services (Go) | net/http | Native, efficient networking |
| JVM services | OkHttp | Connection management and HTTP/2 |
| Kotlin services | OkHttp or Ktor | Kotlin-friendly networking |
One more consideration for LLM work: streaming and server-sent events (SSE) support matter a lot. You do not want to buffer a whole generated response before handing tokens to the application. Whatever client a service uses, check that it can read a response body incrementally and that nothing in the path (a proxy, a gateway, an interceptor) quietly buffers it.
Standardize the network, not the library
Rather than mandate one HTTP library, set one networking standard that every service meets, in whatever language:
These are bigger architectural decisions than OkHttp versus HTTPX. Write them down once, ship them as a thin shared SDK or wrapper per language, and every new service gets them for free.
A caution on retries
Do not blindly retry POST requests or agent operations. A request that timed out may still have run, and retrying it can create a duplicate job, a second payment or an agent that takes the same action twice. GET, PUT and DELETE are idempotent by definition; POST is not. Give non-idempotent operations an idempotency key that the server checks before doing the work again, and make retry policies explicit per operation rather than a global "retry three times".
The verdict
- Building JVM services? OkHttp is an excellent choice.
- Building Python services? Start with HTTPX.
- Building Go services? Use the standard
net/http. - Building a high-performance networking framework? Look at Netty.
For a platform of many services, invest in a shared networking SDK and a written standard, not a mandate that every service use the same HTTP client. The client is the easy part to change. Missing timeouts, unsafe retries and invisible requests are what cause incidents. For more on building agent platforms, see Build the Environments, Not the Workforce.
Sources: project documentation for OkHttp, Apache HttpClient 5, Netty, HTTPX, aiohttp, Go net/http and reqwest; idempotent methods as defined in RFC 9110. Recommendations are our own and reflect how we build. Library features change between versions, so check the current docs before you commit.