NPCs that react to your game
Report an event, get back a behaviour your game loop can switch on — with player memory, moderation, and hard spend caps. No server to run, no secrets in the browser. Try it live below.
Contacting live worker…
{
"behaviour": null,
"say": null,
"action": null,
"degraded": 0
}One Import. Zero Server.
No API secrets in the browser. No prompt templating. No fragile wrappers. The NPC logic, memory, and allowed behaviour vocabulary live securely in the cloud.
import { npc } from '@npc/client';
// 1. Initialize NPC brain with public key & character ID
const smith = npc({
key: 'pk_live_your_game_key',
id: 'smith',
});
// 2. React to game events from your physics or input loop
async function onPlayerInteract(event, worldState) {
// react() NEVER throws. Always returns guaranteed behaviour.
const reaction = await smith.react(event, worldState);
switch (reaction.behaviour) {
case 'greet': playAnimation('wave'); break;
case 'warn': playAnimation('angry'); break;
case 'offer_deal': openShopUI(); break;
case 'throw_out': ejectPlayer(); break;
}
if (reaction.say) {
showSpeechBubble(reaction.say);
}
}
// 3. Fire-and-forget background observations (memory only)
smith.observe('player completed the dragon cavern quest');Everything a Vibe-Coded Game Can't Build
Vibe-coding platforms generate client-side code in seconds. But client-side apps have no database, no anti-cheat, no secret storage, and no spend controls. Smart NPCs is the plug-and-play backend.
Persistent Player Memory
Remembers player actions, reputation, and decisions across sessions without running a database. Raw dialogue is purged after 30 days; distilled facts and disposition persist.
Anti-Cheat Authority Boundary
The NPC returns validated behaviour intents and never touches game state. Client world data is advisory prompt context only — opt-in HMAC signing is available for games that need verified state.
Zero-Secret Public Key
Use pk_live_... keys right inside your client-side JavaScript. Vendor API keys stay on our servers and never ship to the browser.
Hard Spend Caps & Predictability
Set a strict daily spend limit per game, enforced before each request against a worst-case cost reservation. Past the cap, NPCs degrade to idle or block — they never bill past it.
Latency Budget With Fallback
Reactions target an 800ms p95 budget; every failure path degrades to a playable fallback instead of throwing. Repeat situations answer from the behaviour cache in milliseconds.
Measurable Invariant Evals
Scored against R1–R5 invariants (validity, appropriateness, consistency, diversity, latency) — deterministic gates run on every deploy, and judge-scored tiers run on demand wherever vendor keys are configured.
Direct Architecture Comparison
Why inline raw LLM calls break down in production games
| Capability | Raw Client-Side LLM Call | Smart NPCs (smartnpcs.com) |
|---|---|---|
| State & Memory | ❌ Wiped on browser refresh | ✅ Cross-session working memory keyed by player id (raw dialogue purged after 30 days) |
| Security | ❌ API key exposed in DevTools | ✅ Scoped public key (pk_live_...) with zero secret risk |
| Cost Control | ❌ Infinite liability on viral spikes | ✅ Hard dollar spend caps with automatic fallback |
| Response Type | ❌ Unpredictable raw prose text | ✅ Strict game-ready behaviour token enum |
| Latency | ❌ Full model call on every event, no cache, no fallback | ✅ 800ms p95 budget; cache repeats in milliseconds, degraded fallback on failure |
See It in Real Game Loops
Two runnable examples in the monorepo: one wired to the real client SDK, one standalone UI prototype with canned reactions. Clone the repo and run them locally.
Shopkeeper Barter & Theft Demo
Interact with a gruff medieval blacksmith over the real @npc/client: bargaining, item trade, and what happens when a player draws a weapon or tries to steal an enchanted potion. The page calls /v1/* on its own origin and the demo server proxies those paths to a local worker, so running both commands below gives live inference — without the worker, the SDK answers with its offline fallback.
pnpm --filter @npc/shopkeeper-demo start
pnpm --filter @npc/worker run serveDungeon Guardian RPG Demo
A dark fantasy dungeon where an ancient gate guardian inspects your player credentials and responds to aggression or stealth maneuvers. Standalone page: its reactions are canned in-page and it makes no worker calls — run it to preview the interaction patterns, not live inference.
pnpm --filter @npc/dungeon-rpg startBuilt for Indie Game Economics
Events cost fractions of a cent. Our pricing is designed so you never get hit with unexpected viral bills. Between Hobby and Pro, Pay As You Go bills $2 per 1k events with no base fee.
Perfect for game jams, prototyping, and indie experiments.
- 5,000 events / month
- Up to 3 NPCs · 2 games
- Persistent player memory
- Hard daily spend cap ($10 max)
- Community support
For launched browser games and AI game-builder creators.
- 100,000 events / month
- Unlimited NPCs · 10 games
- Configurable spend caps per game
- Eval scorecard + planner
- Priority developer support
For commercial studios, multi-player worlds, and publishers.
- 1,000,000 events / month
- Unlimited NPCs & games
- Custom multi-project spend caps
- Everything in Pro
- Dedicated support