AI Gateway logs now show session affinity
- Source
- vercel.com
- Author
- Sam Chitgopekar
- Date
Vercel's AI Gateway logs now include a Sessions view that groups requests into sessions and shows how session affinity routed each one. Each row names the coding agent or app behind the session, such as Claude Code, Codex or Cursor, with its cost, models, providers and how much input was served from cache across every turn. Opening a session shows its cache hit rate, duration and path: each turn with its model and timing, plus the provider serving the session and any earlier ones. Session affinity runs by default on text and chat requests and sends each turn to the provider that served the previous turn, so that provider already holds most of the prompt in cache. Teams can group requests explicitly by sending the same sessionId in providerOptions.gateway or the same x-session-id header. Requests without either are grouped by a fingerprint of the conversation's opening. Sessions can be filtered by turns, client, model, provider, authentication or cost, and single-turn sessions stay hidden until the minimum turns filter is cleared. The practical result is that cache behavior, usually invisible, becomes a number per session that can be checked against the bill.

Context
A provider's prompt cache lives on the provider account that served a request, so when the next turn of a conversation goes to a different provider, that cache is cold and the whole prompt is billed at full price again. Vercel's AI Gateway, which can send a request for one model to any of several providers, handles this with session affinity: it groups related requests into a session, remembers which provider served the last one, and tries that provider first on the next turn. The new Sessions view in Gateway logs, announced in the changelog, lets users check whether that worked. Each row names the client that ran the session, such as Claude Code from Anthropic, Codex from OpenAI or Cursor, alongside its cost, models, providers and how much of its input was cached across turns. Opening a session shows its cache hit rate, duration and path, a turn-by-turn list of model and timing that names the provider now serving the session and any earlier ones. The changelog states the cost logic directly: a session that stays on one provider reads more of each prompt from cache.
The session affinity docs explain what the view is measuring. Affinity is on by default for text and chat requests and does not apply to , images or realtime sessions, which have no prompt cache to keep warm. Gateway takes the session from an ID the caller sends (the sessionId provider option or an x-session-id header, among a few accepted sources), then from the x-claude-code-session-id header that Claude Code sends automatically, and otherwise from a fingerprint: a hash of the conversation's opening system message, first other message and tool set, combined with the team ID. The docs warn that two conversations with the same opening share a fingerprint, so callers running many similar conversations should send an ID. Affinity runs after routing filters and only reorders providers already allowed; if the pinned provider fails, Gateway tries the next one as usual, and setting sessionAffinity to false keeps an explicit provider order exactly as written.
The routing problem is not unique to Vercel. OpenRouter describes a similar mechanism as sticky routing, keyed on a session_id when one is sent, because with many providers behind one model a second turn can land on an endpoint with no warm cache. What this changelog adds is a Gateway view, session by session, of whether pinning held. The changelog does not report any measured cache hit rates or cost savings for Gateway traffic.
- Vercel AI Gateway's new Sessions view groups requests by session and lists each one's client (such as Claude Code, Codex or Cursor), cost, models, providers and how much of its input was served from cache across turns.
- To group requests yourself, send the same sessionId in providerOptions.gateway, or the same x-session-id header, on every request in a conversation. Requests without one are grouped by a fingerprint of the conversation's opening.
- Session affinity runs by default on text and chat requests. Single-turn sessions are hidden in the view until you clear its minimum-turns filter.
Checking sign-in…
Loading comments…



