EN ▾

Roleplay Chat With No Login: Build It on an API

A roleplay chat no login is easy to ship if you split the problem in two: you hold one API key on your server, and your visitors never see an account screen. Here is the architecture, working code, and what each turn costs.

Updated

Isometric stage with two masks and floating chat bubbles fed by one key from a server, for an anonymous roleplay chat

Key points

  • You sign up once for a key. Your visitors do not need an account at all.
  • Keep the key and the character prompts on a server, and let the browser talk only to your own endpoint.
  • A typical turn of 3,000 input and 300 output tokens costs $0.0006, so 1,000 turns cost $0.60.
  • Per-IP limits, a history cap and a concurrency queue protect your balance from anonymous traffic.

What no login can and cannot mean

If you are looking for a ready-made site where anyone chats with a character without registering, that is a product somebody else would have to run. This article is for developers who want to build one. The API itself needs a key, and the key comes from an account: sign-up is with Google or with email and password, once, by you.

What your visitors experience is up to you. They can open your page, pick a character and start typing, with no email, no password and no profile. All the account machinery lives between your server and the API, and it consists of exactly one secret. That is the whole trick, and it is how most anonymous chat demos on the web work.

Two things to decide up front. First, who pays: with no login, you do, from prepaid credit, so you need protection against abuse. Second, who may use it: roleplay and fiction apps built here are for lawful adult use, and sexual content involving minors is a hard limit of the service. Put an adult notice on the entry page, and do not offer characters or scenarios that point toward that line.

Architecture: one key, many anonymous visitors

The pieces are small:

  1. The browser holds the conversation in memory and in localStorage. It talks only to /chat on your domain.
  2. Your server owns the API key, maps a character name to a system prompt, trims history and forwards the stream.
  3. The API at https://api.uncensoredchat.top/v1 receives a standard OpenAI-style chat completion request with the model uncensored and answers over server-sent events.

Never call the API directly from the browser. A key in client code can be copied by anyone who opens the developer tools, and it can then spend your balance. The server hop costs a few milliseconds and removes that problem. It also lets you keep the character prompts private and add limits in one place.

The site has a separate walk-through of the endpoint itself in the Uncensored Chat API guide, and the quickstart shows the same request in curl and Python.

The server: a streaming proxy in Node

This Express server needs Node 18 or newer for the built-in fetch. Personas live in an object on the server, so a visitor can choose only from the list you wrote. History is capped at the last 24 messages, each message at 4,000 characters, and the reply at 400 tokens.

import express from "express";

const app = express();
app.use(express.json({ limit: "1mb" }));

const BASE = "https://api.uncensoredchat.top/v1";
const KEY = process.env.UNCENSORED_KEY;

// Personas live on the server, so visitors cannot rewrite them.
const PERSONAS = {
  captain: "You are Captain Mara, a dry-witted starship pilot in an ongoing story. Stay in character.",
  innkeeper: "You are Old Bram, a gossiping innkeeper in a fantasy town. Stay in character.",
};

app.post("/chat", async (req, res) => {
  const { persona, messages } = req.body;
  const system = PERSONAS[persona];
  if (system === undefined || Array.isArray(messages) === false) {
    return res.status(400).json({ error: "bad request" });
  }
  const recent = messages.slice(-24).map((m) => ({
    role: m.role === "assistant" ? "assistant" : "user",
    content: String(m.content).slice(0, 4000),
  }));

  const upstream = await fetch(`${BASE}/chat/completions`, {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "uncensored",
      stream: true,
      temperature: 0.9,
      max_tokens: 400,
      messages: [{ role: "system", content: system }, ...recent],
    }),
  });

  if (upstream.status === 429) {
    res.set("Retry-After", upstream.headers.get("retry-after") || "5");
    return res.status(429).json({ error: "busy, try again in a few seconds" });
  }

  res.status(upstream.status);
  res.set("Content-Type", "text/event-stream");
  for await (const chunk of upstream.body) {
    res.write(chunk);
  }
  res.end();
});

app.listen(3000);

Three details earn their place. Only user and assistant roles pass through, so a visitor cannot inject their own system message. The 429 branch forwards a short wait, because on temporary overload the API returns 429 with a Retry-After: 5 header. And the stream is piped straight through, so the first words appear while the rest is still being written.

The browser: anonymous history and live text

With no accounts, the browser is the database. Store the message list in localStorage and send it with each request. This client reads the event stream, appends tokens as they arrive and saves the finished turn.

// Talks only to our own /chat route. The server calls https://api.uncensoredchat.top/v1 with model "uncensored".
const history = JSON.parse(localStorage.getItem("chat") || "[]");

async function send(text) {
  history.push({ role: "user", content: text });
  const res = await fetch("/chat", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ persona: "captain", messages: history }),
  });
  const reader = res.body.getReader();
  const decoder = new TextDecoder();
  let reply = "";
  let buffer = "";
  while (true) {
    const { value, done } = await reader.read();
    if (done) break;
    buffer += decoder.decode(value, { stream: true });
    const lines = buffer.split("\n");
    buffer = lines.pop();
    for (const line of lines) {
      if (line.startsWith("data: ") === false || line.includes("[DONE]")) continue;
      const delta = JSON.parse(line.slice(6)).choices[0].delta.content;
      if (delta) { reply += delta; render(reply); }
    }
  }
  history.push({ role: "assistant", content: reply });
  localStorage.setItem("chat", JSON.stringify(history));
}

One design note on identity. A random session ID is optional here, since the history already travels with each request. Add one only if you want server-side rate limits per visitor instead of per address, because many people share an IP behind a mobile network or an office. Generate it with crypto.randomUUID(), keep it in a cookie, and treat it as a label for counting turns, never as proof of who someone is.

Wrap the localStorage calls in try/catch in production, because private windows can block them. If a visitor clears their data, the story is gone; offer an export button that downloads the history as JSON and an import button to load it back. That is the closest thing to a save file that you can offer without accounts, and it keeps you from storing anyone's private fiction on your server.

Keeping anonymous traffic from draining your credit

Anyone can open your page, including scripts. Four limits keep the cost predictable.

  • Per-IP rate limit. Allow a handful of turns per minute per address. This is a few lines with an Express rate-limit middleware.
  • History cap. Already in the code. Without it, a long session sends ever more input on every turn.
  • Output cap. max_tokens: 400 stops one request from producing a novel.
  • A queue for concurrency. A full key allows 8 concurrent requests and 300 requests per minute, and a streamed request occupies its slot until the stream ends. If nine visitors send at once, the ninth receives a 429 with the error code concurrency. Queue requests on your side and release them as streams finish.

Pick the numbers from your own traffic, not from a guess. A person reading and typing a reply rarely sends more than a few turns a minute, so a limit of six turns per minute per address is generous for humans and tight for scripts. Return a plain 429 with a friendly message when it is exceeded. If you notice one address sending the same long text repeatedly, block it for an hour; a short blocklist in memory is enough for a small site.

Watch the balance as well. Every API response includes an X-Balance-USD header; log it and send yourself an alert when it falls below a level you choose.

What a turn costs

Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens. In a roleplay chat the input is the persona prompt plus up to 24 messages of history, and the output is the character's reply. Take a mid-conversation turn of 3,000 input tokens and 300 output tokens:

  • Input: 3,000 / 1,000,000 x $0.15 = $0.00045
  • Output: 300 / 1,000,000 x $0.50 = $0.00015
  • One turn: $0.00045 + $0.00015 = $0.0006

A thousand turns cost $0.60, and ten thousand cost $6.00. The $0.50 trial credit that a new account can claim with one click covers about 833 turns, since 0.50 divided by 0.0006 is 833.3. That is enough to test the whole flow with friends before you put money in. Failed or refused requests are not charged, and credit never expires, so an idle site costs nothing.

The trial key is limited to 2 concurrent requests and 60 requests per minute, which is fine for a private test and too small for a public launch. Move to a funded full key before you share the link.

Paying with crypto and getting started

This site takes top-ups by crypto (USDT on TRC20, USDC on Base), in any whole amount from $20 to $500. Bonuses are +5% from $50, +10% from $100 and +15% from $200. A $20 top-up buys about 33,333 turns of the size above (20 divided by 0.0006), which is a lot of conversation for a launch.

The steps from zero: create an account, claim the trial credit on the API key page, set UNCENSORED_KEY in your server environment, run the proxy above, and open your page. When the flow works, check the pricing page and top up. Model ID, base URL and the request format are the same as for any OpenAI-compatible client, so you can swap the front end later without touching the key handling.

Questions and answers

Do my visitors need an account to use the chat?

No. Only you need an account, to get the API key. Visitors talk to your server, which uses the key on their behalf.

Can I put the API key directly in front-end code?

Do not. Anyone can read it from the page and spend your balance. Keep it in an environment variable on a server and expose only your own chat endpoint.

How do I stop abuse when there is no login?

Limit requests per IP, cap history length and max_tokens, queue requests to stay within 8 concurrent, and alert on the X-Balance-USD header.

Is any content off limits?

Sexual content involving minors is a hard limit and is never allowed. Use is intended for lawful adult fiction and roleplay.

Your key is one form away

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

Get API keyRead the docs