Get an NPC talking in under 60 seconds:
All API calls require two headers:
| Header | Description |
|---|---|
x-api-key | Your API key |
x-game-id | Your game identifier (tenant isolation) |
POST /api/npcs
{
"name": "Grok the Blacksmith",
"role": "merchant",
"faction": "village_guard",
"location": "blacksmith_shop",
"personality": {
"traits": ["gruff", "honest", "protective"],
"speechStyle": "gruff",
"backstory": "Former soldier who retired to smithing",
"values": ["honor", "craft", "family"],
"quirks": ["always mentions the weather"]
},
"inventory": [
{ "item": "iron_sword", "price": 50, "quantity": 2 },
{ "item": "shield", "price": 30, "quantity": 1 }
]
}
POST /api/npcs/:npcId/event
{
"type": "player_dialogue",
"playerId": "player_joe",
"message": "Do you have any swords for sale?",
"context": {
"location": "blacksmith_shop",
"timeOfDay": "morning",
"weather": "sunny",
"playerReputation": 75,
"playerLevel": 12
}
}
Response:
{
"response": {
"dialogue": "Aye lad, got a fine iron blade. Fifty gold.",
"emotion": "cheerful",
"action": { "type": "gesture", "target": "display_rack" },
"tradeOffer": { "item": "iron_sword", "price": 45 },
"memoryUpdated": true
},
"tokenUsage": { "input": 1200, "output": 85, "calls": 1 }
}
Connect to ws://host:port/ws?apiKey=xxx&gameId=yyy
Send events:
{ "action": "event", "data": { "type": "player_dialogue", "npcId": "...", "message": "...", "context": {...} } }
{ "action": "subscribe", "npcIds": ["npc1", "npc2"] }
PATCH /api/npcs/:npcId — Update any NPC properties (partial update).
curl -X PATCH http://localhost:18542/api/npcs/{npcId} \
-H "x-api-key: your-key" \
-H "x-game-id: my-game" \
-H "Content-Type: application/json" \
-d '{"location": "town_square", "mood": {"emotion": "angry", "intensity": 0.8, "cause": "theft"}}'
POST /api/npcs/generate — AI-generate an NPC with full persona, psychology, and schedule.
curl -X POST http://localhost:18542/api/npcs/generate \
-H "x-api-key: your-key" \
-H "x-game-id: my-game" \
-H "Content-Type: application/json" \
-d '{"role": "merchant", "name": "Grok"}'
Returns a full NPC with cognitive extensions: persona (OCEAN personality, backstory, fears, ambitions), schedule (daily routines), and psychology (stress, trauma, goals, emotions).
POST /api/npcs/generate-batch — Generate multiple NPCs with social relationships.
curl -X POST http://localhost:18542/api/npcs/generate-batch \
-H "x-api-key: your-key" \
-H "x-game-id: my-game" \
-H "Content-Type: application/json" \
-d '{"count": 5, "role": "guard"}'
Returns { npcs: [...], socialLinks: [...] } — NPCs plus auto-generated relationships between them.
POST /api/events — Send multiple events in one request.
{
"events": [
{ "type": "player_dialogue", "npcId": "npc1", "playerId": "p1", "message": "Hello!", "context": {...} },
{ "type": "player_approached", "npcId": "npc2", "playerId": "p1", "context": {...} }
]
}
Returns { results: [EventResult, ...] } — one result per event, in order.
Copy sdk/unity/ into Assets/Plugins/AINPCEngine/
var client = new NPCEngineClient("http://localhost:18542", "key", "my-game");
// Talk to an NPC
var result = await client.Say(npcId, "player1", "Hello!", context);
Debug.Log(result.response.dialogue);
// AI-generate an NPC with full persona
var npc = await client.GenerateNPC(new GenerateNPCRequest { role = "merchant" });
// Batch-generate NPCs with relationships
var batch = await client.GenerateBatch(new GenerateBatchRequest { count = 5, role = "guard" });
// Send batch events
var results = await client.SendBatchEvents(new BatchEventItem[] { ... });
Copy sdk/unreal/AINPCEngine/ into your project's Plugins/ folder and enable in the Plugin Manager.
// Create client
UNPCEngineClient* Client = NewObject<UNPCEngineClient>();
Client->Init("http://localhost:18542", "key", "my-game");
// Bind response delegate
Client->OnEventResult.AddDynamic(this, &AMyActor::OnNPCResponse);
// Talk to an NPC
FGameContext Context;
Context.Location = "blacksmith_shop";
Context.TimeOfDay = "morning";
Client->Say(NpcId, "player1", "Got any swords?", Context);
// AI-generate an NPC
FGenerateNPCRequest GenReq;
GenReq.Role = "merchant";
Client->GenerateNPC(GenReq);
Full Blueprint support — all methods are BlueprintCallable and responses fire BlueprintAssignable delegates.
Copy sdk/godot/addons/ainpcengine/ into your project's addons/ folder. Enable in Project → Project Settings → Plugins.
var client = AINPCEngineClient.new()
client.setup("http://localhost:18542", "key", "my-game")
add_child(client)
# Talk to an NPC
var context = AINPCModels.game_context("blacksmith", "morning", "sunny")
var result = await client.say(npc_id, "player1", "Got any swords?", context)
print(result.response.dialogue)
# AI-generate an NPC
var npc = await client.generate_npc("merchant", "Grok")
# Batch-generate NPCs with relationships
var batch = await client.generate_batch(5, "guard")
Uses Godot 4 await pattern. WebSocket client available via AINPCWebSocket class for real-time streaming.
| Event | Experts | Use When |
|---|---|---|
player_approached | Dialogue + Social | Player enters NPC range |
player_dialogue | Dialogue | Player speaks to NPC |
combat_started | Combat + Dialogue | Fight begins |
trade_requested | Trade + Dialogue | Player wants to buy/sell |
quest_accepted | Quest + Dialogue | Player takes a quest |
quest_completed | Quest + Social + Dialogue | Player finishes quest |
ambient_trigger | Ambient | Idle/background behavior |
world_event | Ambient + Social | Weather change, explosion, etc. |
npc_interaction | Social + Dialogue | NPC-to-NPC interaction |