Sessions
A session is a named context whose KV cache stays on the GPU between requests. A chat turn against a session pays prefill only for the tokens it adds; the rest is resumed from held KV. On top of that, data can be pushed into a session and ingested in the background, and flash queries are standing questions the engine re-answers after every data batch, so reading one costs no GPU time.
Sessions hold KV until deleted, or until nobody has used them for an hour (see Idle expiry). Creation is explicit: a turn against an unknown id is a 404, never a new session. One turn runs per session at a time; a second concurrent turn is refused with 409. /generate questions are the exception: any number run at once.
Every tier runs any number of live sessions, up to the engine’s ceiling of 256.
A server started with --api-key <KEY> needs -H "Authorization: Bearer <KEY>" on every request below.
Create, list, inspect, delete
# Create, with a generated idcurl -X POST http://127.0.0.1:8080/v1/sessions
# Create with a chosen id and a sliding data windowcurl -X POST http://127.0.0.1:8080/v1/sessions \ -H "Content-Type: application/json" \ -d '{"id": "ticker-feed", "window": 8192, "pre_decode": true}'Body fields, all optional:
| Field | Meaning |
|---|---|
id |
1 to 128 characters of A-Z a-z 0-9 _ -. Default: a generated sess_.... 409 if it already exists. |
window |
Token cap on the ingested-data region. When new data does not fit, the oldest whole entries are evicted. A whole number below the context minus the query reserve. Without it the region is append-only, and data that no longer fits is dropped and counted. |
pre_decode |
After every ingested batch, pre-decode the query entry and cache the logits at the ready position, for the fast_answer path of /generate. Default false. |
The response, and the shape of every session object:
{ "id": "ticker-feed", "object": "session", "created": 1757000000, "last_used": 1757000000, "tokens": 0, "kv_tokens": 0, "busy": false, "turns": 0, "data_end": 0, "data_version": 0, "pending": 0, "pre_decode": true, "ready": false, "evicted": 0, "window": 8192}last_used is when a request last named the session or a turn on it ended, in Unix seconds (GET /v1/sessions/{id} reports the time before its own lookup); tokens is the session’s whole token sequence; kv_tokens how many of them have KV; data_end where the durable context (system prompt, conversation, ingested data) ends; data_version increments once per ingested batch; pending counts pushed entries not yet ingested; evicted counts entries the window evicted. frozen_end, ready_token and ready_gap appear once they have values.
curl http://127.0.0.1:8080/v1/sessionscurl http://127.0.0.1:8080/v1/sessions/ticker-feedcurl -X DELETE http://127.0.0.1:8080/v1/sessions/ticker-feedThe list is {"object": "list", "data": [...]} in creation order. Delete answers {"id": ..., "object": "session", "deleted": true} and releases the KV; it answers 409 while a foreground request is in flight.
Errors: 404 no such session '...', 409 session '...' has a request in flight. They come in OpenAI’s envelope, or in Anthropic’s (409 as conflict_error, 503 as overloaded_error, with a request_id) for a request that sent an anthropic-version header and for a turn on /v1/messages (see Errors).
Idle expiry
A session nobody uses for an hour is deleted as DELETE would delete it, and its KV goes back to the pool. Every request that names the session restarts the clock: a turn, a GET /v1/sessions/{id}, a warm turn, a push, a /generate, a flash query change or opening an event stream. The listing does not. A session is never expired while a request is in flight on it, while pushed data waits to be ingested, or while an event stream or WebSocket is open on it. The session_expired log line records each expiry with the idle time.
This bounds what a client that crashed or restarted without deleting its sessions can hold. A client that comes back within the hour, and knows the ids it used, adopts its sessions with GET /v1/sessions/{id}: a 200 means the session is still live, kv_tokens says how much of it the last turn left held, and the next turn resumes from it while the session keeps that KV. A 404 means it is gone, and the client creates it again. Expiry happens on idle time alone. Memory pressure never deletes a live session, and never fails a request while an idle session holds KV it could give back: idle sessions give it back instead, implicit ones and the prefix cache first, then explicit ones, the one used longest ago first. Such a session stays live, and its next turn prefills again what the prefix cache no longer holds.
Chat turns on a session
Send the session id in the x-layerscale-session-id header of a /v1/chat/completions, /v1/responses or /v1/messages request. Send the whole conversation as usual; the engine finds the longest prefix already held and prefills only what is new. The response is the ordinary one: usage.prompt_tokens_details.cached_tokens (OpenAI) or usage.cache_read_input_tokens (Anthropic) says how many prompt tokens came from cache, and Anthropic’s input_tokens leaves them out. A turn may also adopt pages from the prefix cache: past what it resumed, or from the start when the session could not resume, such as on its first turn. Those count as cached too, and prefix_cached_tokens names that part (see the API reference).
A /v1/responses conversation sent without the header runs on a session of its own behind the scenes, so each turn resumes from where the last one ended; there is nothing to configure. These sessions count against no session limit, and memory pressure takes them before any request fails.
Some chat templates render a reply back without its reasoning (Qwen3, Nemotron 3.5, Gemma 4, gpt-oss), so the next prompt differs from what the model generated. On these models a session prefills the conversation in that form as soon as a text reply has gone out, in the background, and the next turn prefills only its new message. session_warm_turns_total and session_warmed_tokens_total count this work.
curl http://127.0.0.1:8080/v1/chat/completions \ -H "Content-Type: application/json" \ -H "x-layerscale-session-id: ticker-feed" \ -d '{ "messages": [{"role": "user", "content": "Summarise the feed so far."}], "max_tokens": 200 }'Images
A turn on a named session may carry pictures, sent as on the stateless routes. The session keeps them with the conversation: the next turn resends the conversation as usual and resumes past the pictures it already holds, and /generate questions are asked over them without sending them again. To ask many questions about one picture, send it once in a turn, then ask each question with /generate.
Gemma 4 26B-A4B and 31B, audio clips, warm turns and /v1/responses conversations without the header do not keep media in a session: the first three are refused by name, the last runs stateless.
Push data
curl -X POST http://127.0.0.1:8080/v1/sessions/ticker-feed/push \ -H "Content-Type: application/json" \ -d '{"data": ["AAPL 231.10 +0.4%", "MSFT 415.22 -0.1%"]}'data is a string or a non-empty array of strings. The acknowledgement is immediate; ingestion happens in the background and bumps data_version per batch:
{"pushed": 2, "dropped": 0, "pending": 2, "pending_bytes": 36, "total_pushed": 2, "total_dropped": 0, "data_version": 0}A session queues at most 4,096 pending entries or 8 MiB; past that the oldest unprocessed entry is dropped and counted in dropped. The producer never blocks. A foreground turn takes precedence over ingestion at the next step boundary.
Ask over the session
POST /v1/sessions/{id}/generate asks a question over the session’s durable context: the system prompt, the conversation and the ingested data. The question and its answer stay ephemeral. They do not become part of the session, so many questions can run over the same state, one after another or at once: a question asked while the session is busy runs beside the request that holds it, over the context as it stood.
curl -X POST http://127.0.0.1:8080/v1/sessions/ticker-feed/generate \ -H "Content-Type: application/json" \ -d '{"prompt": "Which symbol moved most?", "max_tokens": 32}'| Field | Default | Notes |
|---|---|---|
prompt |
required | The question. |
max_tokens, temperature, top_p, top_k, seed, stop, ignore_eos, skip_special_tokens, stream |
as for chat completions | |
reasoning_effort, chat_template_kwargs.enable_thinking |
as for chat completions | With an anthropic-version header, thinking and output_config.effort instead, read as /v1/messages reads them, and errors come in Anthropic’s envelope. The question’s generation prompt is the one a chat request with the same setting ends on, where the setting lives only there: on Qwen3, Qwen3.5 and Nemotron 3.5, enable_thinking: false (or reasoning_effort: "none") closes an empty think block. Where a template also writes the setting before the first turn (gpt-oss, Mistral Small 4, Qwen3.8’s reasoning instruction, Gemma 4’s thinking switch, GLM-5.3’s effort turn), that part belongs to the held context, so the setting has no effect on a question and the question renders under the template’s default: Qwen3.8 thinks, Gemma 4 does not, GLM-5.3 thinks at Max. Ripple-65B’s template has no setting, so the setting has no effect on its questions either. A question whose setting changes the generation prompt is never served from the flash cache or fast_answer, whose answers were computed under the default. |
logprobs, top_logprobs |
as for chat completions | The answer’s tokens come back in logprobs.content, in the chat completions’ shape, on the body and on a stream’s done frame. A question asking for them is never served from the flash cache or fast_answer. |
fast_answer |
none | An array of words. With pre_decode on, if the model was already confident at the ready position and its first token starts one of these words, that word is returned with no GPU work. |
gap_threshold |
2.0 |
The logit gap the ready position must clear for fast_answer to fire. |
{ "id": "genr_...", "object": "session.generation", "session_id": "ticker-feed", "text": "AAPL, up 0.4%.", "finish_reason": "stop", "data_version": 1, "usage": {"prompt_tokens": 14, "completion_tokens": 7, "total_tokens": 21, "prompt_tokens_details": {"cached_tokens": 12}}}A prompt that exactly matches a registered flash query whose answer is current is served from the cache with "flash": true, flash_id, confidence and zero usage (prompt_tokens, completion_tokens and total_tokens all 0). A fast_answer hit carries "speculative": true and logit_gap, with the same zero usage.
With "stream": true, frames are data: {"text": "..."} per piece, then one data: frame with "done": true and the fields above without text, then data: [DONE]. The status line goes out with the first piece, so a question refused before it (one past the context, a backend fault) is an HTTP error; an error after it is an error object as a data: frame, then data: [DONE]. Both come in OpenAI’s envelope, or in Anthropic’s for a request that sent an anthropic-version header.
Flash queries
A flash query is a question registered on a session. The engine re-evaluates it in the background after every ingested batch and keeps the latest answer. A /generate whose prompt matches it exactly is answered from the cache, and the event stream pushes every new answer as it lands.
# Registercurl -X POST http://127.0.0.1:8080/v1/sessions/ticker-feed/flash \ -H "Content-Type: application/json" \ -d '{"query": "Which symbol moved most?", "max_tokens": 16}'
# Listcurl http://127.0.0.1:8080/v1/sessions/ticker-feed/flash
# Removecurl -X DELETE http://127.0.0.1:8080/v1/sessions/ticker-feed/flash/1query is required; max_tokens defaults to 32 and is clamped to 1..256. At most 20 flash queries per session (400 past that); a duplicate query is a 409. The entry:
{ "id": 1, "object": "session.flash_query", "query": "Which symbol moved most?", "max_tokens": 16, "tokens": 9, "fresh": true, "value": "AAPL, up 0.4%.", "data_version": 1, "confidence": 0.82, "evaluated_at": 1757000010}fresh is true when value was computed against the current data_version. value, data_version, confidence and evaluated_at are absent until the first evaluation. The list response is {"object": "list", "data": [...], "data_version": N}; delete answers {"id", "object", "deleted": true, "remaining"}.
Event stream (SSE)
GET /v1/sessions/{id}/events is a long-lived text/event-stream:
curl -N http://127.0.0.1:8080/v1/sessions/ticker-feed/events| Event | Data | When |
|---|---|---|
connected |
{"session_id", "data_version", "flash_queries"} |
On connect |
flash_ready |
{"id", "query", "value", "data_version", "confidence"} |
On connect, a replay of every cached answer; then whenever an answer changes |
data_updated |
{"data_version", "tokens", "pending"} |
Whenever a batch is ingested |
A : heartbeat comment goes out after 15 seconds of silence. The stream ends when the session is deleted or the server shuts down. A subscriber that falls more than 64 events behind is dropped; reconnecting replays the current answers.
WebSocket
GET /v1/sessions/{id}/ws with the standard upgrade headers opens a socket that carries the same events out and push in. Under --api-key, send the key as Authorization: Bearer <KEY> on the handshake; without it the upgrade is refused with a plain HTTP 401. Every message is one JSON text frame of the form {"type": ..., "data": {...}}.
Server to client:
type |
data |
|---|---|
connected |
{"session_id", "data_version", "flash_queries"} |
flash_ready |
as the SSE event, replayed on connect and then live |
data_updated |
as the SSE event |
push_ack |
{"pushed", "dropped", "pending", "total_pushed", "total_dropped", "data_version"} |
pong |
{} |
error |
{"message", "code": 400} |
Client to server:
type |
Message |
|---|---|
push |
{"type": "push", "data": "one entry"} or {"type": "push", "data": ["entry", ...]} |
ping |
{"type": "ping"} |
close |
{"type": "close"} |
The server pings every 15 seconds; a client that answers with pongs, as every WebSocket library does, keeps the socket’s read timeout from firing. Frames are limited to 16 MiB and must not be fragmented.
The Responses API’s WebSocket mode (an upgrade on /v1/responses, see the API reference) runs on the same socket, each lane’s conversation on a session of its own behind the scenes.