LLM Non CensureGuide
Uncensored AI chatbot: build it in Python
An uncensored AI chatbot takes about sixty lines of Python. Here is the code, history management, streaming, cost per conversation, and the rules to follow.


Key points
What you will build
The goal: an uncensored AI chatbot in the command line, which keeps the conversation going, displays the answer as it arrives, and does not crash on the first network error. Once the logic is in place, it transfers effortlessly to a web app, a messaging bot, or a role-playing game.
Prerequisites: Python 3.9 or higher, the openai package (pip install openai) and a key created on the get API key page. The $0.50 free trial credit, no payment method required, is more than enough for this tutorial. The model is called uncensored: it is a text model, tuned to respond without content refusal in a legal adult context. It does not generate images.
Step 1: a first exchange
Before coding the loop, verify that everything responds with a simple curl call:
curl https://api.llmnoncensure.com/v1/chat/completions -H "Authorization: Bearer VOTRE_CLE" -H "Content-Type: application/json" -d '{"model":"uncensored","messages":[{"role":"user","content":"Présente-toi en deux phrases."}]}'
You must receive a JSON with choices[0].message.content. If you get a 401, the key is wrong; if you get a 404, the URL is incomplete. Keep the key in an environment variable and never in the code you publish.
Step 2: conversation history
The API retains nothing between two calls. For a chatbot to "remember", your program keeps a list of messages and sends the entire history with each turn: a system message at the start, then the user and assistant exchanges in order. This is the point beginners most often forget.
The system message sets the bot's character. Be precise about the tone and language, and about what the bot should do when the user goes off-topic. The temperature and top_p parameters are passed to the model: raise the temperature to around 0.9 for a chatty bot, lower it for a factual bot.
A system message that keeps its distance
Four elements are enough: who the bot is, how it speaks, the length of its answers, and what it does in edge cases. For example: "You are a role-playing narrator. You write in the second person, in fewer than five sentences. If the user asks you to break character, you indicate it in one line and then resume." Avoid twenty-line lists of prohibitions: they bloat the input with each turn and the model rarely follows them all. Test with ten messages that push the bot to its limits, then adjust one phrase at a time to see what changed the behavior.
Persisting the conversation
In this tutorial, the history lives in memory. For a real application, save it per user in a database, with a session ID. Load the last messages at the start of each request, apply the same context window, then save the response once the stream is finished.
Step 3: the full program with streaming
Here is the program. It keeps the last 12 messages in addition to the system message, displays tokens as they arrive, and retries after a 429.
import os
import time
from openai import OpenAI, RateLimitError
client = OpenAI(
base_url="https://api.llmnoncensure.com/v1",
api_key=os.environ["LLM_API_KEY"],
)
SYSTEME = {
"role": "system",
"content": "Tu es Margaux, une conteuse sarcastique. Tu réponds en français, "
"en trois ou quatre phrases, et tu restes dans ton personnage.",
}
historique = []
def repondre():
messages = [SYSTEME] + historique[-12:]
for essai in range(4):
try:
flux = client.chat.completions.create(
model="uncensored",
messages=messages,
temperature=0.9,
max_tokens=400,
stream=True,
)
texte = ""
for morceau in flux:
if morceau.choices and morceau.choices[0].delta.content:
partie = morceau.choices[0].delta.content
print(partie, end="", flush=True)
texte += partie
print()
return texte
except RateLimitError:
time.sleep(5)
return "(trop de requêtes, réessayez dans un instant)"
while True:
entree = input("Vous : ").strip()
if entree in ("", "quit", "exit"):
break
historique.append({"role": "user", "content": entree})
print("Margaux : ", end="")
historique.append({"role": "assistant", "content": repondre()})
Each line has a reason. The historique[-12:] slice bounds the input size. The max_tokens=400 avoids endless responses. The retry loop handles the 429 case: the API returns this code with rate_limited or concurrency, and with Retry-After: 5 during temporary overload. An ongoing stream occupies its slot until it ends, so do not launch two responses in parallel with a trial key, limited to 2 parallel requests and 60 per minute.
Conversation cost, calculated
At the rate of $0.15 per million input tokens and $0.50 per million output tokens, let's calculate a 30-turn discussion. Assumptions: 200-token system message, 150 tokens per user message, 250 per response.
- Without history limits, the input at turn k is 200 + 400 × (k − 1) + 150 tokens. Over 30 turns: 6,000 + 4,500 + 400 × 435 = 184,500 tokens, or $0.0277.
- Outputs: 30 × 250 = 7,500 tokens, or $0.00375.
- With a window that bounds input to about 2,600 tokens (the code above keeps 12 messages), total input does not exceed 30 × 2,600 = 78,000 tokens, or at most $0.0117.
Truncation thus reduces input by more than half in this example ($0.0277 vs. at most $0.0117), at the cost of a bot that forgets the start of the discussion. To keep the essentials, regularly summarize old messages into a short paragraph that you place in the system message. The model context window reaches 100,000 tokens, but using it fully is expensive with each turn. Pricing details on the pricing page.
Rules to follow for an uncensored bot
No filter does not mean no rules. As soon as the bot is used by others, several points are your responsibility:
- Legal adult use only. Implement age verification appropriate for your country and audience.
- Content involving minors: excluded. This is a strict service limit, with no exceptions, and you must also prohibit it in your own terms of use.
- Server-side key. Never send the key to the browser. Route calls through your backend.
- Per-user limits. Without a cap, a single visitor can consume your credit. Add a message limit per hour.
- Transparency. Clearly state that the interlocutor is an AI and that it may make mistakes.
Prompts are not used to train the model, but read the privacy policy before collecting your users' data.
Go further
Three ways to extend this program. JSON mode (response_format with {"type":"json_object"}) lets the bot return structured data. Function calling (tools, tool_choice) lets it trigger functions in your code, such as rolling a die or looking up a character sheet. Finally, the seed parameter helps reproduce a response during testing. Everything is described in the documentation.
The balance is available in the X-Balance-USD header or via GET /v1/balance: log it in your dev logs. Once the prototype works, top up between $20 and $500 in crypto (USDT on TRC20 or USDC on Base). The API-integrated uncensored AI integration guide complements this architecture tutorial.
Other guides
FAQ
Does my chatbot remember previous messages on its own?
No. The API is stateless: your code must send the history with each request.
How to display the response as it arrives?
Pass stream=True in the call. Tokens arrive via SSE, and usage is reported at the end of the stream.
What is the maximum conversation size?
The context window is 100,000 tokens, including prompt and response. Truncating history is recommended to limit costs.
Can I add image generation to the chatbot?
Not with this API, which handles text only. You would need another service for images.
Your key is one step away
Create an account, copy the key, update the base URL. That's it.