EN ▾
Get API key

LLM Role Play Prompt: Structure, Examples, Settings

A good llm role play prompt gives the model a fixed character, a clear scene and rules for how to write, then lets the conversation do the rest. This page shows a prompt structure that works, with code you can run against an OpenAI-compatible endpoint.

Updated

Key points

  1. Put identity, setting, style rules and boundaries in the system message, not in the first user turn.
  2. Show the voice with a short example exchange instead of describing it with adjectives.
  3. Lower temperature for consistency, raise it for variety, and trim history before it drifts.
  4. Fiction and companion apps for lawful adult use only; sexual content involving minors is never allowed.
Stage with blank masks and glowing chat bubbles representing character roleplay prompts for an LLM

The short answer: four blocks in one system message

Most weak roleplay comes from a vague setup, not a weak model. If you give a model two lines like "you are a pirate, stay in character", it fills the gaps with generic filler. A stronger prompt has four blocks, in this order: who the character is, where and when the scene happens, how the character writes, and what the story must never do.

Here is a compact template. Replace the bracketed parts with your own material.

CHARACTER
Name: Mara Voss. A salvage pilot in her forties, dry humor, distrusts officials,
loyal to her crew. Speaks in short sentences. Never explains her feelings directly.

SCENE
The cargo bay of the freighter Kestrel, mid-repair, two days from the nearest port.
The user plays Jin, a new engineer who has just joined the crew.

STYLE
Write in third person, past tense, 80 to 150 words per reply.
Describe actions and speech. Do not write Jin's actions or words.
End each reply on something Jin can respond to.

BOUNDARIES
Adults only. Keep content within lawful adult fiction.
If a request would involve a minor in a sexual way, refuse and change the scene.

The template is plain text and has no special syntax. Models follow headed blocks well because each block answers one question the model would otherwise have to guess.

Why the system message matters more than the first turn

Chat APIs weight the system message as standing instructions. If you put your character sheet into the first user message, it is just one more line of dialogue, and it will sink as the history grows. Keep the sheet in the system role and resend it every call. On the pricing side that costs very little: a 600-token system message is 600 x $0.15 / 1,000,000 = $0.00009 per call, which is under a hundredth of a cent. See the pricing page for the rates.

Models that are tuned to refuse certain themes often break the scene with an apology or a lecture halfway through a story. An endpoint tuned to answer without content refusals for lawful adult use avoids that behavior, which matters for dark fiction, horror, villains with real menace and morally grey characters. It does not remove your responsibility to set the boundaries of your own story, which is why the template above has a boundaries block. One limit is fixed on this service: no sexual content involving minors, ever.

Show the voice with an example exchange

Adjectives such as "sarcastic" or "gritty" are weak instructions. Two lines of sample dialogue do more, because the model copies rhythm, vocabulary and length. Add a short example block to the system message, or seed the conversation with a fake first exchange using real user and assistant turns.

EXAMPLE
Jin: Is the reactor supposed to make that noise?
Mara: She glanced at the gauge, then at him. "Only when it's about to stop." She tossed him a wrench. "Pick a bolt."

Notice what the example shows: a short reply, an action in the narration, one line of dialogue with an edge, and an open ending. The model will follow all four. If your replies come out too long, shorten the example. If they come out flat, make the example more specific. You can use the character's own vocabulary, for example a trade slang term she would use, and the model will keep using it.

Avoid negative-only rules. "Don't be repetitive" gives little to hold on to, while "vary the opening word of each paragraph" can be followed.

Run it: a working chat loop

The service is OpenAI-compatible, so the standard SDK works. The base URL is https://api.smollm.top/v1 and the model ID is uncensored. This loop keeps the system message fixed and appends each turn:

from openai import OpenAI

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

SYSTEM = open("mara.txt", encoding="utf-8").read()
history = [{"role": "system", "content": SYSTEM}]

while True:
    user = input("> ")
    if not user:
        break
    history.append({"role": "user", "content": user})
    stream = client.chat.completions.create(
        model="uncensored",
        messages=history,
        temperature=0.9,
        top_p=0.95,
        max_tokens=300,
        stream=True,
    )
    reply = ""
    for chunk in stream:
        if chunk.choices and chunk.choices[0].delta.content:
            piece = chunk.choices[0].delta.content
            reply += piece
            print(piece, end="", flush=True)
    print()
    history.append({"role": "assistant", "content": reply})

The same request in curl, useful for testing a prompt file before you build anything around it:

curl https://api.smollm.top/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "temperature": 0.9,
    "max_tokens": 300,
    "messages": [
      {"role": "system", "content": "You are Mara Voss, a dry-humored salvage pilot. Reply in 80 to 150 words."},
      {"role": "user", "content": "Is the reactor supposed to make that noise?"}
    ]
  }'

If you do not have a key yet, the key page explains sign-up. New users can claim $0.50 of trial credit with one click, valid for 7 days. For endpoint details, see the quick-start docs.

Sampling settings that change the feel

Parameters are passed through to the model, so they have a real effect on character voice.

  • temperature: 0.7 to 0.9 keeps a character steady while still surprising you. Above 1.0, voices start to wander and sentences get odd. Near 0.3, replies turn repetitive.
  • top_p: 0.9 to 0.95 trims the unlikely tail. Change either temperature or top_p first, not both at once, so you know which did what.
  • frequency and presence penalties: small positive values, around 0.2 to 0.5, reduce loops where the character repeats a catchphrase. Large values make wording strange.
  • stop: set a stop string such as "\nJin:" so the model never writes the user's lines.
  • seed: fix it while you edit the prompt, so differences in output come from your edits and not from chance.
  • max_tokens: optional, but a ceiling of 250 to 400 matches the 80 to 150 word target above and keeps costs predictable.

Keeping long sessions on track

Character drift

After 30 or 40 turns, characters tend to soften into a generic helpful tone. Two fixes work. First, restate the key voice rule in a short reminder message every ten turns or so. Second, keep the example exchange in the system message, where it stays visible. Do not rely on turn one to hold the whole setup.

Memory without a giant history

The context window is 100,000 tokens, which is very large for chat, but you pay for the input on every call. A cheaper pattern is to keep the last 12 or so turns verbatim and replace older turns with a running summary written by the model itself. Ask for the summary in a separate call with a prompt like "List the facts, injuries, promises and locations that matter for continuing this story, in 150 words." Then insert it into the system message under a MEMORY heading.

Cost check on a session of 60 turns where each turn adds 500 tokens, using that 12-turn window plus a 600-token system message and a 300-token summary: late-turn input is about 600 + 300 + 12 x 500 = 6,900 tokens, so each call is 6,900 x $0.15 / 1,000,000 = about $0.001 of input. Without trimming, turn 60 would carry about 30,600 tokens, or $0.0046 of input, and growing.

Rate limits in multi-user apps

A full key allows 8 concurrent requests and 300 per minute. A streamed reply holds its slot until the stream ends, so an app with many players needs a small queue. A 429 with code concurrency means too many at once. A 429 with Retry-After: 5 means temporary overload.

Common problems and fixes

SymptomLikely causeFix
Model writes the user's linesNo rule against it, no stop stringAdd the rule to STYLE and a stop sequence
Replies too longExample exchange is longShorten the example, set max_tokens
Same phrases repeatLow temperature, no penaltiesRaise temperature to 0.9, add a small presence penalty
Voice goes genericSetup buried in historyKeep the sheet in the system message, add a reminder
Scene stallsReplies end with no hookAdd "end on something the user can respond to"

If you are weighing hosts for this kind of app, the DeepInfra comparison lays out how this service differs. This is one open-weight model from an independent provider, billed per token from prepaid credit, with prompts not used for training. It is text only, so cover art or voices need other tools.

Questions and answers

Where should the character description go?

In the system message, resent on every call. Putting it in the first user turn lets it fade as the history grows.

What temperature is best for roleplay?

Start at 0.8 to 0.9 with top_p around 0.95. Lower it if the character wanders, raise it if replies feel flat.

How do I stop the model from writing my character's lines?

Add a rule in the style block and set a stop string, such as a newline followed by your character's name and a colon.

Is there a content restriction?

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

Can I keep a long story without huge costs?

Yes. Keep the last dozen turns in full and replace older turns with a short summary stored in the system message.

Your key is one form away

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