---
title: "An AI NPC SDK with no AI bill: how sign-in, checked actions and save-file memory work"
subtitle: How the Yumina games SDK puts AI NPCs in a Unity, Godot or web game without a model key in the build, and what the server checks before your game acts.
description: How an AI NPC SDK works with no key in the build. The player signs in and pays, the server checks each action, and memory follows the save file.
author: Yumina
date: 2026-12-04
category: engineering
tags: AI NPC, AI NPC SDK, AI NPC API, Unity, Godot, game development, open source
lang: en
url: https://yumina.io/blog/ai-npc-sdk-how-it-works
canonical: https://yumina.io/blog/ai-npc-sdk-how-it-works
---

# An AI NPC SDK with no AI bill: how sign-in, checked actions and save-file memory work

*How the Yumina games SDK puts AI NPCs in a Unity, Godot or web game without a model key in the build, and what the server checks before your game acts.*

A game built on the Yumina games SDK ships with no AI key in it, and everything an NPC remembers hangs off one id in the player's save file. The player signs in with a Yumina account and that account pays for each line, on Yumina's free models, on their balance or on their own key. The developer pays nothing.

The JavaScript package is `@yumina.io/games`, Apache-2.0, with no dependencies. It runs in browsers and in Node 18 or later.

```
npm install @yumina.io/games
```

There is a [C# SDK](https://docs.yumina.io/developers/dotnet) for Unity, Godot .NET and MonoGame, a [GDScript addon](https://docs.yumina.io/developers/godot) for Godot 4, and a [plain HTTP reference](https://docs.yumina.io/developers/http) for Unreal and everything else. All four send the same requests. This post follows the JavaScript source.

## Who pays for the AI when there is no key in the build?

The game is a public OAuth client: it has a `clientId` and no secret. The player signs in with Authorization Code and PKCE, and the SDK has three ways to get them there.

```js
import { Yumina, Card } from "@yumina.io/games";

const yumina = new Yumina({ clientId: "ym_…", language: "en" });

// Web game: send the page to yumina.io and back.
await yumina.signInWithRedirect(location.origin + "/play");
await yumina.handleRedirect();          // on the page the player returns to

// Steam Deck, console, TV, full screen: a code the player scans.
const link = await yumina.startQrSignIn();
drawQr(link.qr.rows);                   // rows[r][c] === "1" is a dark square
await link.wait();

// Node or Electron: the system browser and a local port.
await yumina.signInWithLoopback((url) => shell.openExternal(url));
```

`signInWithLoopback` listens on the first free port from 47613 to 47617 on `127.0.0.1`. `startQrSignIn` returns the QR code as a grid of squares plus a short code such as `ACDE-2345`, then polls every 2 seconds. The code expires after 10 minutes. A scan always shows the consent screen with the code the game displays. The server comment gives the reason: without it, someone could post a QR code for a game the player had already allowed and receive their tokens with no prompt.

What comes back is a 15-minute access token and a refresh token that rotates on every use. A leaked build gives away nothing, because the build holds only the public id.

Each turn is then charged to the signed-in player, at the model's cost, and only when a reply was delivered. A player who has set their own AI key in Yumina plays on that key and is charged nothing. When the balance runs out the SDK throws a `YuminaError` with `needsMushies` set, and `me()` returns a `plansUrl` to send the player to.

## What can the AI NPC do to my game?

It can ask. Your game declares what characters may ask for in a manifest, registered once in the [developer console](https://yumina.io/app/developer).

```json
{
  "version": 1,
  "game": { "id": "steam:413150", "name": "Stardew Valley" },
  "inputs":  [{ "id": "hearts", "type": "number", "description": "Friendship hearts, 0 to 14." }],
  "outputs": [{ "id": "friendship_delta", "type": "number", "min": -20, "max": 20,
                "description": "Friendship this line earns or costs." }],
  "actions": [{
    "id": "give_item",
    "description": "Hand the player something you would plausibly have on you.",
    "params": { "item": { "type": "string", "enum": ["coffee", "a daffodil"] } },
    "limits": { "perPeriod": 1 }
  }]
}
```

A manifest holds up to 32 actions with up to 8 parameters each. A limit is a count from 1 to 100, per conversation or per `period`, and `period` is whatever string your game sends: a day, a week, a run.

Each turn the character may propose one action. The server checks it in this order before your game sees it:

1. The action exists in the manifest. Otherwise `unknown_action`.
2. Your game offered it this turn, through `allow`, and its limits are not used up. Otherwise `not_allowed` or `limit`.
3. Its parameters have the right type, sit inside `min` and `max`, and match the `enum`. Otherwise `invalid_params`.

`allow` can narrow a parameter for one turn, so an NPC carrying a bandage and rice wine can offer only those two. Outputs are clamped the same way: a `friendship_delta` of 500 arrives as 20.

An accepted action is still only a request. Your game applies it under its own rules and says what happened.

```js
const mira = yumina.character("mira", Card.id(cardId));

const turn = await mira.say("Morning! Anything warm?", {
  inputs: { hearts: 3 },
  allow: [{ id: "give_item", params: { item: { enum: npc.carrying } } }],
  period: "spring-3",
});

if (turn.action?.accepted && turn.action.id === "give_item") {
  const ok = inventory.add(turn.action.params.item);
  mira.report(turn, ok, ok ? "the player got it" : "backpack full");
}
```

`report` queues the result and sends it with that character's next turn, so Mira's next line knows whether the coffee reached the backpack. An action reported as not applied does not count toward its limit. An action never reported counts as done.

Here is the limit at work. On `spring-3` Mira gives a coffee and the game reports `true`. The player asks again that day. `give_item` has `perPeriod: 1` and one use this period, so it is not offered, and Mira is told why and can refuse in her own words. If the model proposes it anyway, the turn carries `accepted: false` with code `limit`, and the game applies nothing.

## What does the AI NPC remember after I load an older save?

Exactly what had happened by that save. Memory is a chain of turns on the server, and each turn points at the one before it. The game keeps only the id of the newest one.

```js
save.yumina = yumina.save();   // { v: 1, memory: "<id of the newest turn>", worlds: {} }
yumina.load(save.yumina);      // when a save is loaded; null for a new game
```

`save()` returns plain JSON: `memory` is the head of the chain, and `worlds` holds a session for each whole card the game plays through `yumina.world()`. `load()` sets the head back, and the next `say` sends it. The server reads a character's memory by walking backwards from that head, so turns played after the save are never reached. A branch the player did not save is not mixed in.

Limits come from the same walk. The server counts accepted actions along the chain from the head the game sent, up to 2,000 turns back. Load the save from before Mira's coffee and `give_item` is on offer again, because in that timeline she has not given it.

Three more facts from the code. One head covers every character in the save, up to 500 of them. A head from another Yumina account is refused with `unknown_head`, and the SDK then starts that save's memory fresh. And the server runs one turn at a time per player and game, since two turns from the same head would fork the save and the game can keep only one. The SDK queues calls for you.

## FAQ

### Does the Yumina AI NPC SDK work with Unity?

Yes. The C# SDK, `Yumina.Games`, is one .NET Standard 2.0 DLL with no third-party dependencies. It runs in Unity on Mono and IL2CPP, and in BepInEx, MelonLoader and SMAPI mods.

### Is there an AI NPC plugin for Godot?

Yes. Godot 4 projects copy the `addons/yumina` folder, which is plain GDScript with no plugin to enable. Godot .NET projects can use the C# SDK instead.

### What does a player pay to talk to an AI NPC?

Each line is charged to the player's Yumina account at the cost of the model they picked. Yumina has free models, and a player who uses their own AI key is charged nothing by Yumina.

### Can I run the AI NPC server myself?

Yes. Yumina is open source, and the open-source edition answers the same calls on your own machine. Set `selfHosted: true` and `baseUrl` in the SDK options. There is then no sign-in and no balance, and the API keys set on that server pay.

## Sources

Read on 4 December 2026, from the public repository and the developer docs.

- SDK: [packages/games/src/index.ts](https://github.com/lovetimo0421/yumina-oss/blob/main/packages/games/src/index.ts)
- Manifest and action checks: [packages/engine/src/game/manifest.ts](https://github.com/lovetimo0421/yumina-oss/blob/main/packages/engine/src/game/manifest.ts)
- Counting used actions: [packages/engine/src/game/turn.ts](https://github.com/lovetimo0421/yumina-oss/blob/main/packages/engine/src/game/turn.ts)
- The memory chain: [packages/server/src/lib/game-link/memory.ts](https://github.com/lovetimo0421/yumina-oss/blob/main/packages/server/src/lib/game-link/memory.ts)
- Docs: [How it works](https://docs.yumina.io/developers/concepts), [JavaScript](https://docs.yumina.io/developers/javascript), [C#](https://docs.yumina.io/developers/dotnet), [Godot](https://docs.yumina.io/developers/godot), [HTTP](https://docs.yumina.io/developers/http)
