EN ▾

Uncensored chatbot: how to build it via API in Python

To build an uncensored chatbot you need a key, a base URL and an input loop with history. Here you find the full code, streaming and usage rules.

Uncensored AI: Analysis of Available Options

Updated:

Stage with bright spotlights and theatrical masks, image of a conversation with a chatbot.

Key points

  • You just need the OpenAI SDK with base URL https://api.apiiasenzacensura.com/v1 and the uncensored model.
  • You manage the history: for each request you resend the previous messages.
  • Streaming shows the text as it arrives and reduces perceived wait time.
  • Having no model filters does not mean having no rules: age, your moderation, and the ban on minors remain.

What you need

An uncensored chatbot is, technically, a normal chatbot whose model does not reject requests for lawful adult use. The rest is the usual work: a loop that reads input, calls the API and prints the response. You need Python 3.9 or later, the openai package and a key.

  1. Register with Google or with email and password and open the API key page.
  2. Request the $0.50 free trial credit with one click: it lasts 7 days and requires no payment.
  3. Install the SDK with pip install openai.
  4. Save the key in an environment variable, e.g. API_KEY, instead of writing it in the code.

The API is OpenAI-compatible: the base URL is https://api.apiiasenzacensura.com/v1, the model is called uncensored and authentication uses the Authorization: Bearer header. If you need the full picture of available methods, there is the documentation.

First call with curl

Before the real code, verify that the key works.

curl https://api.apiiasenzacensura.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [
      {"role": "system", "content": "Sei un assistente diretto e conciso."},
      {"role": "user", "content": "Presentati in due frasi."}
    ]
  }'

If you receive a JSON with choices[0].message.content, you are good. A 401 error indicates a wrong or missing key; a 429 means you exceeded a limit (2 concurrent requests and 60 per minute with the trial key) and you just need to wait a few seconds.

Terminal chatbot with history and streaming

The model does not remember anything between one call and the next. Conversation memory is a list of messages that you update and resend each time. The script below manages it and prints the response as it arrives.

import os
from openai import OpenAI

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

SISTEMA = "Sei un compagno di conversazione per adulti. Rispondi in italiano, con tono naturale."
storia = [{"role": "system", "content": SISTEMA}]

while True:
    try:
        utente = input("Tu: ").strip()
    except (EOFError, KeyboardInterrupt):
        break
    if not utente:
        continue
    storia.append({"role": "user", "content": utente})

    flusso = client.chat.completions.create(
        model="uncensored",
        messages=storia,
        stream=True,
        temperature=0.8,
    )
    risposta = ""
    print("Bot: ", end="", flush=True)
    for pezzo in flusso:
        if pezzo.choices and pezzo.choices[0].delta.content:
            testo = pezzo.choices[0].delta.content
            risposta += testo
            print(testo, end="", flush=True)
    print()
    storia.append({"role": "assistant", "content": risposta})

Three details matter. First, control pezzo.choices: the last streaming event may contain only usage data, no text. Second, the full response must be added to the history with the assistant role; otherwise, the bot won't remember what it said in the next turn. Third, with streaming, your script holds a concurrency slot until the stream ends.

Keep history under control

The longer the conversation, the more tokens you send each turn, and the more you pay. The maximum context window is 100,000 tokens between prompt and response, so sooner or later you must cut. A simple strategy is to keep the system prompt and the last N messages.

import os
from openai import OpenAI

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

def ridotta(storia, massimo=24):
    # tiene il messaggio di sistema e gli ultimi N messaggi
    return storia[:1] + storia[1:][-massimo:]

def riassumi(vecchi):
    testo = "\n".join(f"{m['role']}: {m['content']}" for m in vecchi)
    r = client.chat.completions.create(
        model="uncensored",
        messages=[{"role": "user", "content": "Riassumi in 5 righe questa conversazione:\n" + testo}],
        max_tokens=300,
    )
    return r.choices[0].message.content

The second function enables a finer-grained variant: instead of discarding old messages, you summarize them with a separate call and place the summary right after the system prompt. You lose some details, but the character or context remain coherent. For a conversation partner or role-playing game, it is usually worth keeping important facts in a fixed note in the system prompt.

How much does a conversation cost

Let's do a realistic calculation. 300-token system prompt, 100 tokens per user message, 250 per response. At turn k the input is 400 + 350 × (k − 1) tokens, because previous turns accumulate.

  • Input over 20 turns: 20 × 400 + 350 × (0 + 1 + … + 19) = 8,000 + 350 × 190 = 74,500 tokens.
  • Output over 20 turns: 20 × 250 = 5,000 tokens.
  • Cost: 74,500 × $0.15 / 1M = $0.011175, plus 5,000 × $0.50 / 1M = $0.0025. Total about $0.0137.

With the $0.50 free trial credit you can therefore have about 36 conversations of that type ($0.50 / $0.013675 = 36.6). A bot with 1,000 identical conversations per month would spend about $13.68. The price list is on the pricing page, and top ups start at $20 with crypto payment (USDT on TRC20 or USDC on Base). The credit never expires and failed requests are not charged.

System prompts and parameters that change the character

Most of the bot's personality lies in the system prompt. A vague message like "be nice" produces generic answers; a concrete one gives better results. Specify who the character is, how they speak, how much they write and what they must not do. For example: "You are Marta, guide of a role-playing game set in a port city. Write a maximum of five sentences per response. Never break character unless the user writes STOP."

On parameters, three practical rules:

  • temperature between 0.7 and 1 for creative conversations, lower (0.2 or 0.3) for answers that must remain stable;
  • top_p is an alternative to temperature: do not change both together, otherwise you will not understand which of the two produced the effect;
  • presence_penalty and frequency_penalty reduce repetitions, useful when the bot tends to repeat the same phrases.

Change one parameter at a time and compare responses on the same message. With a fixed seed the comparison is cleaner. If the bot ignores an instruction, the solution is often to put it higher in the system prompt or repeat it briefly in the last message. There is no guaranteed formula, but some trial of this kind is worth more than many hours of theory.

From terminal to web app

When moving from script to service, there is only one rule: the key stays on the server. The browser talks to your backend, which in turn calls the API. If you put the key in client-side JavaScript, anyone opening development tools copies it and consumes your credit.

For the interface you can also write nothing: many chat clients accept an OpenAI-compatible endpoint, and you just need to enter the base URL, API key, and model uncensored. The exact field names vary from app to app, so check the documentation of the tool you choose.

If you need the bot to call external functions, like a weather service or a database, the API supports tool calling with tools and tool_choice. With response_format set to json_object you receive structured responses that your code can read without interpreting free text.

Usage rules and responsibility

An uncensored model shifts the responsibility to you. The model is trained not to refuse, but the decision on who can use your bot and what it can do lies with the publisher. Some best practices:

  • Adults only. If you open the bot to the public, add an age verification and clearly state that it is for lawful adult use.
  • Minors: absolute limit. No sexual content involving minors, in any case and with any prompt formulation.
  • Your moderation. If you host different users, consider a conversation log, a way to report abuse and the ability to block an account.
  • Text only. The API does not generate images, audio or video. Other tools are needed for those.
  • Data. Prompts are not used for training, but they are still text passing through an external service: do not ask users for data that is not needed.

For an overview of the service, see the uncensored AI page.

Other guides

FAQ

Do I need to install a model on my computer?

No. The model runs on the provider side and you call it via HTTP. You only need Python, the openai package, and an API key.

Does the chatbot remember past conversations?

Only if you make it remember: for each request, you pass the history. For long sessions, save it to a file or database and summarize the old part.

Can I use the same code with other OpenAI clients?

Yes. Change the base URL and key and set the uncensored model. Chat completions, responses, and the model list via GET /v1/models are available.

Can the bot generate images?

No. The API is text-only: no images, audio, video, embeddings, or fine-tuning.

Your key is just a form away

Create an account, copy the key, edit the base URL. That's all the configuration.