EN ▾
Uncensored Story

Uncensored API. Pay per token.

Agent for User Story Creation With a 100k Context API

A story agent is a loop around a chat model: it plans, writes a piece, stores what changed, and carries a compact memory into the next call. This guide builds one against an OpenAI-compatible endpoint with a 100,000-token window.

Updated

Robotic hand arranging story cards in a loop, illustrating an AI agent that writes stories chapter by chapter

Key points

  1. The agent keeps a story bible outside the model and reads or updates it through tool calls.
  2. A 20-chapter novella with summaries costs about $0.038; resending every chapter costs about $0.089.
  3. 100,000 tokens covers prompt and completion together, so budget the bible, summary and next chapter.
  4. The same loop works for agile user stories if you switch the output to JSON mode.

Two meanings of user story, and the one covered here

People who type agent for user story creation into a search box mean one of two things. Some want an agent that writes agile user stories ("As a customer, I want...") from a feature request. Others want an agent that writes stories for a user: a reader gives a premise, and the agent turns it into chapters, scenes and characters. This article is built mainly for the second reading, because that is where a large context window and a model that does not refuse dark themes matter.

The architecture carries over to the first reading, though. At the end there is a short section on producing backlog items as strict JSON.

The endpoint is OpenAI-compatible, the model ID is uncensored, and it is a single open-weight model tuned to answer without content refusals for lawful adult use. Fiction for adults often includes violence, grief, crime or morally grey characters, and a model that stops mid-scene to lecture breaks the loop of an agent. Sexual content involving minors is not allowed, and the agent should enforce the same rule in its own system prompt.

The shape of a story agent

An agent here is not magic. It is four pieces you control.

  1. A story bible. Characters, setting, tone rules and the facts established so far. This lives in your code or a database, not only in the chat history.
  2. A running summary. A short recap of the chapters already written, updated after each one.
  3. Tools. Functions the model can call to read or change the bible, such as get_character and add_fact.
  4. A loop. Plan the chapter, write it, extract new facts, update the summary, repeat.

Why avoid keeping everything in one long chat? You can, up to a point, and the 100,000-token window is large enough to hold a lot of prose. But the window includes the completion, a model reading 80,000 tokens of earlier text pays attention unevenly, and every call re-bills the full history. A bible plus summary is cheaper and keeps continuity facts in one place where you can inspect and correct them.

Step 1: store the bible and expose it as tools

Start with a plain dictionary. The tools below let the model read a character sheet and record a new fact. Because tool calling follows the OpenAI format, the model returns tool_calls, you run them, and you send results back with role: "tool".

import json
from openai import OpenAI

client = OpenAI(base_url="https://api.uncensoredstory.top/v1", api_key="YOUR_KEY")

bible = {
    "tone": "slow-burn noir, third person past tense, no happy coincidences",
    "characters": {
        "Mara Voss": "ex-detective, 41, drinks too much, owes a favor to the harbor boss",
        "Teodor": "harbor boss, polite, never raises his voice",
    },
    "facts": ["The lighthouse has been dark for three weeks."],
}

tools = [
    {"type": "function", "function": {
        "name": "get_character",
        "description": "Read a character sheet by name",
        "parameters": {"type": "object",
                       "properties": {"name": {"type": "string"}},
                       "required": ["name"]}}},
    {"type": "function", "function": {
        "name": "add_fact",
        "description": "Record a new established fact about the story world",
        "parameters": {"type": "object",
                       "properties": {"fact": {"type": "string"}},
                       "required": ["fact"]}}},
]

def run_tool(name, args):
    if name == "get_character":
        return bible["characters"].get(args["name"], "unknown character")
    if name == "add_fact":
        bible["facts"].append(args["fact"])
        return "recorded"
    return "unknown tool"

Keep tool descriptions to one line. They are sent with every request, so long descriptions are input tokens you pay for on each call.

Step 2: the chapter loop

The loop sends the bible, the summary so far and the chapter brief. If the model asks for tools, run them and call again. When it returns plain text, that is the chapter.

# client, bible, tools and run_tool come from step 1 (base_url https://api.uncensoredstory.top/v1)
summary = "Mara has just learned the harbor boss wants the lighthouse keeper found."

def write_chapter(brief):
    system = (
        "You are a fiction-writing agent for adult readers. "
        "Tone rules: " + bible["tone"] + ". "
        "Established facts: " + " | ".join(bible["facts"]) + ". "
        "Never write sexual content involving minors. "
        "Use get_character before writing a named character's first line, "
        "and add_fact after introducing anything the next chapter must remember."
    )
    messages = [
        {"role": "system", "content": system},
        {"role": "user", "content": "Story so far: " + summary + "\n\nWrite the next chapter, about 1500 words. Brief: " + brief},
    ]
    for _ in range(6):  # hard cap on tool rounds
        resp = client.chat.completions.create(
            model="uncensored", messages=messages, tools=tools,
            temperature=0.9, top_p=0.95,
        )
        msg = resp.choices[0].message
        if not msg.tool_calls:
            return msg.content
        messages.append(msg)
        for call in msg.tool_calls:
            result = run_tool(call.function.name, json.loads(call.function.arguments))
            messages.append({"role": "tool", "tool_call_id": call.id, "content": result})
    raise RuntimeError("too many tool rounds")

chapter = write_chapter("Mara visits Teodor's office and learns what he is really afraid of.")
print(chapter)

The cap on tool rounds is not decoration. Without it, a confused model can call the same tool repeatedly, and you pay for every round. Each round resends the messages so far, so a runaway loop gets more expensive with every turn.

Step 3: summarize, then continue

After each chapter, make one more call that updates the running summary. Ask for a fixed size, for example 150 words, so the summary does not grow.

# same client as above: base_url https://api.uncensoredstory.top/v1, model uncensored
def update_summary(old_summary, chapter_text):
    resp = client.chat.completions.create(
        model="uncensored",
        messages=[
            {"role": "system", "content": "Rewrite the story summary to include the new chapter. Maximum 150 words. Plot events and character state only."},
            {"role": "user", "content": "Old summary: " + old_summary + "\n\nNew chapter:\n" + chapter_text},
        ],
        temperature=0.2,
    )
    return resp.choices[0].message.content

summary = update_summary(summary, chapter)

A low temperature suits the summary and a higher one suits the prose. If you want to compare two takes on a scene, pass a fixed seed and change only the brief, so differences come from your change and not from sampling noise.

Your premise is the thing a human edits. Show the summary and the bible to the reader between chapters and let them correct a wrong fact before the next call. That one step prevents most continuity drift.

Keeping continuity honest

Long fiction breaks in predictable places, and an agent can guard against most of them with cheap checks.

  • Names and traits drift. A character described with grey eyes in chapter 2 gets green eyes in chapter 9. Store physical details in the sheet and make the first rule of the system prompt "use get_character before writing a named character".
  • Dead characters return. Add a status field to each sheet and update it with a tool call such as set_status whenever someone dies, leaves or changes sides.
  • The tone softens. Over many chapters, models tend to move toward resolution and reassurance. Keep the tone rule in the bible, repeat it in each system prompt, and add a brief line per chapter that says what must stay unresolved.
  • Chapters repeat each other. Include the last two chapter openings in the brief and tell the model not to reuse their structure.

A second pass can also act as an editor. Send the finished chapter and the bible to a separate call with the instruction "list contradictions with the bible as JSON" and a low temperature. It costs a few thousand input tokens, well under a tenth of a cent, and catches mistakes before the reader does.

What a novella costs

Prices are $0.15 per 1M input tokens and $0.50 per 1M output tokens. Take a 20-chapter novella with chapters of about 1,500 words, which is roughly 2,000 tokens of output each (a rough rule for English prose; measure your own text). Each call sends the bible, brief and summary: about 6,000 input tokens.

Bible and summary approach

  • Input: 20 x 6,000 = 120,000 tokens x $0.15 / 1M = $0.018
  • Output: 20 x 2,000 = 40,000 tokens x $0.50 / 1M = $0.02
  • Total: $0.038

Resend every chapter approach. Say the fixed part is 4,000 tokens and each earlier chapter adds 2,000. Call k sends 4,000 + (k - 1) x 2,000 tokens.

  • Input: 20 x 4,000 + 2,000 x (0 + 1 + ... + 19) = 80,000 + 380,000 = 460,000 tokens
  • Input cost: 460,000 x $0.15 / 1M = $0.069
  • Output cost: $0.02 (same 40,000 tokens)
  • Total: $0.089

Both are cheap in absolute terms. The gap matters at scale, and it matters for the window: call 20 in the second approach sends 42,000 tokens before it writes anything. That still fits in 100,000, but a 60-chapter epic would not. Summaries scale; full history does not. Check the pricing page for the current rates and the top-up bonuses, and note that failed or refused requests are not charged.

Using the same loop for agile user stories

If your goal is backlog items, replace the prose chapter with structured output. JSON mode returns a valid object, and you describe the fields in the prompt.

# same client: base_url https://api.uncensoredstory.top/v1
resp = client.chat.completions.create(
    model="uncensored",
    response_format={"type": "json_object"},
    messages=[
        {"role": "system", "content": "Return JSON: {\"stories\": [{\"title\": str, \"as_a\": str, \"i_want\": str, \"so_that\": str, \"acceptance\": [str]}]}"},
        {"role": "user", "content": "Feature request: let users export their order history as CSV."},
    ],
    temperature=0.3,
)
print(resp.choices[0].message.content)

Validate the fields in your own code and retry once on a missing key. For ordinary business backlogs, any capable chat model will do, so the uncensored model is a better pick when your product is fiction or roleplay and refusals would stall the pipeline.

Limits and practical settings

A full key allows 8 concurrent requests and 300 requests per minute. Run chapters of one story in sequence, since each needs the last, but generate several stories in parallel up to the concurrency cap. Over a limit you get HTTP 429 with rate_limited or concurrency; on overload the response carries Retry-After: 5. If you stream chapters to a reader, remember that a stream holds its slot until it ends.

New users can try all of this on the $0.50 trial, claimed with one click on the API key page after sign-up. It lasts 7 days and needs no card. The trial is enough for the whole 20-chapter run above many times over. Full request details are in the API docs, and the account steps are explained in the key setup walkthrough.

Questions and answers

Does a story agent need the full 100k context window?

No. Most agents work better with a bible and a short summary of about 6,000 tokens per call. The large window is a safety margin, not a target.

Can the model call tools while writing fiction?

Yes. Tool calling uses the OpenAI format with tools, tool_calls and role tool messages, so a story agent can read character sheets or record facts mid-chapter.

How much does a 20-chapter story cost?

About $0.038 with a bible and summary approach, or about $0.089 if you resend every earlier chapter, assuming 2,000 output tokens per chapter.

Is any content blocked?

The model is tuned to answer without refusals for lawful adult use. Sexual content involving minors is never allowed.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key