Long-Context Novel Generation: Token Cost and Writing Style Optimization Practices
This article explains how to generate long-form Chinese novels with large language models while keeping token costs under control and preserving a consistent writing style. It covers the role of extended context windows and prefix caching, how to turn a writing methodology into a reusable skill file with state management, how to align style using a personal corpus, and how to remove English-style sentence patterns that make Chinese text feel artificial. It also describes structured map and character files, a practical cost model, and three engineering gaps that usually explain poor results. Readers will find concrete prompt layering, YAML and Python examples, and a transferable optimization order.
1. Background: Why Long-Form Chinese Writing Feels “Hard to Use”
Many developers notice a counterintuitive pattern after connecting a large language model to an AI coding tool: the model performs reliably on code tasks, but the experience drops sharply when it switches to long-form Chinese content such as full-length novels. Three problems show up repeatedly: conflicting settings between earlier and later chapters, drifting character voice, and a strong “AI flavor.” It is common to blame insufficient model capability, but from an engineering perspective the main cause is the absence of process constraints and corpus constraints.
In an original practice, the author embedded a long-context model into an AI coding tool, first searched a code hosting community for several “AI novel writing” skill packages, had the tool parse their internal logic, and then abstracted a new skill tailored to Chinese web novel generation. Next, the author exported years of public answers and articles from a Q&A community into a local knowledge base for style alignment. The final output was a long work of roughly 800,000 Chinese characters, consuming about 75 million tokens, of which only about 1.1 million were cache misses. The actual cost was under four yuan. The key takeaway from these numbers is not “cheap,” but structural: an extended context window plus high cache reuse is what makes long-form writing cost-controllable.
2. Prerequisites: Extended Context and Caching
The first hurdle in long-form writing is memory. The traditional approach generates segments and stitches them together manually; the settings document grows thicker, yet the model can only see the most recent few thousand characters, so character traits, place names, and timelines inevitably drift. The value of an extended context window is that the worldview, character cards, map information, and summaries of completed chapters can all be loaded into the same window, so the model can still “see” the foreshadowing planted in chapter one while writing chapter fifty.
The second hurdle is cost. Under token-based billing, if an identical repeated prefix (system prompt, skill description, settings collection) cannot be reused, cost grows roughly with the square of the chapter count. Mainstream inference services generally offer context caching: once the same prefix hits the cache, that portion is billed significantly lower than a first computation. In practice, the cache-miss portion was about 1.5%, meaning the vast majority of input was a stable prefix. This is the mechanism that lowers the cost of long tasks, not any vendor’s “exclusive discount.”
A schematic call structure follows (pseudocode, expressing only the idea of prefix layering):
[Stable prefix: character cards + map + style rules + skill description] # Highest hit rate, unchanged throughout[Rolling summary: completed chapters compressed to 2k~4k characters] # Updated every 5 chapters[Current window: latest 1~2 chapters of raw text + this chapter's outline] # The changing part[Output constraints: word count, POV, list of banned sentence patterns]
3. Process Engineering: Turning Writing Experience into a “Skill”
A one-off prompt cannot support 800,000 characters; the methodology must be solidified into a loadable skill file. The transferable abstraction steps are:
- Sampling and decomposition: collect several public writing skill definitions and have the tool summarize their structure (character setting layer, outline layer, chapter generation layer, review layer).
- Rewriting into your own skill: keep the layered idea, replace it with your own genre and pacing requirements, and define the input/output contract clearly.
- Adding state management: the skill needs a “progress file” recording completed chapters, unrecovered foreshadowing, and current character states, to avoid context bloat.
- Iteration loop: after each chapter is generated, automatically run a consistency check; if it fails, roll back and rewrite rather than continuing forward.
Keep the core fields of the skill file to a minimal set; fewer fields mean more stability:
skill:name: long_form_novelinputs: [worldview, characters, map, style_rules, outline]state: {chapter_index, open_threads, character_status}checks: [timeline_conflict, name_consistency, banned_patterns]output: {target_words, pov, chapter_summary}
4. Style Alignment: Use Your Own Corpus Instead of Generic Prompts
Much of the “AI flavor” comes from the corpus distribution. The model’s default Chinese style is an “encyclopedic, balanced expression” that differs from any specific author’s feel. Organizing personal historical public text into a local knowledge base and having the model first extract describable features (sentence length distribution, paragraph rhythm, colloquialisms, argumentation habits, punctuation preferences), then writing those features into explicit rules, works far better than simply saying “imitate my style.”
Three layers of constraints are recommended: a statistical layer with quantifiable metrics such as mean and variance of sentence length and dialogue ratio; a lexical layer listing frequently used self-coined words and banned words; and a structural layer specifying the opening hook, scene-switch frequency, and the position of chapter-end suspense. When all three layers constrain at once, style drift decreases markedly.
5. The Overlooked Key Issue: English Syntax Pollution in Chinese
The most valuable finding of the original practice is that the sense of floating in Chinese writing often does not come from a poorly written prompt, but from the model reusing English syntax while generating Chinese. Typical forms include:
- Frequent “not… but…” constructions (bù shì… ér shì…), mirroring the English contrast structure, which is far less dense in Chinese;
- Overuse of long attributives with “de” and passive constructions, with subjects repeatedly omitted or repeatedly supplied;
- Paragraphs that open with abstract generalization and close with a concrete example, an English expository habit, whereas Chinese novels more often lead with action and imagery;
- Excessive transition words (however, but, only), which fragments the rhythm.
The remedy is to write “negative constraints” into the skill’s check layer and to run automatable statistical validation:
banned = ["不是", "而是", "然而", "不仅仅是", "从某种意义上说"]def check_style(text):hits = {w: text.count(w) for w in banned}density = sum(hits.values()) / max(len(text) / 1000, 1)return density, hits # Trigger a rewrite when density exceeds the threshold
Positive rewriting rules work better in combination: turn contrast sentences into parallel action sentences, turn abstract generalizations into perceivable details, and turn passive sentences back to the actor’s perspective. In testing, this single adjustment typically improved “readability” more than piling on additional prompts.
6. Configurable Management: Maps and Character Cards
Once a work reaches the scale of hundreds of thousands of characters, settings retrieval itself becomes a bottleneck. A workable approach is to split maps and character cards into structured files and inject them on demand rather than in full: a map records locations, adjacency relations, current factions, and events that have occurred; a character card records identity, goals, speaking habits, relationship changes, and chapters of appearance. When generating a chapter, load only the relevant entries, which both controls context size and reduces the chance of setting conflicts. In engineering terms, this step is equivalent to adding an “index layer” to the writing system.
7. Cost Model and Transferable Conclusions
Abstracting the above chain into a general model: total cost ≈ cache-miss prefix tokens × unit price + output tokens × unit price. The higher the share of stable prefixes and the more fully they are reused, the closer the marginal cost per chapter comes to being determined by output alone. Therefore the optimization order should be: first improve prefix stability and cache reuse, then compress the rolling summary, and only then consider switching models. If hosted on general cloud capabilities, you can combine object storage to hold corpora and manuscripts, a message queue to decouple chapter generation tasks, and logging and monitoring services to track token consumption and failed retries; these are all common industry product categories and do not bind you to any specific solution.
In summary, the root cause of “hard to use” long-form Chinese generation usually lies not in the model but in three engineering gaps: missing state management for extended context, missing cost structure from reusable prefixes, and missing negative constraints against English syntax. Filling these three gaps brings 800,000-character-scale writing into a stable, budgetable, and iterable state.
