NPC Interaction
Base URL: https://loremind.peekgames.dev/api/loremind/v1
The runtime NPC endpoint is the stable integration surface for your game. Call it from your backend with a Server Key. Want to try it first? See the API Quickstart.
POST /npc/interact
Generate an NPC response to player input. This is the primary endpoint for NPC interactions.
Authentication: Server Key (sk_server_*)
Request Body
{
// Required
text: string; // Player's message (max 2,000 chars)
entityMindId: string; // Entity Mind ID (provides name, personality, knowledge filters)
playerId: string; // Your player identifier (max 255 chars; used for rate limiting,
// memory, and conversation tracking)
// Optional
context?: {
location?: string; // Current location name
locationDetails?: string; // Location description
timeOfDay?: string; // "morning", "evening", etc.
weather?: string; // Weather conditions
atmosphere?: string; // Scene mood ("peaceful", "tense", ...)
situation?: string; // Interaction type ("shopping", "combat", ...)
npcMood?: string; // NPC's current mood
npcActivity?: string; // What the NPC is doing
playerAppearance?: string; // How player looks to NPC
playerReputation?: string; // How the NPC views the player
playerVisibleItems?: string[]; // Notable items the player carries
nearbyCharacters?: string[]; // Other characters present
nearbyObjects?: string[]; // Notable objects present
recentEvents?: string[]; // Recent world events
custom?: string; // Freeform game-specific context (max 500 chars)
};
memory?: {
retrieve?: boolean; // Retrieve past memories for this player and store new ones (default: false)
};
playerAssertion?: string; // Token your backend signed for playerId (max 4,096 chars).
// Required for memory requests when your project requires
// signed players; ignored otherwise. See Signed Players.
activeKnowledgeTags?: string[]; // Narrow which lore the NPC can reference (by tag name).
// Max 50 tags, 100 chars each. Can only restrict the
// Entity Mind's configured tags, never expand them.
// Tags the Entity Mind doesn't have are ignored with a
// warning; if none of them exist, the request fails
// (see Unknown Knowledge Tags below).
conversationHistory?: Array<{ // Max 50 messages, 10,000 chars per message.
role: "user" | "assistant"; // The server keeps the most recent messages up to the
content: string; // project's max session length.
}>;
}The request schema is strict: unknown fields are rejected with a 400 error. String fields inside context are capped at 200 characters (500 for custom), arrays at 10 items (100 characters per item), and the context block at 2,000 characters overall.
Response
{
success: true;
response: string; // NPC's response text
character: string; // Character name
metadata: {
memoryCheckpoint?: boolean; // True when session hit max length and memories were auto-saved
warnings?: string[]; // Non-fatal notices (e.g. ignored knowledge tags)
};
}Example Request
curl -X POST https://loremind.peekgames.dev/api/loremind/v1/npc/interact \
-H "Authorization: Bearer sk_server_your_key" \
-H "Content-Type: application/json" \
-d '{
"text": "What can you tell me about the dragon?",
"entityMindId": "em_abc123",
"playerId": "steam_76561198012345678",
"context": {
"location": "Blacksmith Shop",
"timeOfDay": "evening",
"weather": "rainy"
},
"memory": {
"retrieve": true
},
"activeKnowledgeTags": ["dragon-war", "village-history"]
}'Example Response
{
"success": true,
"response": "The dragon? Aye, I've heard the rumors. Spotted near the old watchtower, they say. If you're thinking of going after it, you'll need better steel than what you're carrying.",
"character": "Grom the Blacksmith",
"metadata": {}
}Error Responses
| Status | Error | Description |
|---|---|---|
| 400 | Missing or empty text | No player message provided |
| 400 | Text too long | Message exceeds 2,000 characters |
| 400 | Missing entityMindId | entityMindId is required |
| 400 | Missing playerId | playerId is required for API key authentication |
| 400 | Unknown field(s) | Request contains fields not in the schema |
| 400 | Entity Mind has no knowledge tags configured | Configure knowledge tags in the dashboard first |
| 400 | Unknown knowledge tags (code UNKNOWN_KNOWLEDGE_TAGS) | None of the activeKnowledgeTags exist on the Entity Mind, so there's no lore to answer from. No reply, not charged. See Unknown Knowledge Tags |
| 401 | Invalid API key | API key is missing, malformed, or revoked |
| 402 | Insufficient credits | Team balance too low |
| 403 | Invalid authentication | Editor keys cannot be used; use a Server Key |
| 403 | Terms of Service not accepted | Nobody who runs the team accepted updated Terms within 30 days; see Terms Not Accepted |
| 403 | Player assertion required (code PLAYER_ASSERTION_REQUIRED) | Your project requires signed players and this memory request has no playerAssertion. Not charged |
| 403 | Invalid player assertion (code PLAYER_ASSERTION_INVALID) | The playerAssertion is malformed, expired, valid for more than 1 hour, wrongly signed, or for another player. Not charged |
| 404 | Project not found | Invalid project or key |
| 404 | Entity Mind not found | Invalid entityMindId |
| 429 | Rate limit exceeded | Too many requests (see Retry-After header and retryAfter field) |
| 503 | Lore unavailable | The NPC's lore couldn't be searched, so no reply was made. Not charged. Carries a Retry-After header; see Lore Unavailable |
| 503 | Generation failed | The language model failed to reply. Not charged. No Retry-After header |
Rate limit defaults and 429 behavior are covered in Errors & Rate Limits.
Unknown Knowledge Tags (400)
activeKnowledgeTags can only narrow the Entity Mind's own tags. LoreMind checks each requested tag against them:
- Some tags unknown: the unknown ones are ignored, the request searches the tags that do exist, and the NPC replies.
metadata.warningsnames the ignored tags. - All tags unknown: there is no lore to search, and an NPC never replies without its lore. The request fails with
400, no reply is generated, and you aren't charged:
{
"error": "Unknown knowledge tags",
"code": "UNKNOWN_KNOWLEDGE_TAGS",
"message": "None of the requested activeKnowledgeTags exist on this Entity Mind: act-3, castle. No reply was generated.",
"unknownTags": ["act-3", "castle"]
}Retrying the same request won't help. Compare the tags with the Entity Mind's tags in the dashboard (a renamed or removed tag is the usual cause), or leave activeKnowledgeTags out to use all of the Entity Mind's tags.
Lore Unavailable (503)
Every NPC reply uses your project's lore. If LoreMind can't search the lore for a request, it doesn't reply without it: the request fails with 503 Lore unavailable instead, and you aren't charged for it. A search that runs and finds nothing relevant (an off-topic question, say) is not an error: the NPC still replies.
The response carries a Retry-After header, in seconds, and the same value in the body's retryAfter field:
HTTP/1.1 503 Service Unavailable
Retry-After: 5
Content-Type: application/json
{
"error": "Lore unavailable",
"message": "The NPC's lore could not be searched right now. Please try again.",
"retryAfter": 5
}How to handle it:
- Retry after the wait. Wait at least
Retry-Afterseconds, then send the same request again. Cap the number of attempts, and show the player an error if they all fail. - Retry nothing else automatically. A
503that carriesRetry-Afteris the only response worth retrying on its own. Never retry a request that timed out or lost its connection: LoreMind may have finished the first request, charging for it and storing any memories it made. - Don't invent a reply. Show the player that the NPC can't answer right now. Don't substitute canned NPC lines: they don't come from the NPC's lore either.
Response Time
The first request after a period of inactivity can take much longer than usual, sometimes minutes. LoreMind allows up to 600 seconds per request.
Set every timeout between your game and LoreMind to at least 600 seconds: your HTTP client, your function or server timeout, and any load balancer or proxy in between. Server Integration lists the settings for common platforms.
Next Steps
- API Quickstart - Try this endpoint with curl
- Server Integration - Production patterns for Nakama, PlayFab, Node.js, and Mirror
- Runtime Context - What each context field does
- Long-Term Memory - How memory retrieval works
- Signed Players - Require your backend to sign each player for memory requests