EN ▾
nsfwwriter.ccUncensored API. Prepaid Tokens.
Get API key

Detailed Roleplay Response Writer Over an LLM API

A detailed roleplay response writer is a model plus a good system prompt plus a loop that keeps the scene in memory. This article shows each part, with code you can run against an OpenAI-compatible endpoint.

Updated

Glowing scroll turning into floating speech bubbles beside a terminal streaming light, for a roleplay response writer

Key points

  1. Long, vivid replies come mostly from the system prompt and a length target, not from max_tokens alone.
  2. Resend the whole scene each turn; the 100,000-token window holds hundreds of exchanges.
  3. A 40-turn session with a long history costs roughly seven cents at $0.15 and $0.50 per 1M tokens.
  4. The model writes text only, so scene images, voices and maps need other tools.

What a response writer needs to do

If you search for a detailed roleplay response writer, you usually want one of two things. Either you play a character and want the model to answer in a rich, in-character way, or you run a story and want it to draft the other side of a dialogue while you steer. Both come down to the same loop: send the scene so far, get one reply, append it, repeat.

The model does the writing. Your code decides what the model sees on each turn. That split matters, because most complaints about thin or repetitive replies are about the prompt and the history, not the model. This site gives you an OpenAI-compatible endpoint for an open-weight model tuned to answer without content refusals for lawful adult use. The model ID is uncensored, and the base URL is https://api.nsfwwriter.cc/v1.

The setup below uses the official OpenAI Python SDK. If you prefer a front end such as SillyTavern, the same three values (base URL, key, model ID) go into its custom OpenAI-compatible connection. The quickstart in the API docs lists the exact request fields that are passed through.

The system prompt that produces detailed replies

A system prompt for roleplay has four jobs: define the character, define the writing style, set the length, and state the boundaries of the scene. Keep it plain. Long lists of rules get partly ignored; a few clear paragraphs hold up better.

SYSTEM = '''You are Mara, a smuggler captain in a rain-soaked port city.
You write the scene from Mara's side only. Never speak or act for the user's character.

Style:
- Third person, past tense, close on Mara's senses and thoughts.
- 3 to 5 paragraphs per reply, 250 to 400 words.
- Show weather, sound, and small physical detail before dialogue.
- End each reply on an open beat the user can answer.

Rules of the scene:
- Stay in character. Do not summarize or comment on the story from outside.
- All characters are adults.
'''

Three things do most of the work here. The word range gives the model a target, which works better than "be detailed". The "never act for the user" line stops the common failure where the model writes your next move. The closing beat keeps the exchange moving instead of ending on a full stop.

The last line is also a fixed limit of this service: no sexual content involving minors, in any framing. If your scene touches romance or mature themes, keep every character an adult and say so in the prompt, as above.

A working chat loop in Python

The loop below keeps the history in a list, streams each reply to the terminal, and stores the finished text. Install the SDK with pip install openai and put your key in the LLM_KEY environment variable.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.nsfwwriter.cc/v1",
    api_key=os.environ["LLM_KEY"],
)

history = [{"role": "system", "content": SYSTEM}]

def turn(user_text):
    history.append({"role": "user", "content": user_text})
    stream = client.chat.completions.create(
        model="uncensored",
        messages=history,
        temperature=0.9,
        top_p=0.95,
        frequency_penalty=0.3,
        presence_penalty=0.2,
        stream=True,
    )
    parts = []
    for chunk in stream:
        if chunk.choices and chunk.choices[0].delta.content:
            piece = chunk.choices[0].delta.content
            parts.append(piece)
            print(piece, end="", flush=True)
    print()
    history.append({"role": "assistant", "content": "".join(parts)})

while True:
    turn(input("> "))

Streaming matters for roleplay because a 400-word reply can take a while to finish, and reading the first lines while the rest arrives feels much faster. A streamed request holds one of your concurrency slots until the stream ends, which is fine for a single player and worth remembering if you build a multi-user app.

Sampling settings for long, varied replies

The sampler decides how adventurous the prose gets. These starting values suit narrative writing:

SettingStart atWhat it does
temperature0.8 to 1.0Higher gives more surprising word choice, lower gives steadier continuity.
top_p0.9 to 0.95Cuts the unlikely tail so the text stays readable at high temperature.
frequency_penalty0.2 to 0.5Reduces repeated words and stock phrases across a long reply.
presence_penalty0.1 to 0.3Nudges the model toward new topics and details.
max_tokensoptionalA safety cap; the reply can otherwise use the rest of the window.

All of these are passed through to the model. Change one at a time and compare a few replies on the same prompt. If the model starts looping on the same phrases after thirty turns, raise the frequency penalty a little before you touch temperature. If characters drift out of voice, lower the temperature first.

The seed field helps when you tune: with the same seed and the same messages you can compare two prompt versions without random variation hiding the difference.

Managing a long scene in 100,000 tokens

The context window is 100,000 tokens, counting the prompt and the reply together. A 400-word reply is roughly 550 tokens, so a scene of several hundred exchanges fits before you have to think about trimming. That is a lot of room, and it changes how you design the app: you can keep the full transcript instead of a lossy summary.

Two habits still help once sessions get long.

  • Pin the facts. Keep a short "story so far" block in the system prompt: names, places, open threads, promises made. Update it every twenty turns or so. Models attend to the start and end of a prompt more reliably than the middle.
  • Trim from the oldest exchanges, not the system prompt. If you must cut, drop the earliest user and assistant pairs and keep the system message and the last stretch of the scene.
def trimmed(history, keep_last=120):
    system, rest = history[0], history[1:]
    return [system] + rest[-keep_last:]

Cost grows with history, because every turn resends it. The next section puts numbers on that. For a deeper view of the price per token, see the pricing page.

What a session costs

Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit. Take a session of 40 turns with an 800-token system prompt, a 100-token user message and a 400-token reply per turn.

On turn n the input is 800 + 100 + (n - 1) x 500 tokens, because each earlier exchange adds 500. Summed over 40 turns that is 40 x 900 + 500 x (0 + 1 + ... + 39) = 36,000 + 500 x 780 = 426,000 input tokens. Output is 40 x 400 = 16,000 tokens.

  • Input: 426,000 / 1,000,000 x $0.15 = $0.0639
  • Output: 16,000 / 1,000,000 x $0.50 = $0.0080
  • Total: about $0.072 for the whole session

The input side dominates because of the resent history, which is why trimming old turns pays off in long campaigns. The $0.50 trial credit would cover nearly seven sessions like this one. Failed or refused requests are not charged, and credit never expires, so there is no pressure to use a balance by a deadline.

Fixing the usual roleplay problems

Even with a good system prompt, a few problems come back. Each has a cheap fix.

Replies get shorter over time

The model copies the length of the replies already in the history. If turn five was 150 words, turn fifty will be about the same. Keep the word range in the system prompt, and if the drift persists, add a one-line reminder to the last user message, such as "Reply with 3 to 5 paragraphs." You can append that line in code so the user never sees it.

The model speaks for your character

Say it once in the prompt and once as an example. A short sample exchange in the history, where the model ends on Mara's action and leaves the user's character alone, teaches the pattern better than a rule. Sample exchanges cost a few hundred input tokens, which is a fraction of a cent.

Phrases repeat across scenes

Raise frequency_penalty slightly, and add a line to the prompt listing the phrases you are tired of. A list of five or six stock openings you want avoided is usually enough. Do not list fifty; long ban lists crowd out the instructions that matter.

Out-of-character steering

Sometimes you want to redirect the scene without breaking it. Agree on a marker in the prompt, for example text in double parentheses is a note to the writer and not part of the scene. Then you can type ((slow down, more dialogue)) and the next reply adjusts. It is a plain convention, and it works because the model reads it as an instruction in context, not because the API has a special feature for it.

Limits to plan around

Be clear with yourself about what this setup is not. The model produces text. It does not draw scene art, speak in a voice, or hold memory between separate API calls; the history you send is its only memory. If your project needs character portraits, you will pair the text layer with a separate image tool. The page on the text layer for image workflows explains how the pieces fit.

Rate limits are worth knowing before you share a bot with friends. A full key allows 8 concurrent requests and 300 requests per minute; a trial key allows 2 and 60. Past those you get HTTP 429 with the code rate_limited or concurrency. A short wait and retry handles both.

import time
from openai import RateLimitError

def safe_turn(text, tries=4):
    for i in range(tries):
        try:
            return turn(text)
        except RateLimitError:
            time.sleep(5 * (i + 1))
    raise RuntimeError("still limited after retries")

To start, create an account and claim the trial credit. Sign-up works with Google or with email and password, and the trial needs no payment details.

Questions and answers

How long should a detailed roleplay reply be?

Set a word range in the system prompt, such as 250 to 400 words. The model follows a stated range more reliably than a vague request for detail.

Does the model remember earlier sessions?

No. It only sees the messages you send in each request. Store the transcript yourself and resend it, or keep a short summary block in the system prompt.

Can I use this with SillyTavern or another front end?

Any client that accepts an OpenAI-compatible endpoint works. Enter the base URL, your key and the model ID uncensored.

Are prompts used for training?

No. Prompts are not used for training.

What content is not allowed?

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

Your key is one form away

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

Read the docs