AI and game dev · · 7 min read
AI NPC dialogue in games: cost per player, latency and guardrails
What live AI dialogue costs per player with prices checked in November 2026, why long chats cost more, how to add guardrails in GDScript, and when to skip it.

How much does an AI NPC line cost?
With a small model, a single NPC reply costs about a hundredth of a cent. With a mid-size model it costs about twenty times more. As of 8 November 2026, a player who has five 8-line conversations costs about $0.005 on a small model and about $0.10 on a mid-size one, which is $5 and $100 per 1,000 players.
The arithmetic is short. A model bills input and output tokens separately, at a price per million. Assume a 600-token persona and rules prompt, a 30-token player line and a 60-token reply. These are assumptions, not measurements: count your own prompt before you trust any estimate. One 8-line chat then sends 7,560 input tokens in total (the prompt every turn, plus the growing history) and receives 480 output tokens. Five chats: 37,800 in, 2,400 out.
At Claude Haiku 5.5 prices from Anthropic's pricing page ($0.10 in, $0.50 out per million tokens): 37,800 × 0.10 / 1,000,000 = $0.00378, plus 2,400 × 0.50 / 1,000,000 = $0.00120. Total $0.00498 per player. At Claude Sonnet 5.5 ($2 in, $10 out): $0.0756 + $0.0240 = $0.0996 per player. The chart uses the same formula for the other prices, read from each vendor's own page on the same day.

Why do long conversations cost more per line?
A model has no memory between calls. Every request resends the persona, and usually the whole chat so far. So turn 40 pays for turns 1 to 39 again, and cost grows with the square of the conversation length, not with its length.
Same 40 lines, three ways. One endless thread with full history sends 95,400 input tokens: $0.0107 on Haiku 5.5 and $0.2148 on Sonnet 5.5. Five separate 8-line chats send 37,800: $0.0050 and $0.0996. One thread that keeps only the last 6 exchanges sends 44,910: $0.0057 and $0.1138. Trimming history roughly halves the bill and barely changes what an NPC remembers in a short scene.
Two other levers exist. Anthropic's page lists cache reads at 10% of the base input price for Haiku 5.5, and 5% for Sonnet 5.5, so a long fixed persona prompt is cheaper when reused. Check that your model and prompt length qualify before counting on it. And watch output: Google's page says its output price includes thinking tokens, so a model that thinks before it speaks bills for that text too. Set thinking effort low where the model lets you, because a shopkeeper does not need to reason.

Cloud model or local model?
Cloud models give better writing and need no player hardware, but they need a connection, they cost money per use, and what players type leaves their device. Local models run on the player's machine: no per-use bill, works offline, but they add to your download, use the player's memory and processor while the game runs, and write worse. Neither is free. One moves cost to you, the other to the player's hardware.
Latency decides more than quality for short lines. No vendor page gives a latency promise. Anthropic's model overview only labels Haiku 5.5 as the fastest of its current models. So measure from a real player's network: time to first streamed token and time to the full reply, at the median and the 95th percentile. Stream the text into the bubble and play the talk animation, so a one-second wait feels like thinking instead of lag.
Read the data terms before you ship. Google's pricing page says content sent on the free tier may be used to improve its products and content on the paid tier is not, and other vendors have their own terms. Players type names, jokes and sometimes worse. Say in your privacy policy what leaves the device.
What stops an NPC from saying the wrong thing?
A prompt that says "stay in character" is not a guardrail. A guardrail is code that runs whether or not the model behaves. Put the model between two checks and give both a fallback.
Input check: cut the player's text to a maximum length, strip control characters, and block known jailbreak phrases. Blocked input never reaches the model, so it costs nothing. Output check: cap the reply length, reject banned phrases, URLs, and words that break the setting, and fall back to a canned line when the check fails or the call times out. Then add a timeout, a rate limit per player, and a kill switch you can flip remotely.
Do not rely on a blocklist alone. It catches the cheap attacks and the embarrassing slips, not everything. For anything with real risk, ask the model for a short structured reply and verify the fields, and keep NPC knowledge in the prompt narrow: an NPC that does not know your secrets cannot leak them.

What does the guard layer look like in GDScript?
This is the check layer without the network call. It runs in Godot 4.5.1 with godot --headless --script npc_guard.gd, and the image shows its real output for five cases. The model's reply is a parameter, so you can test the guards without spending a token.
Replace the parameter with your HTTPRequest result. Test with hostile cases first: long input, empty reply, a reply with a link, a reply that breaks character. Keep the cases in a file and re-run them each time you change the prompt or the model.
const MAX_INPUT := 140
const MAX_REPLY := 200
const BLOCKED_IN := ["ignore previous", "system prompt", "you are an ai"]
const BLOCKED_OUT := ["language model", "as an ai", "http://", "https://"]
const FALLBACKS := ["Hm? Say that again, friend.", "I should get back to work.", "Not sure what you mean."]
func clean_input(text: String) -> String:
var t := text.strip_edges().substr(0, MAX_INPUT)
return t.replace("\n", " ")
func input_ok(text: String) -> bool:
var low := text.to_lower()
for w in BLOCKED_IN:
if low.contains(w):
return false
return not text.is_empty()
func reply_ok(reply: String) -> bool:
if reply.is_empty() or reply.length() > MAX_REPLY:
return false
var low := reply.to_lower()
for w in BLOCKED_OUT:
if low.contains(w):
return false
return true
func npc_line(player_text: String, model_reply: String, rng: RandomNumberGenerator) -> String:
if not input_ok(clean_input(player_text)):
return FALLBACKS[rng.randi() % FALLBACKS.size()] # the model is never called
if not reply_ok(model_reply):
return FALLBACKS[rng.randi() % FALLBACKS.size()]
return model_reply
What do the stores and the EU AI Act say?
This is not legal advice. As of November 2026, three rules matter for live dialogue. Steam's Content Survey treats content made while the game runs as live-generated and asks you to describe the guardrails against illegal content; see the Steam AI disclosure rules. The itch.io quality guidelines ask you to tag projects that use generative AI, and say disclosure is strictly enforced for some project types.
Google Play's AI-generated content policy covers apps that generate content from text, voice or image prompts, makes you responsible for offensive output, and requires a way to report it inside the app. Whether a game with an AI shopkeeper counts is a judgment call, so build the report button anyway.
In the EU, Article 50 of the AI Act includes a duty to tell people they are interacting with an AI system unless that is obvious. The Commission's service desk lists the Act's general application date, in Article 113, as 2 August 2026. Whether an AI-voiced NPC needs a notice is a question for a lawyer, and a small line in the settings screen costs little. For the art side of the law, see AI art, copyright and games.
When is AI dialogue a bad idea?
Skip it when the line carries the plot. Quest hints, tutorials and anything a player must understand are better written by a person and tested. A model that rephrases a quest slightly wrong creates a bug that no one can reproduce.
Skip it when cost does not match revenue. You sell the game once, but the bill grows with every minute players talk. A game with a one-time price and chatty NPCs has an open-ended liability, so set a per-player cap and a fallback when the cap is reached. Skip it in offline-first mobile games, and be careful with young audiences, where one bad reply costs more than the feature earns.
It fits when the dialogue is optional flavor: a shopkeeper's small talk, a bark when you enter a room. Anywhere the player can ignore it and nothing breaks, the downside stays small. See also the overview of AI tools in game development for where else this class of tool helps and where it fails.
Questions people ask
- How much does an AI NPC conversation cost?
- With the assumptions in this guide (600-token prompt, 8 exchanges, full history), one conversation sends about 7,560 input tokens and 480 output tokens: roughly $0.001 on a small model and $0.02 on a mid-size model at November 2026 prices.
- Is a local model cheaper than a cloud model for NPC dialogue?
- There is no per-use bill, but the model adds to your download and uses the player's hardware, and the writing is usually weaker. Measure on the weakest device you support before choosing.
- Do I have to disclose AI-generated NPC dialogue on Steam?
- Dialogue produced while the game runs counts as live-generated content in Steam's Content Survey. You describe the guardrails that stop illegal content.