Why a single prompt will not write your novel
If you ask a model for a whole story in one request, you get a short story with a rushed ending. The completion can use the rest of the 100,000-token window, but the model still tends to compress. Plot threads you set up in paragraph two are dropped by paragraph forty.
The fix is structure. You decide the shape of the story first, then generate it in pieces, and at each step you hand the model only what it needs: the fixed facts, a summary of what has happened, and the job for this chapter. The model does the writing. Your code does the remembering.
The three layers of context
Every chapter request carries three layers, ordered from most stable to most volatile.
- The story bible (about 500 to 1,500 tokens). Premise, tone, point of view, tense, characters with a line or two each, and the rules of the world. It never changes unless you change it.
- The rolling summary (about 500 to 2,000 tokens). What has happened so far, written by the model itself after each chapter, with open threads listed at the end.
- The chapter brief (about 100 to 300 tokens). The outline entry for this chapter, plus the last paragraph or two of the previous chapter so the prose joins up.
With these three layers, a request stays near 3,000 to 5,000 tokens however long the story gets. That keeps cost flat and quality steady. The alternative, resending all earlier chapters, hits the window around 75,000 words of total prompt and completion, and it makes every late chapter dearer than the first.
Step 1: create the outline as JSON
Ask for the outline in JSON mode so you can loop over it in code. JSON mode is enabled with response_format.
import json
from openai import OpenAI
client = OpenAI(
base_url="https://api.storyuncensored.com/v1",
api_key="YOUR_KEY",
)
BIBLE = (
"Premise: a salvage crew finds a sealed city under a dry sea.\n"
"Tone: slow-burn mystery, dark humour, adult characters.\n"
"POV: third person limited, past tense.\n"
"Characters: Mara (captain, stubborn), Teo (engineer, nervous), "
"Ilse (cartographer, hides her past)."
)
def make_outline(chapters=12):
r = client.chat.completions.create(
model="uncensored",
response_format={"type": "json_object"},
messages=[
{"role": "system", "content": "You plan novels. Reply with JSON only."},
{"role": "user", "content": (
BIBLE + "\n\nReturn {\"chapters\": [{\"n\": 1, \"title\": \"...\", "
"\"beats\": \"2-3 sentences\"}]} with exactly %d chapters. "
"Each chapter must raise the stakes." % chapters
)},
],
temperature=0.8,
)
return json.loads(r.choices[0].message.content)["chapters"]
Read the outline yourself before moving on. Fixing a weak middle at this stage costs a fraction of a cent. Fixing it after twelve drafted chapters costs your evening.
Step 2: draft chapters and keep the summary
The loop below writes a chapter, then asks for an updated summary. Two calls per chapter, both small.
from openai import OpenAI
client = OpenAI(
base_url="https://api.storyuncensored.com/v1",
api_key="YOUR_KEY",
)
# BIBLE and outline come from step 1
def draft_chapter(ch, summary, tail):
r = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "You are a novelist. Write vivid prose, "
"no meta commentary.\n\nSTORY BIBLE\n" + BIBLE},
{"role": "user", "content": (
"STORY SO FAR\n" + summary +
"\n\nEND OF PREVIOUS CHAPTER\n" + tail +
"\n\nWrite chapter %d, '%s'. Beats: %s\n"
"Length: about 2000 words." % (ch["n"], ch["title"], ch["beats"])
)},
],
temperature=0.9,
top_p=0.95,
)
return r.choices[0].message.content
def update_summary(summary, chapter_text):
r = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "user", "content": (
"Update this running summary with the new chapter. Keep it under "
"600 words and end with a list of open plot threads.\n\n"
"SUMMARY\n" + summary + "\n\nNEW CHAPTER\n" + chapter_text
)},
],
temperature=0.3,
)
return r.choices[0].message.content
outline = make_outline()
summary, tail = "Nothing has happened yet.", "(start of book)"
for ch in outline:
text = draft_chapter(ch, summary, tail)
summary = update_summary(summary, text)
tail = text[-1200:]
with open("chapter_%02d.txt" % ch["n"], "w") as f:
f.write(text)
Low temperature for the summary and higher for the prose is deliberate: you want faithful bookkeeping and varied writing. Samplers such as temperature, top_p, seed and the penalties are passed through, so set seed while debugging to make a bad chapter reproducible.
Prompts that keep a story coherent
- State the point of view and tense in the bible. Drift between first and third person is the most common continuity bug.
- Give each character a verbal habit. "Teo hedges every sentence" produces a voice that survives across chapters.
- Ask for a scene goal, not a word count alone. "End with Ilse lying to Mara" beats "make it exciting".
- Carry forward the last 1,200 characters of the previous chapter, as above. It fixes most seams.
- List open threads in the summary. The model then pays them off instead of inventing new ones.
For adult fiction, the API answers without content refusals for lawful adult use, so you do not need to disguise the genre in your prompts. One limit is fixed: sexual content involving minors is never allowed, and all characters in your bible should be adults.
Revising, extending and fixing short chapters
First drafts are rarely final. Three small techniques cover most revision work without restarting the loop.
Continue a cut-off chapter
When a reply hits the max_tokens you set, the response ends mid-sentence and the choice reports finish_reason as length. Append the partial text as an assistant message and ask the model to continue from exactly where it stopped. If you set no max_tokens, the completion may use whatever is left of the window, so this mostly happens when you cap it on purpose.
Rewrite with a note
Send the chapter back with one clear instruction: "Rewrite this chapter with more dialogue and less description; keep every event." One instruction per pass gives better results than a list of ten, and you can compare passes side by side.
Expand a thin outline entry
If a chapter comes back at 900 words when you wanted 2,000, the beats were probably too thin. Add two or three concrete moments to the outline entry (an argument, a discovery, a reversal) and regenerate that chapter only. Asking for "longer" without new material tends to produce padding.
Catching continuity errors with a second pass
A short checking call after each chapter is cheap and catches the errors that readers notice first: a wrong eye colour, a dead character who speaks, a clock that goes backwards. Give the model the story bible, the summary and the new chapter, and ask for a JSON list of contradictions.
import json
from openai import OpenAI
client = OpenAI(
base_url="https://api.storyuncensored.com/v1",
api_key="YOUR_KEY",
)
def check_continuity(bible, summary, chapter_text):
r = client.chat.completions.create(
model="uncensored",
response_format={"type": "json_object"},
messages=[{"role": "user", "content": (
"Find contradictions between the NEW CHAPTER and the BIBLE or "
"SUMMARY. Reply as {\"issues\": [{\"quote\": \"...\", "
"\"problem\": \"...\"}]} and use an empty list if there are none.\n\n"
"BIBLE\n" + bible + "\n\nSUMMARY\n" + summary +
"\n\nNEW CHAPTER\n" + chapter_text
)}],
temperature=0.0,
)
return json.loads(r.choices[0].message.content)["issues"]
Run it on each chapter and print the issues. Fix small ones by hand, and for larger ones regenerate the chapter with the issue pasted into the brief. The check costs about 6,500 tokens in and 150 out per chapter, which is 6,500 x $0.00000015 + 150 x $0.0000005 = $0.000975 + $0.000075 = $0.00105. For 50 chapters that adds about $0.05.
Rate limits and cost for the loop
The loop above is sequential, so it uses one concurrent request. A trial key allows 2 concurrent requests and 60 requests per minute; a full key allows 8 and 300. If you draft several books in parallel, cap your workers at 2 on a trial key, or at 8 on a full key, and handle a 429 by waiting for the Retry-After value.
Cost per chapter, with 4,000 tokens in and 2,700 out for drafting, plus 3,300 in and 800 out for the summary:
- Draft: 4,000 x $0.00000015 + 2,700 x $0.0000005 = $0.0006 + $0.00135 = $0.00195
- Summary: 3,300 x $0.00000015 + 800 x $0.0000005 = $0.000495 + $0.0004 = $0.000895
- Total per chapter: about $0.0028. A 12-chapter book is about $0.034.
Why chapter-sized calls beat scene-sized ones
Every call pays for the story bible, the summary and the instructions again. If you write 100,000 words as 200 scenes of 500 words, that fixed overhead of about 4,000 tokens is paid 200 times: 800,000 input tokens, or $0.12, against $0.03 for 50 chapters. Output is the same either way, so scene-level drafting costs about $0.1875 against $0.0975. Smaller units give you finer control, though, so use scenes where the plot is tricky and chapters where it is not.
The $0.50 trial credit, claimed on the API key page, is enough for a dozen books. Current rates and top-up bonuses are on the pricing page, and request details are in the docs. If you are still deciding which model to build on, the uncensored AI comparison lists the options.
