EN ▾
Get API key

Uncensored Chat API for Roleplay: Setup and Costs

A roleplay app needs a model that stays in character, streams quickly and remembers a long story. Here is how to wire that up over an OpenAI-compatible endpoint, with real costs.

Theatre stage with two masks exchanging glowing chat bubbles, representing a roleplay chat API

Updated

Key points

  • Put the character card in the system message and stream every reply.
  • The 100,000-token window holds a long story, but each turn bills the whole history as input.
  • A 40-turn session of about 6,000 input tokens per turn costs roughly four cents.
  • For lawful adult use only. Sexual content involving minors is never allowed.

What a roleplay backend actually needs

If you are searching for an uncensored chat api roleplay setup, you are probably building one of three things: a character chat app, a text adventure or game master, or a personal tool that connects to a frontend you already like. All three have the same requirements. The model must follow a persona for hundreds of turns. Replies must stream so the user is not staring at a spinner. The context must be large enough to hold the story. And the model must not break the scene with a refusal or a lecture halfway through a fictional conflict.

The service described here is an OpenAI-compatible text API with one model, uncensored, tuned to answer without content refusals for lawful adult use. That fits fiction, companion apps and interactive stories for adults. It does not fit anything involving minors: that content is a hard limit and is never served. The API is text only, so there are no generated images or voices. If your product has portraits or audio, they come from other tools.

Because the protocol is the standard chat completions format, most roleplay frontends that accept a custom OpenAI-compatible endpoint can use it. SillyTavern, for example, lets you add such an endpoint. You enter the base URL, paste a key and type the model name. The rest of this article assumes you are writing your own backend instead, since that is where the details matter.

Set up the character in the system message

Put everything stable in the system message: who the character is, how they speak, the setting, and the rules of the scene. Keep the user's messages for the user's actions. A model follows a clean split like this better than a single wall of text.

A card that works well has five parts:

  1. Identity: name, age (adult characters only), role, one line of background.
  2. Voice: two or three concrete speech habits. "Short sentences, dry humor, never uses contractions" beats "witty and smart".
  3. Setting and state: where the scene happens and what each party wants right now.
  4. Style rules: point of view, tense, reply length, and whether the character may speak for the user.
  5. Boundaries: topics the story avoids, written as story rules, not apologies.

The third and fourth items save the most trouble. Without a rule such as "never write the user's actions or speech", many models happily continue the scene on the user's behalf. Without a length rule, replies drift longer with each turn.

{
  "model": "uncensored",
  "messages": [
    {"role": "system", "content": "You are Mara Vell, a smuggler captain in her forties. Voice: clipped, sardonic, never explains a joke. Setting: the harbor town of Kest, night, rain. Goal: get the user's character to pay for passage without revealing the cargo. Rules: third person past tense, 80 to 150 words per reply, never write the user's actions or dialogue, stay in the scene."},
    {"role": "user", "content": "I step under the awning and ask what the crate costs me."}
  ],
  "temperature": 0.9,
  "stream": true
}

Send that body to POST /v1/chat/completions at https://api.wanuncensored.com/v1 with an Authorization: Bearer header, and you have a working scene.

A streaming chat loop in Python

The loop below keeps history in a list, streams each reply to the terminal, and appends the finished reply so the next turn has it. It is about thirty lines and is a good base for a web backend later.

import os
from openai import OpenAI

client = OpenAI(base_url="https://api.wanuncensored.com/v1", api_key=os.environ["WAN_API_KEY"])

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

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

    stream = client.chat.completions.create(
        model="uncensored",
        messages=history,
        stream=True,
        temperature=0.9,
        top_p=0.95,
        max_tokens=400,
    )
    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)
    history.append({"role": "assistant", "content": reply})

Two habits will save you debugging time. First, save history to disk after every turn so a crash does not erase an hour of story. Second, if the user hits "regenerate", pop the last assistant message and call the API again with the same history. Pass a different seed or a slightly higher temperature, otherwise you may get the same text back.

In a web app, relay the stream with Server-Sent Events from your own server to the browser, so the API key never reaches the client. Remember that a streamed request holds one of your concurrency slots until the last chunk arrives. On a full key that is 8 slots, so a small app can serve a handful of simultaneous users before you need a queue. If you expect more, add a waiting line in your backend and return a friendly "one moment" state, rather than letting users see raw 429 errors.

Sampling settings for fiction

Creative writing wants more variety than question answering, but too much variety makes a character lose their voice. These starting points are reasonable and you should adjust them by reading real output, not by trusting a number.

  • temperature 0.8 to 1.0: lively but coherent. Go lower, around 0.6, for a game master who must track rules and inventory.
  • top_p 0.9 to 0.95: cuts off the strangest words. Leave temperature and top_p both moving only if you test carefully.
  • frequency_penalty 0.2 to 0.5: helps when the character keeps repeating the same gesture or phrase.
  • presence_penalty 0.1 to 0.3: nudges the story toward new topics and away from circling back.
  • stop: add a marker like the user's name followed by a colon if the model likes to continue the dialogue past its own turn.
  • max_tokens: optional, but a cap of 300 to 500 keeps replies short and cost predictable.

When you tune, use seed with a fixed value so you compare two prompts under the same conditions. Change one setting at a time, run the same five opening messages, and keep the results in a file. It is slow, but it is the only way to know whether a change helped.

Memory: using the 100k window well

The window is 100,000 tokens, prompt plus completion. That is long enough to hold a very large amount of dialogue, so many small apps can send the full history every time and never think about memory. The catch is cost and attention. Each new turn bills the entire history as input, and models pay less attention to details buried in the middle of a very long prompt.

Three techniques keep long stories sharp:

  1. Pinned facts. Keep a short "story so far" block after the system message: names, relationships, promises made, items carried. Update it every ten or twenty turns.
  2. Rolling summary. When the history passes a threshold such as 60,000 tokens, ask the model to summarize the oldest two thirds in under 400 words, then replace those turns with the summary.
  3. Lorebook entries. Store descriptions of places and characters separately. When the user's message mentions "Kest" or "the Gull", insert the matching entry into the prompt for that turn only.

Read usage.prompt_tokens from each response to know where you stand. The count is exact, which beats guessing from characters. If you need ideas for the summary call, the same chat endpoint works for it with a low temperature and no streaming.

What a session costs

Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit. Here is a realistic session. A story runs 40 turns. By the middle the history is large, and the average input per turn works out to about 6,000 tokens. Each reply is about 300 tokens.

PartTokensMathCost
Input40 x 6,000 = 240,0000.24 x $0.15$0.036
Output40 x 300 = 12,0000.012 x $0.50$0.006
Total$0.042

So a long evening of roleplay costs about four cents. The $0.50 trial credit, which you claim with one click on the key page, covers roughly 11 sessions of this size ($0.50 divided by $0.042 is a little under 12). The trial lasts 7 days and needs no card.

The figure grows if you let the history balloon. The same 40 turns at an average of 30,000 input tokens each would be 1,200,000 input tokens, or $0.18, plus the same $0.006 of output: $0.186. That is still small, but it shows why a rolling summary pays off in an app with many users. For top-ups, you can add any whole amount from $20 to $500, with a bonus of 5% from $50, 10% from $100 and 15% from $200. Failed or refused requests are not charged, and credit never expires. The pricing page lists payment options, including crypto only.

Limits, safety and a launch checklist

Before you put a roleplay app in front of users, go through the points below.

  • Adults only. The model is tuned for lawful adult use. Put an age gate in your app, and write character cards for adult characters only. Sexual content involving minors is a hard limit of the service.
  • Concurrency. A full key allows 8 requests at once and 300 per minute. Queue extra users on your side. A 429 with code concurrency means too many in flight, and rate_limited means too many per minute.
  • Overload. A 429 with Retry-After: 5 is a temporary condition. Wait five seconds and try again.
  • Keys. Keep the key on your server. Never ship it in a browser or mobile bundle.
  • Data. Prompts are not used for training. Still, tell your users what you store on your own side.
  • Balance. Each response includes an X-Balance-USD header. Log it and warn yourself before credit runs out.

When you are ready to test, claim a key on the API key page and follow the steps in the docs quickstart. Start with one character and ten turns, read the output with a critical eye, and only then add memory features. Most roleplay problems come from the system message, not the model: vague voice rules, no length limit and no rule about the user's actions. Fix those first.

Questions and answers

Which frontends work with this API?

Any client that accepts a custom OpenAI-compatible endpoint can use it. You enter the base URL, your key and the model name uncensored. SillyTavern is one example of a frontend with that option.

How long can a roleplay story get?

The context window is 100,000 tokens, shared by the prompt and the reply. For stories beyond that, keep a rolling summary and pinned facts instead of the full history.

Does it generate images or voices for characters?

No. It is a text-only API. Images, audio and video come from other tools.

Is there any content the API will not write?

Sexual content involving minors is never allowed. Beyond that, the model is tuned to answer without content refusals for lawful adult use.

How much does a roleplay session cost?

A 40-turn session averaging 6,000 input tokens and 300 output tokens per turn costs about $0.042 at $0.15 and $0.50 per 1M tokens.

Your key is one form away

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

Get API key