---
name: zenstory
description: "Documents the ZenStory Agent API: reads and manages a user's novel projects in ZenStory (chapter drafts, outlines, characters, lore, materials) with an API key, plus keyword search and AI-assembled writing context. Use when the user mentions ZenStory or a novel project stored there, or asks to read or write its chapters, outlines, characters or world-building."
metadata:
display_name: "ZenStory Novel Writing Platform"
version: "1.0.0"
api_base: "https://api.zenstory.ai/api/v1"
auth_method: "api_key"
auth_header: "X-Agent-API-Key"
auth_prefix: "eg_"
rate_limit: "read=2000/hour, write=1000/hour, search=500/hour, context=500/hour"
triggers: "write a novel, novel writing, create characters, story outline, world building, draft chapters, 写小说, 小说创作, 角色创建, 大纲规划"
capabilities: "project_management, file_crud, file_tree, version_history, keyword_search, writing_context"
file_types: "outline, draft, character, lore, material"
cli: "npx zenstory"
---
# ZenStory Novel Writing Platform
AI-assisted novel writing workbench with file management, keyword search, and writing context.
## Recommended: use the ZenStory CLI (`zenstory`)
Coding agents (Claude Code, Codex, OpenClaw, ...) should prefer the official CLI and standard Agent Skill over hand-written HTTP calls:
```bash
npx zenstory login
# paste the key at the "Paste API key:" prompt (hidden input, kept out of shell history; stored locally, mode 0600)
npx zenstory skill install # install the skill for Claude Code (--target codex|openclaw|
)
npx zenstory whoami # check login state and read/write scopes
```
The user should run the login command in their own terminal and paste the key when prompted. Never put the key
on the command line or paste it into an AI chat; if it was already pasted into a chat, regenerate it in
Settings → Agent and log in again.
## Authentication
All API requests require a valid API Key in the request header:
```
X-Agent-API-Key: eg_your_api_key_here
```
The API Key format is `eg_` prefix followed by 64 hexadecimal characters. Generate and manage API Keys in platform settings.
**Available Scopes**:
- `read` - Read projects and files
- `write` - Create and update content
## API Endpoints
| Endpoint | Method | Description | Required Scope |
|----------|--------|-------------|----------------|
| `/api/v1/agent/files/{file_id}` | DELETE | delete_file | write |
| `/api/v1/agent/files/{file_id}` | GET | get_file | read |
| `/api/v1/agent/files/{file_id}` | PUT | update_file | write |
| `/api/v1/agent/files/{file_id}/move` | POST | move_file | write |
| `/api/v1/agent/files/{file_id}/versions` | GET | list_file_versions | read |
| `/api/v1/agent/files/{file_id}/versions/{version_number}` | GET | get_file_version | read |
| `/api/v1/agent/files/{file_id}/versions/{version_number}/rollback` | POST | rollback_file_version | write |
| `/api/v1/agent/projects` | GET | list_projects | read |
| `/api/v1/agent/projects` | POST | create_project | write |
| `/api/v1/agent/projects/{project_id}` | DELETE | delete_project | write |
| `/api/v1/agent/projects/{project_id}` | GET | get_project | read |
| `/api/v1/agent/projects/{project_id}` | PUT | update_project | write |
| `/api/v1/agent/projects/{project_id}/files` | GET | list_files | read |
| `/api/v1/agent/projects/{project_id}/files` | POST | create_file | write |
| `/api/v1/agent/projects/{project_id}/writing-context` | GET | get_writing_context | read |
| `/api/v1/agent/projects/{project_id}/search` | POST | search | read |
## File Types
| Type | Purpose | Key Fields |
|------|---------|------------|
| outline | Story structure with hierarchy | title, content, parent_id, metadata |
| draft | Main content editing | title, content, parent_id, metadata |
| character | Character profiles | title, content, metadata(traits, relationships) |
| lore | World-building entries | title, content, metadata(category) |
| material | Writing materials | title, content, metadata(source, tags) |
## Usage Examples
### 1. List Projects
```bash
curl -H "X-Agent-API-Key: eg_your_key" \
"https://api.zenstory.ai/api/v1/agent/projects"
```
### 2. Create New Project
```bash
curl -X POST "https://api.zenstory.ai/api/v1/agent/projects" \
-H "X-Agent-API-Key: eg_your_key" \
-H "Content-Type: application/json" \
-d '{
"name": "My Sci-Fi Novel",
"description": "A story about interstellar travel",
"project_type": "novel"
}'
```
### 3. Create Chapter Draft
```bash
curl -X POST "https://api.zenstory.ai/api/v1/agent/projects/{project_id}/files" \
-H "X-Agent-API-Key: eg_your_key" \
-H "Content-Type: application/json" \
-d '{
"title": "Chapter 1: The Journey Begins",
"file_type": "draft",
"content": "Morning light streamed through the curtains..."
}'
```
### 4. Get Writing Context
```bash
curl -H "X-Agent-API-Key: eg_your_key" \
"https://api.zenstory.ai/api/v1/agent/projects/{project_id}/writing-context?file_id={file_id}"
```
### 5. Semantic Search
```bash
curl -X POST "https://api.zenstory.ai/api/v1/agent/projects/{project_id}/search" \
-H "X-Agent-API-Key: eg_your_key" \
-H "Content-Type: application/json" \
-d '{
"query": "protagonist adventure",
"top_k": 5
}'
```
## Scope
**Suitable for:** Novel writing, short stories, screenwriting, character design, world building, outline planning
**Not suitable for:** General Q&A, code generation, image creation, non-fiction writing, data analysis
## Complete Workflow Examples
### Workflow 1: Create a New Novel Project
```
1. POST /agent/projects → Create new project (response `folders` lists the default folders)
2. POST /agent/projects/{id}/files → Create outline file (file_type=outline, parent_id=outline folder)
3. POST /agent/projects/{id}/files → Create character profiles (file_type=character, parent_id=character folder)
4. POST /agent/projects/{id}/files → Create lore entries (file_type=lore, parent_id=lore folder)
5. GET /agent/projects/{id}/writing-context → Get writing context
6. POST /agent/projects/{id}/files → Create chapter (file_type=draft, parent_id=draft folder, order=chapter number)
```
Default folder ids are predictable: `{project_id}-lore-folder`, `-character-folder`, `-material-folder`,
`-outline-folder`, `-draft-folder` (`-script-folder` for screenplays). Move existing files with `POST /agent/files/{file_id}/move`.
### Workflow 2: Continue an Existing Chapter
```
1. GET /agent/projects/{id}/files?file_type=draft&fields=id,title → List drafts
2. GET /agent/files/{file_id} → Read current content
3. GET /agent/projects/{id}/writing-context?file_id={file_id} → Get relevant context
4. POST /agent/projects/{id}/search query="character relationships" → Search character relations
5. PUT /agent/files/{file_id} → Update draft content
```
### Workflow 3: Undo a Change
```
1. GET /agent/files/{file_id}/versions → Version history (newest first, no content)
2. GET /agent/files/{file_id}/versions/{n} → Content of version n
3. POST /agent/files/{file_id}/versions/{n}/rollback → Restore version n (history is kept; adds a new version unless the per-file version quota is full)
```
## Error Handling
API returns standardized error responses:
```json
{
"detail": "Error description",
"error_code": "ERROR_CODE",
"request_id": "req_xxx"
}
```
Common error codes:
| Error Code | HTTP Status | Description |
|------------|-------------|-------------|
| `AUTH_UNAUTHORIZED` | 401 | Missing authentication |
| `AUTH_TOKEN_INVALID` | 401 | Invalid API Key |
| `AUTH_TOKEN_EXPIRED` | 401 | API Key expired |
| `NOT_AUTHORIZED` | 403 | Insufficient permissions |
| `NOT_FOUND` | 404 | Resource not found |
| `VALIDATION_ERROR` | 422 | Request validation failed |
| `RATE_LIMIT_EXCEEDED` | 429 | Rate limit exceeded |
## Rate Limiting
Tiered rate limits by endpoint type:
| Type | Limit |
|------|-------|
| Read (read) | 2000/hour |
| Write (write) | 1000/hour |
| Search (search) | 500/hour |
| Context (context) | 500/hour |
---
For questions or suggestions, contact support or visit API docs: https://api.zenstory.ai/docs