EN ▾
https://api.chatunrestricted.com/v1uncensored
Get your key
chatunrestricted.com

Last updated

Unrestricted Chatbot AI: Build One With an API

An unrestricted chatbot ai is three parts: a model that does not refuse, a persona written as a system prompt, and a history list your code maintains. This walkthrough builds all three in under 80 lines of Python.

Small stage with a mannequin and ribbons of dialogue bubbles, representing a persona-driven chatbot built on an API

What you are building

Most people who search for an unrestricted chatbot ai want a character that stays in its role, remembers the conversation and does not break the scene with a refusal. That is a small program. The model does the writing; your code holds the persona and the memory.

Here, "unrestricted" means the model was tuned to answer without content refusals for lawful adult use. It is a single open-weight model run by an independent provider, reached through an OpenAI-compatible endpoint, model ID uncensored. It has one fixed limit, no sexual content involving minors, and you decide everything else about what your bot allows.

The bot below is a command-line character. The same structure works behind a web page, a Discord bot or a mobile backend.

Setup

Create an account and claim the trial on the API key page: $0.50 of credit, one click after signing up with Google or email, valid for 7 days. Then install the SDK and export the key.

pip install openai

On macOS or Linux, run export CHAT_API_KEY=your_key. Keep the key out of source files. If it ever leaks, you can reissue it on the same page and the old one stops working immediately.

Write the persona as a system prompt

The persona is the difference between a generic assistant and a character. Good ones answer four questions in a few lines:

  1. Who is speaking? A name and a role the model can picture.
  2. How do they talk? Sentence length, humor, slang, formality.
  3. What shape should a reply have? Paragraph count, whether actions go in asterisks, whether to ask questions back.
  4. What are the ground rules? Who the user is, what the setting allows, what you want to avoid.

Concrete beats clever. "Deadpan, short sentences, never explains jokes" gives better results than a page of backstory. Put backstory in only if the character needs it in every scene, since the persona text is sent with every request and billed as input.

A persona that works

Compare two prompts for the same bartender. The weak one says: "You are a bartender. Be friendly." The strong one names the city, the era, the speech habits and a recurring behaviour, such as polishing a glass when a topic gets uncomfortable. The second gives the model a handful of concrete hooks to reuse, so the character feels consistent across a hundred turns. Spend your words on habits and voice, not on adjectives.

The chat loop with saved history

This is the complete program. It keeps history in a JSON file so the character remembers you after a restart.

import json
import os
from pathlib import Path
from openai import OpenAI

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

PERSONA = """You are Vesper, a dry-witted night-shift bartender in a rain-soaked cyberpunk city.
Voice: short sentences, deadpan humor, occasional street slang.
Format: reply in 1 to 3 short paragraphs, stay in character, never mention being an AI unless asked directly.
Setting rules: the user is an adult regular at the bar. Keep the story going and ask a question when it fits."""

HISTORY_FILE = Path("history.json")
MAX_TURNS = 24   # keep the last 24 messages


def load():
    if HISTORY_FILE.exists():
        return json.loads(HISTORY_FILE.read_text())
    return []


def save(history):
    HISTORY_FILE.write_text(json.dumps(history, indent=2))


def reply(history, user_text):
    history.append({"role": "user", "content": user_text})
    messages = [{"role": "system", "content": PERSONA}] + history[-MAX_TURNS:]
    resp = client.chat.completions.create(
        model="uncensored",
        messages=messages,
        temperature=0.9,
        top_p=0.95,
        max_tokens=400,
        presence_penalty=0.3,
    )
    text = resp.choices[0].message.content
    history.append({"role": "assistant", "content": text})
    save(history)
    return text


if __name__ == "__main__":
    history = load()
    print("Type 'quit' to leave.")
    while True:
        line = input("you> ").strip()
        if line.lower() in ("quit", "exit"):
            break
        print("vesper>", reply(history, line))

Points worth noticing:

  • The system message is built fresh on every call and is not stored in the history file, so you can edit the persona and old chats pick up the change.
  • history[-MAX_TURNS:] sends only the last 24 messages. The API is stateless and every sent token is billed, so a cap keeps both cost and delay under control.
  • The reply is saved before it is returned, so a crash does not lose it.

One history per user

The script above stores a single history.json. For a service with many users, key the file or database row by user ID and load only that user's messages for each request. Never mix histories: a character that quotes another user's chat is the fastest way to lose trust. Sanitise IDs before using them in file names, or use a database instead.

Streaming for a live feel

Waiting for a full reply feels slow in a chat. Streaming shows text as it is generated. Swap the call for a streamed one:

def reply_stream(history, user_text):
    history.append({"role": "user", "content": user_text})
    messages = [{"role": "system", "content": PERSONA}] + history[-MAX_TURNS:]
    stream = client.chat.completions.create(
        model="uncensored", messages=messages, stream=True, temperature=0.9
    )
    parts = []
    for chunk in stream:
        if chunk.choices and chunk.choices[0].delta.content:
            piece = chunk.choices[0].delta.content
            parts.append(piece)
            print(piece, end="", flush=True)
    print()
    text = "".join(parts)
    history.append({"role": "assistant", "content": text})
    save(history)
    return text

A streamed request occupies one of your concurrency slots until the stream ends: 8 on a full key, 2 on a trial key. Rate limits are 300 requests per minute on a full key and 60 on a trial key. If you run many chats at once, queue requests and handle HTTP 429 with the Retry-After value.

Keeping the character stable

Drift in long chats

After many turns, a character can lose its voice. Repeat one line of the persona as a final system message right before the newest user turn, or trim older history so the persona carries more weight.

Repetition

Loops such as the same gesture every reply respond to a small presence_penalty (0.2 to 0.5) and a temperature near 0.9. More on those settings is in the practical guide for developers.

Long-term memory

For stories that run for weeks, ask the model to summarise the oldest 20 messages in 150 words every so often, and store that summary as an extra system message. You keep the plot and drop most of the tokens.

Test the persona before launch

Write ten test messages that push on the character: a rude user, a question about its past, a request to change style, a very short reply like "ok". Run them against a fresh history and read the answers for voice, length and consistency. Edit the persona, run again. Ten tests cost about $0.006, so you can repeat the loop many times for a few cents.

Cost, and the Node version

With 24 messages of history, a persona of 300 tokens and a 400-token reply, one turn is roughly 3,000 input tokens and 300 output tokens. At $0.15 and $0.50 per 1M tokens that is $0.00045 + $0.00015 = $0.0006. A user who sends 50 messages in an evening costs 3 cents. See the pricing page for top-ups from $20.

The same function in Node with the official SDK:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.chatunrestricted.com/v1",
  apiKey: process.env.CHAT_API_KEY,
});

export async function reply(history, userText, persona) {
  history.push({ role: "user", content: userText });
  const res = await client.chat.completions.create({
    model: "uncensored",
    messages: [{ role: "system", content: persona }, ...history.slice(-24)],
    temperature: 0.9,
    max_tokens: 400,
  });
  const text = res.choices[0].message.content;
  history.push({ role: "assistant", content: text });
  return text;
}

Token use grows with history length, so measure it. Print resp.usage.prompt_tokens after each call and watch it climb until the 24-message cap flattens it. That plateau is your steady-state cost per turn.

Rules you still own

A model without refusals moves the responsibility to you. If the bot is public, add an age gate, a way for users to report problems and a policy for what your platform allows. Do not build anything involving minors in sexual contexts: that is blocked and against the service's terms. The docs list every parameter used above.

Frequently asked questions

Does the API remember the conversation for me?

No. It is stateless. Your code stores the messages and sends the recent ones with each request.

How do I keep the bot in character?

Put a specific persona in the system message, keep it first in every request, and cap or summarise old history so the persona is not buried.

Can I run several chatbots at once?

Yes, within the limits: 8 concurrent requests and 300 per minute on a full key. Use a queue to stay under them.

Is there anything the model will not do?

One fixed limit applies: no sexual content involving minors. The rest is tuned for lawful adult use, and your product sets its own rules.

Generate your API key

Sign up, copy your key, and update your base URL. That is all you need to do.