Skip to content

AI game master design

Prompt Caching for Long AI RPG Campaigns

Compare OpenAI, Claude, and Gemini prompt caching for long AI RPG campaigns; separate stable world context from turn state and measure cache usage.

By Playworlds · Elser.AI ·

A cloaked adventurer follows a stone path toward a glowing gateway among misty mountains.

Why a long campaign repeats itself

An AI game master may need the same setting rules, character roles, and narration boundaries on every turn. The scene changes when a player opens a door or questions a witness, but the world does not become a different world. Sending that shared material again is often necessary for a coherent reply. Prompt caching is a way an API can reuse work on repeated input; it is not a way for a game to remember an event it never saved.

Imagine a skyship expedition searching for a lost star chart. Every turn needs the cloud sea's geography and the rule that the stormwall cannot be crossed after sunset. The current deck, witnesses, clues, and player action change. That distinction gives developers a starting point for examining cache behavior. This is a design example, not a measured Playworlds optimization.

Put stable world material before changing turn facts

A possible request begins with enduring instructions: the game's role for the narrator, the world's established constraints, how dice outcomes are supplied, and a short description of recurring characters. A later section contains the current scene: which deck is accessible, who is present, what the player knows, and what action they attempted. Putting a clock reading, session identifier, or new player message before the reusable material can change the prefix that a cache might have reused.

Do not pad a brief merely to qualify for a cache. Include facts that help the narrator make a correct decision, then check the provider's eligibility rules. If a permanent rule changes, update the source of truth even if the new version needs fresh processing.

What different APIs mean by a cache hit

OpenAI's API documentation describes reuse of a shared prompt prefix and reports cached input tokens in usage data for supported models. Anthropic documents automatic caching and explicit breakpoints, including a place to mark the end of stable content. Gemini documents implicit caching and explicit cache objects in its Generate Content API. These mechanisms differ, so a copied example from one API is not a portable caching configuration.

A hit can reduce processing and the price of eligible input. It does not make new scene facts free, remove output costs, or prove the answer is correct. Lifetime, minimum length, interfaces, and billing vary by provider and model. Check the exact API route before promising a percentage saving.

A sample request for the skyship scene

Keep the shared section concise: “You are the game master for a skyship expedition. Use established facts, preserve player choice, and narrate the result of rules already resolved by the game. The stormwall cannot be crossed after sunset. Navigator Iri plans routes; her current knowledge is supplied each turn.” That is an illustrative prompt brief, not a Playworlds prompt or a transcript from a model run.

Append changing state after it: “Current scene: the ship approaches the stormwall after sunset. Saved event: the player found the scorched star chart in the engine room. Iri has not seen the chart since departure. Player action: show the chart to Iri and ask who entered the engine room.” On the next turn, preserve the shared section and replace only facts that truly changed. Validate the response against saved events before treating it as a campaign update.

Measure cost per useful turn, not a headline discount

For each request, record the model and interface, total input and output tokens, cached input or cache-read tokens, cache-write tokens where charged, elapsed time, and the actual task result. Compare a normal sequence of turns with a version whose stable prefix is deliberately preserved. If one turn needs two calls or a retry, include both. An apparently cheaper request is not a saving if a broken reply forces another generation.

Compare the reused input fraction and the bill for a complete turn. Check whether the answer respects the chart's discovery, stormwall rule, and Iri's knowledge. Usage fields show reuse, not narrative continuity. Inspect the actual request difference before changing a prompt to fix a cache miss.

Keep story truth separate from cache layout

A campaign can outgrow its original world brief. If the crew dispels the stormwall, a stable sentence saying it cannot be crossed after sunset becomes wrong. The game should update that rule, version the brief, or move the exception into authoritative current state where the narrator will see it. Protecting a cache hit must not preserve a contradiction. Likewise, a secret that belongs only to the game master should not appear in a player-visible recap.

The provider cache is a processing aid, not the campaign database. A saved adventure needs its own record of accepted actions, rolls, discoveries, and character changes. Playworlds offers account-linked adventures and an AI narrator, but this article does not claim its live game uses any particular provider prompt cache. The example is a plan a game team could evaluate.

A short checklist before optimizing

First, identify the facts that repeat across several turns and place them in one versioned, accurate brief. Second, place the player action and current scene after that brief, and keep secrets scoped to the people who may know them. Third, log the exact provider route and its cache usage fields; compare complete turns, including retries and output. Fourth, test the story for factual continuity and player choice before calling a lower bill a success.

If you want to experience the player side of a continuing AI adventure, browse the Playworlds world library and choose a setting that gives your character a reason to investigate. For more on shaping a first session, read the solo roleplaying guide.