Complete API documentation for the AI NPC System.
http://localhost:8000
Currently, no authentication is required. For production, implement API keys or OAuth2.
GET /Response:
{
"status": "online",
"message": "AI NPC System is running",
"version": "1.0.0"
}Create a new NPC with personality and background.
POST /npcRequest Body:
{
"npc_id": "string",
"name": "string",
"personality": "friendly|aggressive|mysterious|merchant|wise|comedic",
"background": "string",
"location": "string"
}Response: 201 Created
{
"npc_id": "blacksmith_01",
"name": "Thorin Ironforge",
"personality": "friendly",
"background": "A master blacksmith...",
"location": "Town Forge",
"conversation_count": 0
}Errors:
400 Bad Request- NPC already exists500 Internal Server Error- Storage failure
Retrieve NPC details by ID.
GET /npc/{npc_id}Path Parameters:
npc_id(string, required) - Unique NPC identifier
Response: 200 OK
{
"npc_id": "blacksmith_01",
"name": "Thorin Ironforge",
"personality": "friendly",
"background": "A master blacksmith...",
"location": "Town Forge",
"conversation_count": 5
}Errors:
404 Not Found- NPC doesn't exist
Delete an NPC and all associated data.
DELETE /npc/{npc_id}Path Parameters:
npc_id(string, required) - Unique NPC identifier
Response: 200 OK
{
"message": "NPC 'blacksmith_01' deleted successfully"
}Errors:
404 Not Found- NPC doesn't exist500 Internal Server Error- Deletion failure
Send a message to an NPC and receive a response.
POST /chatRequest Body:
{
"player_id": "string",
"npc_id": "string",
"message": "string"
}Example:
{
"player_id": "player_123",
"npc_id": "blacksmith_01",
"message": "Can you repair my sword?"
}Response: 200 OK
{
"npc_response": "Of course, friend! Let me take a look at that blade...",
"npc_emotion": "friendly",
"quest_offered": false
}Errors:
404 Not Found- NPC doesn't exist
Side Effects:
- Updates conversation history
- Modifies player reputation
- Increments conversation count
Retrieve past conversations between a player and NPC.
GET /history/{player_id}/{npc_id}?limit=20Path Parameters:
player_id(string, required) - Player identifiernpc_id(string, required) - NPC identifier
Query Parameters:
limit(integer, optional) - Max messages to retrieve (default: 20)
Response: 200 OK
[
{
"timestamp": "2025-12-18T10:30:00",
"player_message": "Hello!",
"npc_response": "Greetings, friend!",
"context": {
"reputation": "5"
}
}
]Check player's reputation with an NPC.
GET /reputation/{player_id}/{npc_id}Path Parameters:
player_id(string, required) - Player identifiernpc_id(string, required) - NPC identifier
Response: 200 OK
{
"player_id": "player_123",
"npc_id": "blacksmith_01",
"reputation": 15,
"level": "Friendly"
}Reputation Levels:
51-100: Trusted Ally1-50: Friendly0: Neutral-1 to -50: Disliked-51 to -100: Enemy
Request an AI-generated quest from an NPC.
POST /quest/generateRequest Body:
{
"player_id": "string",
"npc_id": "string",
"context": "string (optional)"
}Example:
{
"player_id": "player_123",
"npc_id": "blacksmith_01",
"context": "Player needs a legendary weapon"
}Response: 200 OK
{
"quest_id": "a7b3c9d1-e4f5-6789",
"title": "The Lost Mithril Ore",
"description": "Retrieve pure mithril from the Shadowmount Mines",
"difficulty": "hard",
"reward": "Legendary Weapon + 500 Gold",
"objectives": [
"Travel to Shadowmount Mines",
"Defeat the mine guardians",
"Extract pure mithril ore",
"Return to Thorin Ironforge"
]
}Errors:
404 Not Found- NPC doesn't exist
enum PersonalityType {
FRIENDLY = "friendly",
AGGRESSIVE = "aggressive",
MYSTERIOUS = "mysterious",
MERCHANT = "merchant",
WISE = "wise",
COMEDIC = "comedic"
}{
npc_id: string; // Required
name: string; // Required
personality: PersonalityType; // Required
background: string; // Required
location?: string; // Optional, default: "Unknown"
}{
npc_id: string;
name: string;
personality: PersonalityType;
background: string;
location: string;
conversation_count: number;
}{
player_id: string; // Required
npc_id: string; // Required
message: string; // Required
}{
npc_response: string;
npc_emotion?: string;
quest_offered: boolean;
}{
quest_id: string;
title: string;
description: string;
difficulty: string; // "easy" | "medium" | "hard"
reward: string;
objectives: string[];
}All error responses follow this format:
{
"detail": "Error message describing what went wrong"
}200 OK- Successful request201 Created- Resource created successfully400 Bad Request- Invalid request data404 Not Found- Resource doesn't exist500 Internal Server Error- Server-side error
Currently no rate limiting is implemented. For production:
- Implement per-IP rate limiting
- Consider per-user rate limiting
- Add retry-after headers
Planned webhook support for:
- NPC state changes
- Quest completion
- Reputation milestones
Planned WebSocket endpoint for real-time chat:
ws://localhost:8000/ws/{player_id}/{npc_id}
import requests
# Create NPC
response = requests.post(
"http://localhost:8000/npc",
json={
"npc_id": "wizard_01",
"name": "Gandalf",
"personality": "wise",
"background": "A powerful wizard",
"location": "Tower"
}
)
print(response.json())
# Chat with NPC
response = requests.post(
"http://localhost:8000/chat",
json={
"player_id": "player_1",
"npc_id": "wizard_01",
"message": "I seek your wisdom"
}
)
print(response.json()["npc_response"])// Create NPC
const createNPC = async () => {
const response = await fetch('http://localhost:8000/npc', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
npc_id: 'wizard_01',
name: 'Gandalf',
personality: 'wise',
background: 'A powerful wizard',
location: 'Tower'
})
});
return await response.json();
};
// Chat with NPC
const chat = async () => {
const response = await fetch('http://localhost:8000/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
player_id: 'player_1',
npc_id: 'wizard_01',
message: 'I seek your wisdom'
})
});
const data = await response.json();
console.log(data.npc_response);
};# Create NPC
curl -X POST http://localhost:8000/npc \
-H "Content-Type: application/json" \
-d '{
"npc_id": "wizard_01",
"name": "Gandalf",
"personality": "wise",
"background": "A powerful wizard",
"location": "Tower"
}'
# Chat with NPC
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{
"player_id": "player_1",
"npc_id": "wizard_01",
"message": "I seek your wisdom"
}'For endpoints returning lists, pagination will be implemented:
GET /npcs?page=1&limit=20Visit the interactive API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc