web dev//API//stateless API

A stateless API is an API whose server keeps no memory of a client between requests: each request carries everything needed to answer it, and the server forgets the exchange once it has replied. It is the default shape of HTTP and REST, and of most hosted LLM APIs, so it decides where state has to live in any system built on top of them.


A stateless API is an API whose server keeps no memory of a client between requests: each request carries everything needed to answer it, and the server forgets the exchange once it has replied. It is the default shape of HTTP and REST, and of most hosted LLM APIs, so it decides where state has to live in any system built on top of them.

The model call is the clearest case. A chat API does not remember the conversation: on every turn the client sends the whole history again (system prompt, previous messages, tool results), and the model answers as if seeing it for the first time. The memory an agent seems to have is the transcript its own code keeps and resends, bounded by the context window and paid for in tokens on every call.

Statelessness is what makes servers easy to scale. Any replica can answer any request, a crashed server loses nothing, and a load balancer needs no stickiness; that is why serverless functions and web backends are built this way.

The state moves somewhere else: to the client (a token, a cookie, the resent transcript), to a database, or to a cache the server consults by key. Saying an API is stateless says only that the request handler holds nothing between calls.

The price is size and repetition. Resending a long conversation costs bandwidth, latency and tokens each turn; providers add prompt caching and optional server-side conversation storage precisely to soften it, at the cost of state living somewhere again.

With a stateless model API the agent is the memory.

What it stores, trims and resends between calls is its whole continuity.

A stateless API is often confused with an idempotent one: statelessness is about what the server remembers, idempotence about what repeating a request does to the world. The loop that keeps the history is described in agent loop.