EN ▾

Custom Image Roleplay Generator: Build the Text Side

A custom image roleplay generator has two halves: something that writes the story and something that draws it. This API handles the writing half, with character sheets, scene text and ready-to-paste image prompts, and leaves the drawing to an engine you choose.

Updated

Stage with a glowing speech bubble and an empty picture frame joined by a thread of light

What this API covers and what it does not

People who search for a custom image roleplay generator usually want one screen where they describe a character, play out a story and see pictures appear next to the text. Behind that screen there are always two different kinds of model. One writes. The other renders. This API is the first kind. It receives text, returns text, and has no image, audio or video output.

That makes it a good fit for the parts of the project that are about words: inventing the character, voicing the narrator and the side characters, remembering the plot, and turning each scene into a tidy prompt for an image tool. It is a poor fit if you hoped a single call would return a picture. For that you need a separate image engine, hosted by you or by someone else, with its own rules and its own price.

The model behind the API is an open-weight model run by an independent provider and tuned to answer without content refusals for lawful adult use. For fiction and roleplay between adults that means the narrator does not break the scene to lecture you. One rule is fixed and cannot be negotiated: no sexual content involving minors. Every example below states that all characters are adults, and your own system prompts should do the same.

The three jobs of the text model

A tidy way to think about the project is to split the text work into three jobs, each with its own prompt and its own settings.

JobOutputSettings that help
Character sheetJSON with name, voice, secret, opening scene and a visual blockJSON mode, temperature around 0.9
Story turns120 to 220 words of narration per player actionStreaming, top_p 0.95, a small frequency penalty
Image promptJSON with a prompt and a negative promptJSON mode, temperature around 0.5

Keeping the jobs separate has a practical reason. A story prompt asks for atmosphere and variety. An image prompt asks for consistency and a rigid format. When one system message tries to do both, the story gets stiff and the prompts get chatty. Three small calls with narrow instructions behave better than one call with a long list of demands.

Step 1: generate a character sheet

Start with the sheet, because everything else reads from it. The script below asks for a JSON object and saves it to sheet.json. The look field is the important one. It is a single paragraph of visual details that you will paste, unchanged, into every image prompt for this character. Image engines tend to drift when the description changes from scene to scene, and a frozen block is the cheapest way to keep a face, a coat and a colour scheme stable.

import json
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://api.unrestrictedvideogenerator.top/v1",
    api_key=os.environ["LLM_API_KEY"],
)

SYSTEM = (
    "You design characters for interactive fiction written for adults. "
    "Reply with one JSON object with these string keys: name, role, voice, "
    "secret, opening_scene, look. The look value is a single dense paragraph "
    "of visual details (hair, clothing, colours, setting) that can be pasted "
    "into an image prompt. All characters are adults."
)

resp = client.chat.completions.create(
    model="uncensored",
    response_format={"type": "json_object"},
    temperature=0.9,
    messages=[
        {"role": "system", "content": SYSTEM},
        {"role": "user", "content": "A weary lighthouse keeper in a fantasy archipelago, hiding a map."},
    ],
)

sheet = json.loads(resp.choices[0].message.content)
with open("sheet.json", "w") as f:
    json.dump(sheet, f, indent=2)
print(card["name"], "-", card["role"])

Run it a few times with different one-line premises and keep the sheets you like. You can edit the JSON by hand before you move on; the model is a collaborator, not an authority. If you have not made a key yet, the key page explains the sign-up and the free $0.50 trial credit, which is far more than this step needs.

Step 2: the roleplay loop

The second script reads the sheet, builds a system message from it and runs a plain terminal chat with streaming output. Swap input() for a web form or a Discord handler later; the API calls stay the same.

import os

from openai import OpenAI

client = OpenAI(
    base_url="https://api.unrestrictedvideogenerator.top/v1",
    api_key=os.environ["LLM_API_KEY"],
)

sheet = open("sheet.json").read()
system = {
    "role": "system",
    "content": (
        "You are the narrator and every non-player character in an interactive "
        "story between adults. Stay inside the setting of this character sheet. "
        "Write 120 to 220 words per turn in second person and end on a moment "
        "where the player can act. Never speak for the player.\n\nSHEET:\n" + sheet
    ),
}
history = []

while True:
    line = input("> ").strip()
    if line in ("", "/quit"):
        break
    history.append({"role": "user", "content": line})

    stream = client.chat.completions.create(
        model="uncensored",
        messages=[system] + history[-20:],     # last 10 exchanges
        stream=True,
        temperature=0.9,
        top_p=0.95,
        frequency_penalty=0.3,
    )
    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})

Several choices in this loop target problems that long roleplay sessions tend to produce.

  • Never speak for the player. One sentence in the system message prevents the most common complaint about narrator models.
  • End on a hook. Asking for a moment where the player can act gives the user something to answer, and makes turns shorter.
  • Penalties are small. A frequency penalty of 0.3 reduces repeated phrases. Higher values make the prose odd. The parameter is passed through to the model.
  • History is sliced. Only the last 20 messages go out. The sheet sits in the system message, so the character never falls out of the window.

If you want reproducible runs while you tune a prompt, pass seed and keep it fixed. Remove it again for real play.

Step 3: turn each scene into an image prompt

Once a scene exists, ask a second call to describe it for the image engine. Give it the look text and the scene, tell it to reuse the look word for word, and ask for JSON. A curl version makes the shape of the request easy to see:

curl https://api.unrestrictedvideogenerator.top/v1/chat/completions \
  -H "Authorization: Bearer $LLM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "response_format": {"type": "json_object"},
    "messages": [
      {"role": "system", "content": "Turn the scene into JSON with keys prompt and negative. Reuse the look text word for word. All characters are adults."},
      {"role": "user", "content": "LOOK: a tall keeper in a salt-stained coat, silver beard, brass lantern. SCENE: she hides a rolled map as a storm hits the tower window."}
    ]
  }'

The response arrives in choices[0].message.content as a JSON string with prompt and negative. Send those two strings to your image engine in whatever way it accepts them. This glue differs per engine, and the engine decides what it will and will not draw, so check its own documentation and rules. Keep image prompts descriptive and non-explicit if you plan to share results publicly.

For a related walkthrough of connecting a front end to the API, the API documentation lists the request fields in one place. For the broader question of where a text model sits next to image and video tools, the page on text to video pipelines covers the same split from the video side.

Cost and session length

Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens. In a roleplay loop the input side grows because each turn resends the history. Take a session of 40 turns. The system message plus sheet is 600 tokens, each player message is 80 tokens, and each reply is 220 tokens, so one exchange adds 300 tokens to the history.

With the full history resent, input tokens for turn n are 600 + 80 + 300 x (n - 1). Over 40 turns the sum is 40 x 680 + 300 x 780 = 27,200 + 234,000 = 261,200 input tokens. Output is 40 x 220 = 8,800 tokens.

  • Input: 261,200 x $0.15 / 1M = $0.03918
  • Output: 8,800 x $0.50 / 1M = $0.0044
  • Total: $0.04358, about 4.4 cents

Now trim the history to the last 10 exchanges, as the loop above does. The first 11 turns still grow, then every later turn sends 600 + 3,000 + 80 = 3,680 tokens. Input is 23,980 + 29 x 3,680 = 130,700 tokens, which costs $0.019605. Add the same $0.0044 for output and the session costs about $0.024. Trimming cuts the bill by nearly half and loses only very old details, which a short running summary can cover.

The context window is 100,000 tokens for prompt plus completion, so even the untrimmed approach would last more than 300 turns of this size. Failed or refused requests are not charged. See pricing for top-ups from $20 to $500 with bonuses from $50, paid in crypto with USDT on TRC20 or USDC on Base.

Concurrency, safety and polish

A single player never hits the limits. A small public site does. A full key allows 8 concurrent requests and 300 per minute, a trial key 2 and 60. Remember that each open stream holds its slot until the last token arrives. When you receive HTTP 429, read the error code: concurrency means too many at once, rate_limited means too many per minute, and a Retry-After: 5 header marks temporary overload. Queue requests per user and retry after the stated delay.

Some finishing touches are worth the effort. Add a short summary step every 30 turns, where the model compresses old events into 150 words that replace the oldest messages. Offer a regenerate button that resends the last user message with a new seed. Store sheets and sessions on your side, since the API keeps none. Prompts are not used for training, but any chat you save is yours to protect. Finally, put an adult-only gate and a clear statement of the minors rule on any public front end, and read the terms before you launch.

Questions and answers

Can this API generate the pictures for a roleplay?

No. It returns text only. It can write the character, the story and the image prompts, and a separate image engine has to draw them.

How do I keep a character looking the same across images?

Store one fixed visual paragraph in the character sheet and paste it unchanged into every image prompt. Ask the model to reuse it word for word.

Is there a limit on how long a roleplay can run?

The context window is 100,000 tokens for the prompt and the reply together. Trimming history or summarizing old turns lets a story run far longer than that.

What happens if the narrator refuses something?

The model is tuned to answer without content refusals for lawful adult use. Refused or failed requests are not charged, and the hard limit on content involving minors cannot be changed.

Which sampling settings work best for storytelling?

Temperature near 0.9, top_p near 0.95 and a small frequency penalty such as 0.3 are a reasonable start. Adjust one at a time and use a fixed seed while comparing.

Your key is one form away

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