arXiv:2610.25480cs.LGOct 2026

Manuscript Offprint

arXiv:2610.25480

Consistent LLM Call Handling Across Java Frameworks: A Reference Implementation and Benchmark

Oleksandr Klymenko

Oleksandr Klymenko

Independent Researcher, Poland

ORCID 0009-0000-5924-3697

alexanderklmn@gmail.com

Abstract—Java applications reach large language models (LLMs) through an integration framework, and rely on it to handle a failing provider: to retry what can be retried and nothing else, to wait as long as the provider asks, never to present a truncated answer as complete, and to record each failure in the application's metrics. We state these expectations as a six-clause reliability contract and measure Spring AI 2.0.1 and LangChain4j 1.21.0 against it with a scripted OpenAI-compatible provider: fifteen failure scenarios, synchronous and streaming, three repetitions. LangChain4j meets it in 47 of 77 applicable cases with its defaults and in 51 of 83 when configured explicitly, Spring AI in 72 of 77 and 76 of 83; both deliver a stream that ended without its terminator as a complete answer. We then place one implementation of the contract beneath both frameworks, at the HTTP boundary — an OkHttp interceptor for Spring AI, an HttpClient for LangChain4j, and a java.net.http transport for code without a framework — sharing a 725-line core that depends only on the JDK and the Micrometer Observation API. With it, all three clients behave identically and meet the contract in 90 of 91 cases; the remaining case is a policy trade-off between retrying a hung provider and waiting for a slow first token. Against a local model server the layer rejected none of 700 calls, and it adds a median of 32–217 μ\mus to a call.

Index Terms—large language models, reliability, retries, timeouts, server-sent events, observability, Micrometer, Spring AI, LangChain4j.

I. INTRODUCTION

A Java application that calls a large language model (LLM) rarely speaks HTTP to the provider itself. It uses an integration framework — Spring AI or LangChain4j — which turns a prompt into a request, the response into an object, and a failure into an exception, a retry, or nothing. Which of the three happens decides what the application and its operator see. A rate limit absorbed by a retry is invisible; a stream that ended early and is delivered as a complete answer is indistinguishable from a real one; a failure that no metric records does not appear on a dashboard. Such failures are gray in the sense of [1]: the component fails, and the observer that should notice does not.

Providers fail in ordinary, documented ways. They answer 429 with a Retry-After, return 5xx under load, stop responding, close connections, and end streams early. HTTP semantics [2], [3] and the provider's streaming format [4] say what a client should do in most of these cases. The frameworks implement these rules separately, each in its own retry loop, timeout model and instrumentation, and they implement them differently. Section V.B measures the difference: run against the same fifteen scripted provider failures, LangChain4j 1.21.0 meets a six-clause reliability contract in 47 of 77 applicable cases with its defaults and Spring AI 2.0.1 in 72 of 77, and the two fail on different clauses.

This paper argues that the rules belong below the frameworks rather than inside each of them. Both frameworks reach an OpenAI-compatible endpoint over HTTP, and both let the application supply the HTTP client: Spring AI through an OkHttp interceptor, LangChain4j through its HttpClient interface. Beneath that seam the wire is the same — a JSON body or a stream of server-sent events — so a layer placed there can apply one contract to every framework above it, and to an application that uses no framework at all.

We contribute:

  1. A reliability contract for model calls in six clauses (Section III), each derived from HTTP semantics, the streaming format, or the observability requirement, and each checkable against a scripted provider.

  2. A layer that implements it once (Section IV): a framework-independent core of 725 lines with no dependency beyond the JDK and the Micrometer Observation API, and three adapters — an OkHttp interceptor for Spring AI (210 lines), a LangChain4j HttpClient (137 lines), and a java.net.http transport (290 lines) usable without a framework.

  3. An evaluation (Section V) by fault injection — fifteen scenarios, synchronous and streaming, three repetitions, before and after — against a real model server (700 calls to two local models), and of the latency the layer adds.

  4. An open implementation with every result reproducible from one command [5].