EN ▾
Get API key
per 1M input tokens$0.15
Output tokens / 1M$0.50
token context100,000
trial credit$0.50
requests per minute300

https://api.sdxlnsfw.com/v1uncensored

Custom Image Roleplay Chat: Pair a Text API with SDXL

A custom image roleplay chat has two engines: a text model that plays the story and an image model that draws it. This page shows how to wire an uncensored text API to an SDXL backend so each turn can come with a matching picture.

Updated

A chat panel linked by a light bridge to an image panel, showing text and image pipelines working together

Key points

  1. The text API writes the narration and a structured image prompt; a separate SDXL server renders it.

  2. Use JSON mode so every reply carries both fields in a form your code can parse.

  3. Keep a fixed appearance string per character so the images stay consistent between turns.

  4. Text costs cents; the image side has its own hardware or hosting cost, and this API does no image generation.

How the two halves fit together

This kind of chat looks like one product to the user, but the parts are separate services with a thin layer of your code between them. The user sends a message. Your server asks the text model to continue the story and also to describe the current scene as an image prompt. The narration goes to the chat window. The image prompt goes to an SDXL server, which returns a picture a few seconds later.

This API handles only the first half. It is an OpenAI-compatible endpoint for text, running one open-weight model tuned to answer without content refusals for lawful adult use. It does not create images, and it has no embeddings or audio. SDXL, Stable Diffusion XL, is an open image model you run yourself or rent from a GPU host, for example through the AUTOMATIC1111 web UI with its --api flag or through ComfyUI.

The advantage of the split is control. You choose the checkpoint, the style and the content filters on the image side, and you choose the story engine separately. If one half changes, the other keeps working.

A word on scope. These pipelines are for fiction, character chat and companion apps for adults. Sexual content involving minors is never allowed on this service, and your image side should enforce the same rule. If you want a filter on generated pictures, the article on the chat API and NSFW detection describes where such a step fits.

Step 1: make the model return narration and an image prompt

Free-form text is a poor interface between two programs. Ask for JSON instead. The API supports JSON mode through response_format, and the system prompt defines the fields.

import json
from openai import OpenAI

client = OpenAI(base_url="https://api.sdxlnsfw.com/v1", api_key="YOUR_KEY")

SYSTEM = (
    "You run an interactive story. Each turn, reply with a JSON object with two keys. "
    "'narration': 2 to 3 paragraphs of story, never writing the user's actions. "
    "'image_prompt': one line of comma-separated visual tags for the current scene: "
    "setting, lighting, pose, camera angle, mood. Do not name the characters' appearance; "
    "it is added separately. All characters are adults."
)

def next_turn(history, user_text):
    history.append({"role": "user", "content": user_text})
    r = client.chat.completions.create(
        model="uncensored",
        messages=[{"role": "system", "content": SYSTEM}] + history,
        response_format={"type": "json_object"},
        temperature=0.85,
    )
    data = json.loads(r.choices[0].message.content)
    history.append({"role": "assistant", "content": data["narration"]})
    return data["narration"], data["image_prompt"]

Only the narration goes back into the history. The image prompt is a by-product, and keeping it out of the context saves input tokens on every later turn. Wrap the json.loads in a try block: if parsing fails once in a while, resend the request, which costs nothing extra for the failed attempt since failed requests are not charged.

Step 2: render the scene with SDXL

Suppose your SDXL server is the AUTOMATIC1111 web UI running locally with the API enabled. Its txt2img endpoint takes a JSON body and returns images as base64 strings. SDXL's native size is 1024 by 1024, so start there.

import base64, requests

# Story calls use the client from step 1: base_url https://api.sdxlnsfw.com/v1, model "uncensored"
SD_URL = "http://127.0.0.1:7860/sdapi/v1/txt2img"

CHARACTER = "Elin, adult woman, short silver hair, green eyes, dark travel coat"
STYLE = "digital painting, soft cinematic lighting, detailed"
NEGATIVE = "blurry, deformed, extra fingers, text, watermark"

def render(scene_tags, seed=-1):
    body = {
        "prompt": f"{CHARACTER}, {scene_tags}, {STYLE}",
        "negative_prompt": NEGATIVE,
        "width": 1024,
        "height": 1024,
        "steps": 28,
        "seed": seed,
    }
    r = requests.post(SD_URL, json=body, timeout=180)
    r.raise_for_status()
    return base64.b64decode(r.json()["images"][0])

narration, tags = next_turn(history, "I push open the door of the observatory.")
open("scene.png", "wb").write(render(tags))
print(narration)

The code uses the text API at https://api.sdxlnsfw.com/v1 for the story and your own SDXL host for the picture. Replace the endpoint if you run ComfyUI or a hosted service; each has its own request shape, but the idea is identical: tags in, image out.

Keep characters looking the same

Consistency is the part users notice first. If Elin has green eyes in turn one and brown eyes in turn five, the product feels broken. Three habits fix most of it:

  • A fixed appearance string. Note how CHARACTER is kept in code and added to every image prompt. The text model never writes it, so it cannot drift. This is why the system prompt tells the model to leave appearance out.
  • A fixed seed for portraits. For a recurring "avatar" shot, reuse a seed. For scene shots, vary it.
  • Style tags in one place. Keep style and negative prompt constant so the gallery reads as one set.

For stronger identity, the SDXL ecosystem offers LoRA files and reference-image tools. They live on the image side and are outside this API, but the pipeline above does not change when you add them: your code only swaps the CHARACTER string for a LoRA trigger word.

On the story side, store a short character card in the system prompt as well. The text model should know that Elin is wary of strangers, even though it never has to describe her hair.

Speed: do not make the user wait twice

Text arrives in seconds; an SDXL image can take noticeably longer, depending on your GPU and step count. The simplest trick is to show the narration as soon as the text call returns, then place the image in the chat when it is ready. In a web app that means two events: one for the text, one for the picture.

If you stream the narration, you cannot use JSON mode in the same call in a way that is easy to display, since half a JSON object is not readable. Two clean options exist:

  1. Make two calls. First, a streamed call for the narration with plain text. Second, a short non-streamed JSON call that takes the new narration and returns only the image prompt, with max_tokens set to 80.
  2. Make one call in JSON mode without streaming and accept a short pause before the text appears.

Option one costs a few more input tokens, but the chat feels faster. It also lets you skip the image call on turns that need no picture, such as short dialogue.

Remember the limits. A full key allows 8 concurrent requests and 300 per minute, and a streamed request keeps its slot until the stream ends. If an image step takes a long time, do not hold the text request open while you wait for it; finish the text call first, then start the render in the background.

What it costs

Take a chat where each turn sends about 3,000 input tokens (card plus trimmed history) and receives 350 output tokens for the narration. The second call for the image prompt sends 500 input tokens and returns 60.

  • Story call: 3,000 × 0.15 = 450 and 350 × 0.50 = 175, total 625 divided by 1,000,000 = $0.000625.
  • Prompt call: 500 × 0.15 = 75 and 60 × 0.50 = 30, total 105 divided by 1,000,000 = $0.000105.
  • Per turn on the text side: $0.00073.

One hundred turns cost about $0.073, so $0.50 of trial credit covers a bit over 680 turns. The trial is claimed with one click on the API key page after sign-up, needs no card and lasts 7 days. After that, top-ups run from $20 to $500, with +5% from $50, +10% from $100 and +15% from $200. This site takes crypto only: USDT on TRC20 or USDC on Base. See pricing for details.

The image side is where most of your real cost sits. SDXL needs a capable GPU, either your own or rented, and that cost is separate from this API.

Age and content rules in the pipeline

A pipeline that makes pictures needs more care than a text-only chat, because the image side has fewer natural guardrails. Put the rules in code, not only in prompts.

  • Adult characters only. Every character card should state an adult age. Reject any user request that gives a character a younger age or describes a childlike appearance, before it reaches either model.
  • Validate the image prompt. The text model writes the tags, so check them before rendering. A simple deny list for age-related words in the tags costs nothing and catches mistakes.
  • Keep scenes within your product's scope. If your app is for story illustration, keep the style tags and negative prompt tuned to that. An image classifier on the output is a sensible last step.
  • Log request IDs. The X-Request-Id header on each text call lets you tie a picture back to the turn that produced it.

The text API will answer fiction prompts for lawful adult use without refusing, but it will not generate anything involving minors, and you should not build features that try. Your terms page should say the same.

Checklist before you launch

  • Keep your API key on the server; browsers should never see it.
  • Trim history to the last 20 to 30 messages plus a summary. The window is 100,000 tokens, but you pay for every resent token.
  • Add an age statement to your character cards and keep all characters adult.
  • Log X-Request-Id for each call, so the support team can trace a problem.
  • Handle 429 responses: retry after 5 seconds when Retry-After is present.
  • Tell users that prompts are not used for training by this API, and state what your own app stores.

The docs list every supported parameter. Start with a single character and one scene, get the loop working, and only then add LoRAs, galleries and memory.

Questions and answers

Can this API generate the images for the chat?

No. It is text only. You pair it with an SDXL server of your own or a hosted image service, and the text model writes the image prompts.

How do I keep the same character across images?

Store a fixed appearance string in your code and add it to every image prompt, reuse a seed for portraits, and use LoRA files on the image side if you need stronger identity.

Does JSON mode work with streaming?

Both are supported, but half a JSON object is not readable while it streams. Stream plain narration first, then make a short JSON call for the image prompt.

What does one turn cost?

With 3,000 input tokens and 350 output tokens for the story plus a small prompt call, about $0.00073 per turn on the text side. Image rendering is billed separately by your own hardware or host.

Your key is one form away

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

Get API key