nsfwapis.com
// Guide / Text

NSFW roleplay API: building a roleplay app that stays cheap

An NSFW roleplay API is an ordinary uncensored LLM chat API that your app feeds a character card, the chat history and the user’s message on every turn. There is no special roleplay endpoint. The work is in how you build that prompt, because it decides the quality of the character and most of your bill. This guide covers character cards, context length, memory, cost per message and model choice, with a worked 100-turn example priced on published rates.

What is an NSFW roleplay API?

An NSFW roleplay API is a chat completions API, hosted by a provider that allows adult content, running a model that doesn’t refuse fiction with sexual or dark themes. You send a list of messages and get the next one back. The API doesn’t know it’s running a character. Your app tells it, every turn.

That means an “AI roleplay API” is mostly a choice of two things: the provider (its terms, price and payment) and the model (how well it writes and whether it refuses). Everything else, the character, the memory, the persona and the rules of the scene, lives in your code.

All the text providers in this directory host uncensored or abliterated models, and most expose the OpenAI request format, so the same code works across them. If you’re moving an existing app over, the OpenAI-compatible switching guide covers the base URL, key and model ID change.

What goes into a roleplay request?

Every roleplay request is the same stack of parts, rebuilt each turn. A typical order looks like this:

The parts of a roleplay prompt, in a cache-friendly order
PartWhat it holdsChanges between turns?
System promptWriting rules: point of view, tense, reply length, what the model may and may not writeNo
Character cardName, description, personality, scenario and example dialogueNo
User personaWho the user is playingRarely
Memory and loreA summary of earlier events, plus world facts pulled in when relevantSometimes
Chat historyThe recent messages, oldest firstEvery turn
New messageWhat the user just wroteEvery turn

Most roleplay front ends store characters in the community Character Card V2 format. Its data object has these fields: name, description, personality, scenario, first_mes (the opening message), mes_example (sample dialogue), creator_notes, system_prompt, post_history_instructions, alternate_greetings, an optional character_book (lore entries), tags, creator, character_version and extensions. Supporting it lets users import cards they already have.

Two fields deserve care. system_prompt lets a card override your own system prompt, so decide whether you allow that, since your safety rules may live there. post_history_instructions is text placed after the history, right before the model writes. It’s the strongest place to steer style, because models pay most attention to the start and end of a long prompt, but it also sits after the part that changes, which matters for caching (covered below).

The opening message and example dialogue shape the model’s voice more than adjectives in the description do. A card that says “witty” with a dull first message usually produces dull replies.

How much context length does a roleplay app need?

Less than the model allows. Several models in this directory list a 1M-token context window, but a long window only sets the ceiling. You pay for every token you send on every turn, so the real question is how much history is worth paying for.

Take a simple chat: a 2,000-token system prompt and card, 100-token user messages and 300-token replies. Turn 1 sends 2,100 input tokens. Turn 50 sends 21,700. Turn 100 sends 41,700, because the whole conversation rides along. Over 100 turns that adds up to 2,190,000 input tokens, against only 30,000 output tokens.

Input per turn when the full history is re-sent (2,000-token card, 100-token messages, 300-token replies)
TurnInput tokens sentOf which history
12,1000
105,7003,600
2511,7009,600
5021,70019,600
10041,70039,600

Input per message grows in a straight line, so the total for a conversation grows roughly with the square of its length.

More context also isn’t always better for quality. Liu and colleagues, in Lost in the Middle (2023), found that language models used information placed at the start or end of a long input much better than information in the middle. A detail from turn 12 buried in a 40,000-token prompt may be ignored anyway. For most roleplay, 8,000 to 16,000 tokens of well-chosen context, with a summary of older events, is a sensible starting cap. Raise it if users complain the character forgets things.

How do roleplay apps handle memory?

They fake it. The model remembers nothing between requests, so “memory” is whatever your app decides to put back into the prompt. There are four common methods, and most apps combine two or three:

  • Sliding window. Keep the last N messages or the last N tokens and drop the rest. It caps cost, but the character forgets everything older.
  • Rolling summary. When the history passes a limit, ask a model (often a cheaper one) to summarize the oldest part in a few hundred tokens, and keep that summary near the top. This keeps plot points at the price of detail.
  • Keyword lore. Store facts about places, people and past events as entries with trigger words. When a trigger appears in recent messages, insert the entry. SillyTavern calls this World Info, and the card spec’s character_book field carries the same idea.
  • Retrieval. Embed old messages, then fetch the few most similar to the current message and insert them. It finds things keywords miss, but it adds an embedding call and can pull in irrelevant scenes.

A practical default is a sliding window plus a rolling summary, with keyword lore for anything the user explicitly sets up. Store summaries per conversation in your database, not in the card, so two users chatting with the same character don’t share memories.

How much does an NSFW roleplay API cost per message?

A fraction of a cent on the cheaper models, but it depends heavily on how far into the chat you are. Here is the same conversation priced on each provider’s example model from its profile, for one message early and one late in an untrimmed chat, and for the full 100 turns with and without an 8,000-token cap:

Cost of one 100-turn roleplay chat on each provider’s example model, from published rates, before caching
Provider and modelMessage at turn 5Message at turn 100100 turns, untrimmed100 turns, capped at 8,000
UnalignedGLM-5.3 Flash Uncensored · $0.063 / $0.10 per 1M$0.0003$0.0027$0.141$0.0505
UncensoredLLMGLM-5.3 Flash Uncensored · $0.1053 / $0.3685 per 1M$0.0005$0.0045$0.242$0.0904
RefuselessDeepSeek V4.1 Flash 1017 Abliterated · $0.12 / $0.45 per 1M$0.0006$0.0051$0.276$0.104
NanoGPTGLM 5.3 Flash Uncensored · $0.20 / $0.80 per 1M$0.0010$0.0086$0.462$0.175
Uncensored.comGLM-5.3 Flash Cyber Uncensored · $0.96 / $1.92 per 1M$0.0041$0.0406$2.160$0.781

With the cap, the input per turn stops growing at turn 16, and the 100-turn chat needs 753,500 input tokens instead of 2,190,000. That’s 66% less input for a chat that still keeps the last few thousand tokens of story.

To turn this into a monthly figure, multiply by your number of chats. A thousand 100-turn chats a month with the cap cost about $50.47 on Unaligned’s GLM-5.3 Flash Uncensored and about $780.96 on Uncensored.com’s GLM-5.3 Flash Cyber Uncensored. The example models differ in size and quality, so price the model you’d actually pick. The pricing guide shows the method in detail.

Two things push real costs above this table: regenerations (each “reroll” is a full new request) and summary calls. Log usage from every response and you’ll see both.

Can prompt caching cut roleplay costs?

Yes, and in the best case by more than trimming does. Refuseless and Unaligned publish a cached input rate for their example models, charged when the start of a request matches one the provider has recently seen. Roleplay suits this well, since each request is the previous one plus two new messages.

The catch is that a cache only matches an identical prefix. A sliding window that drops the oldest message every turn changes the history right after the card, so only the system prompt and card stay cached. Re-sending everything keeps the whole previous request cacheable. In the best case, where every turn hits the cache, only 41,700 of the 2,190,000 input tokens in the untrimmed 100-turn chat are new.

One 100-turn roleplay chat with and without cached input, from published rates
Provider and modelCached rate per 1MUntrimmed, no cacheCapped at 8,000, no cacheUntrimmed, best-case cache
RefuselessDeepSeek V4.1 Flash 1017 Abliterated$0.025$0.276$0.104$0.0722
UnalignedGLM-5.3 Flash Uncensored$0.004$0.141$0.0505$0.0142

The best-case column assumes the cache never expires between messages. In practice caches are dropped after a period of inactivity that the provider sets, so a user who pauses for a while pays full price on the next turn. Real savings land somewhere between the columns.

The cache-friendly way to trim is in chunks. Let the history grow to, say, 16,000 tokens, then cut it back to 8,000 in one step and fold the removed part into the summary. The prefix then stays stable for many turns at a time. Also keep anything that changes per turn out of the top of the prompt: no timestamps, no random greeting picks, and lore entries inserted after the history rather than before it.

Which model works best for an uncensored AI roleplay API?

Test on your own cards, but a few rules hold across providers:

  • Start with a Flash model. Every text provider here lists a Flash model, usually a GLM-5.3 or DeepSeek build. Short roleplay replies don’t need a flagship model, and the price gap can be ten times or more.
  • Try both abliterated and uncensored fine-tunes. Abliteration removes refusals but adds no writing skill. Fine-tunes trained on fiction can write better prose. The guide to abliterated models explains the difference.
  • Avoid reasoning models for chat. Models such as DeepSeek R1 write hidden reasoning before every reply. It’s billed as output and adds seconds of delay, and it rarely improves a 300-token scene.
  • Watch for repetition. In long roleplay, the more common problem is a model that repeats phrases or loops the same scene beat. Sampling settings help: a slightly higher temperature or a frequency penalty, where the provider supports it.

Write five or six characters that cover the range your users want, run a 30-turn scripted chat on each shortlisted model, and read the transcripts side by side. UncensoredLLM also offers an auto router, which suits apps that want one model for normal chat and a larger one for harder scenes. The uncensored LLM API comparison lists who hosts what.

Adult content rules for an NSFW chat API

An uncensored model doesn’t change the law or the provider’s terms. For a roleplay app that allows sexual content, these are the minimum:

  • Adults only, on both sides. Gate the app to adult users in line with the law where you operate, and make sure characters in sexual content are adults. Sexual content involving minors is illegal everywhere, and that includes fictional and text-only content in many countries. Block it in your system prompt and with your own checks. Don’t rely on the model.
  • No real people without consent. Sexual content about real, identifiable people made without their consent is illegal in many places and harmful everywhere. Refuse cards built on real people.
  • Read the provider’s terms. Each provider sets its own rules for adult content. For example, UncensoredLLM says it refuses any prompt involving a minor. The terms can change, so recheck them before launch.
  • Handle logs carefully. Roleplay chats are some of the most private data an app can hold. Find out what the provider logs and for how long, keep your own logs short, and let users delete chats.
  • Moderate user-made cards. If users can share characters, review or filter them before they appear publicly, and give people a way to report one.

Checklist for building on an NSFW roleplay API

  1. Pick two providers. One main, one fallback, both with the request format your code uses.
  2. Support Character Card V2. Import and export the standard fields so users can bring cards from other tools.
  3. Fix the prompt order. System prompt, card and persona first, then summary, history and the new message.
  4. Cap the context. Start at 8,000 to 16,000 tokens and trim in chunks, not one message at a time.
  5. Add a rolling summary. Store it per conversation and update it when you trim.
  6. Turn on caching where offered and check the cached token count in usage to confirm it works.
  7. Log cost per chat. Track input, cached input, output and regenerations per conversation, not just per request.
  8. Enforce the rules in code. Age gate, adult-only characters, no real people, and a report button.

Frequently asked questions

Is there a special API for AI roleplay?

No. AI roleplay apps use a normal chat completions API. The character, memory and scene rules are all in the prompt the app builds for each request, so any uncensored LLM API that allows adult content can run one.

How much does an NSFW chat API cost per message?

On the example models in this directory, one message early in a chat costs between about $0.0003 and $0.0041. The cost rises as the history grows, so capping the context and using cached input matter more than the headline price.

How much context does an AI roleplay API need?

Most roleplay apps work well with 8,000 to 16,000 tokens of context plus a summary of older events. Sending more raises the cost of every message, and models tend to use details buried in the middle of a long prompt poorly.

Do roleplay characters remember earlier chats?

Only if your app puts that information back into the prompt. The model keeps nothing between requests, so memory comes from the chat history you send, a stored summary, keyword-triggered lore entries or retrieval of old messages.

Can I use SillyTavern character cards with an uncensored AI roleplay API?

Yes. Character cards are just structured text, and the Character Card V2 fields such as description, personality, scenario and first message can be placed into the prompt for any chat completions API.

Sources

Prices and offers come from each provider’s published information, checked . They can change, so confirm them on the provider’s site. Found something out of date? Tell us.