EN ▾
nofilterai.top
NoFilter AI
Get API key

No Filter AI Roleplay App: Build One With an API

An AI girlfriend API provides a dedicated interface for chat applications that simulate romantic or companion-like interactions using large language models. This guide compares technical approaches, focusing on uncensored models that handle roleplay context without standard content refusals.

A miniature theatre stage connected by a glowing data stream to a server, illustrating a roleplay app architecture

The architecture in one picture

The browser sends the user's message to your server. Your server adds the persona and the recent history, calls the model with stream: true, and forwards each chunk back. Nothing else is required.

  1. Browser: a text box and a div that grows as tokens arrive.
  2. Your server: keeps the API key, builds the message list, enforces your own per-user limits.
  3. Model API: POST /v1/chat/completions at https://api.nofilterai.top/v1 with model uncensored.
  4. Storage: a table or file of messages per conversation. SQLite is enough to start.

The model is one open-weight model, tuned to answer without content refusals for lawful adult use. It is text only. If you want character art or voice, you add another service yourself.

Design the system prompt

For roleplay, the system prompt does most of the work. Split it into three short blocks so you can swap each one independently: the world, the character, and the rules of the format.

{
  "world": "A rain-soaked port city in 1920s Europe, run by rival smuggling families.",
  "character": "Ilse, a sharp-tongued ferry captain who trusts nobody but her brother.",
  "format": "Write in third person past tense. 2 to 4 short paragraphs. Never write the user's actions or lines."
}

Join them into one system message at request time. Keeping them separate lets users pick a world and a character independently, which is most of what a roleplay app needs. Because adult fiction is allowed for lawful adult use, say so once in your own terms of service and add an age gate. The one thing the API will not produce is sexual content involving minors, and your app should not try.

The streaming backend

This Express route accepts a conversation ID and a message, loads the history, and pipes the stream to the browser as server-sent events. It uses the official openai package.

import express from "express";
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.nofilterai.top/v1",
  apiKey: process.env.API_KEY,
});

const app = express();
app.use(express.json());
const store = new Map(); // conversationId -> messages

app.post("/chat", async (req, res) => {
  const { id, text, persona } = req.body;
  const history = store.get(id) ?? [];
  history.push({ role: "user", content: text });

  res.setHeader("Content-Type", "text/event-stream");
  res.setHeader("Cache-Control", "no-cache");

  const stream = await client.chat.completions.create({
    model: "uncensored",
    messages: [{ role: "system", content: persona }, ...trim(history)],
    stream: true,
    temperature: 0.9,
  });

  let reply = "";
  for await (const chunk of stream) {
    const piece = chunk.choices[0]?.delta?.content ?? "";
    if (piece) {
      reply += piece;
      res.write("data: " + JSON.stringify(piece) + "\n\n");
    }
  }
  history.push({ role: "assistant", content: reply });
  store.set(id, history);
  res.write("data: [DONE]\n\n");
  res.end();
});

app.listen(3000);

The final chunk of a stream carries usage, which you can log to see what each conversation costs. In production, replace the Map with a database and add error handling around the call.

Trim history inside the 100k window

The context window is 100,000 tokens for prompt plus completion. Roleplay sessions grow slowly, but they grow. A trim function that works by size avoids surprises. A rough estimate of 4 characters per token is good enough for budgeting.

function trim(history, maxChars = 120000) {
  let total = 0;
  const kept = [];
  for (let i = history.length - 1; i >= 0; i--) {
    total += history[i].content.length;
    if (total > maxChars) break;
    kept.unshift(history[i]);
  }
  return kept;
}

120,000 characters is about 30,000 tokens, far below the limit, and it keeps each call cheap. Raise it only if your story needs long recall. Remember the cost rule: every turn resends the kept history as input at $0.15 per 1M tokens, so a 30,000-token prompt costs 30,000 / 1,000,000 x $0.15 = $0.0045 per turn before the reply.

The browser client

The page reads the SSE stream with fetch and appends text as it arrives. Because the request is a POST, EventSource does not fit, so parse the stream by hand.

async function send(text) {
  const out = document.getElementById("reply");
  out.textContent = "";
  const r = await fetch("/chat", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ id: "demo", text, persona: PERSONA }),
  });
  const reader = r.body.getReader();
  const dec = new TextDecoder();
  let buf = "";
  while (true) {
    const { value, done } = await reader.read();
    if (done) break;
    buf += dec.decode(value, { stream: true });
    const parts = buf.split("\n\n");
    buf = parts.pop();
    for (const p of parts) {
      if (p === "data: [DONE]") break;
      if (p.startsWith("data: ")) {
        out.textContent += JSON.parse(p.slice(6));
      }
    }
  }
}

Features that make it feel like an app

  • Regenerate and edit. Keep message IDs. Regenerate means deleting the last assistant message and calling the API again with the same history. Editing means rewriting a stored message before the next call.
  • Per-character settings. Store temperature, top_p and penalties with each character. Calmer characters like 0.7, chaotic ones like 1.0. Pass seed when you want reproducible test runs.
  • Cost display. Read the X-Balance-USD response header or call GET /v1/balance and show the user how much credit is left. If you resell access to your own users, this saves you a lot of support questions.
  • Safety rails you own. Add an adult-only gate, a report button, and a rule that blocks any request involving minors before it reaches the API. The platform enforces that limit as well, but your app should too.

Limits, errors and budgets

A full key allows 8 concurrent requests and 300 requests per minute. A streamed request holds a concurrency slot until the stream ends, so a roleplay app with 20 active users will hit the cap during busy minutes. The API answers HTTP 429 with the code concurrency or rate_limited, and on temporary overload it adds Retry-After: 5. Queue requests on your server and retry after that delay.

Failed or refused requests are not charged, so retries do not cost you. For budgeting, a typical turn of 3,000 input tokens and 300 output tokens costs $0.00045 + $0.00015 = $0.0006. Credit is prepaid from $20 and never expires. This site accepts crypto, USDT on TRC20 or USDC on Base; the pricing page lists the bonuses from $50 up.

Where to go next

Get a key and test with the free trial: the API key page offers $0.50 of credit after sign-up, valid for 7 days, no payment details. The trial key allows 2 concurrent requests, enough for a single-user prototype. The docs list every parameter, including tool calling if you want dice rolls or inventory handled as function calls.

For a companion-style variant with a single persistent character, see the AI companion API article. For a chat bot inside a server, read the Discord bot guide.

Questions and answers

Can I call the API directly from the browser?

You can, but you would expose your key to every visitor. Keep the key on a server and expose only your own route.

How do I stop the model from writing my character's actions?

State it in the system prompt and, if you use a transcript format, add a stop sequence. Both work with the pass-through parameters.

Does the app need to store conversations?

The API itself is stateless, so you resend the history each turn. Prompts are not used for training.

What is the cheapest way to prototype?

Use the trial key and a Map in memory. Move to a database and a funded key once the loop works.

Your key is one form away

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

Get API key