Abliterated AI Chat: Build a Streaming Chat App
You can build an abliterated ai chat interface in under 100 lines using any OpenAI SDK. This guide covers streaming, conversation history, the 100,000-token window and the rate limits you will hit first.
Updated

Key points
- Point the OpenAI SDK at the base URL and use the model ID
uncensored. - Stream with stream: true so users see words as they arrive.
- Trim old messages before the window fills, and keep the system prompt fixed.
- A streaming request holds its concurrency slot until the stream ends, so plan for 429 responses.
The minimal streaming chat loop
An abliterated ai chat app needs three things: an endpoint that speaks the OpenAI chat format, a way to stream tokens to the screen, and a message list you keep on your side. The API is stateless, so it never stores your conversation. Each request carries the whole history.
Here is a terminal chat in Python. It keeps a list of messages, streams the reply, and appends the finished answer to the history so the next turn has context.
from openai import OpenAI
client = OpenAI(
base_url="https://api.abliteratedai.top/v1",
api_key="YOUR_KEY",
)
history = [
{"role": "system", "content": "You are a witty co-writer for adult fiction. Stay in the scene."}
]
while True:
user = input("you> ")
if not user:
break
history.append({"role": "user", "content": user})
stream = client.chat.completions.create(
model="uncensored",
messages=history,
stream=True,
temperature=0.9,
)
answer = ""
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
piece = chunk.choices[0].delta.content
answer += piece
print(piece, end="", flush=True)
print()
history.append({"role": "assistant", "content": answer})
Streaming goes over server-sent events. The SDK parses them for you, and the final chunk carries usage, so you can log what each turn cost.
Streaming to a browser
For a web UI, keep the key on your server. A browser that calls the API directly exposes your key to anyone who opens the network tab. Instead, make a small endpoint that forwards the stream. This Node example uses Express and the OpenAI SDK.
import express from "express";
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.abliteratedai.top/v1",
apiKey: process.env.API_KEY,
});
const app = express();
app.use(express.json());
app.post("/chat", async (req, res) => {
res.setHeader("Content-Type", "text/event-stream");
res.setHeader("Cache-Control", "no-cache");
const stream = await client.chat.completions.create({
model: "uncensored",
messages: req.body.messages,
stream: true,
});
req.on("close", () => stream.controller.abort());
for await (const chunk of stream) {
const text = chunk.choices[0]?.delta?.content;
if (text) res.write("data: " + JSON.stringify(text) + "\n\n");
}
res.write("data: [DONE]\n\n");
res.end();
});
app.listen(3000);
Notice the req.on("close") line. If the user closes the tab, abort the upstream request. A streamed request occupies its concurrency slot until the stream ends, so an abandoned stream wastes a slot that another user needs.
Managing history inside the 100,000-token window
The context window is 100,000 tokens, shared between your prompt and the completion. That is a lot of room, but a long roleplay session or a chat that pastes in documents will get there. Two things go wrong if you ignore it: the request fails, or you pay to resend a huge history on every turn.
The cost side is worth a calculation. Suppose a conversation has grown to 20,000 tokens of history and the user sends a short message that gets a 500-token reply. Input is 20,000 tokens at $0.15 per 1M, which is $0.003. Output is 500 tokens at $0.50 per 1M, which is $0.00025. That turn costs $0.00325. Ten more turns at roughly that size cost about three cents. The history dominates the bill, not the reply.
A simple trimming policy
- Always keep the system prompt as the first message.
- Keep the most recent N turns in full, for example the last 20 messages.
- Replace older turns with a short summary that you generate with the same model, and store it as a second system message.
- Count tokens with a tokenizer estimate. Four characters per token is a rough rule for English, so leave a margin.
Keep the summary factual and short. Character names, relationships, open plot threads and stated preferences are the details that readers notice when they go missing.
Sampling settings that suit chat
The API passes through temperature, top_p, stop, seed and the penalty parameters. For open-ended chat, a temperature between 0.7 and 1.0 gives varied replies. Lower it to 0.2 or 0.3 for tasks where you want consistent structure, such as extracting data from a message.
Set presence_penalty or frequency_penalty slightly above zero if the model starts looping on the same phrases in long sessions. Use seed when you want to reproduce a reply while debugging. The stop parameter is useful when you build a script-style chat where each character speaks in turn and you want the model to halt before it writes the user's lines.
The max_tokens parameter is optional. Without it, the completion can use whatever is left of the window. For a chat interface, set a sane cap anyway, such as 800 tokens, so a runaway reply does not cost more than you expect.
Handling rate limits and concurrency
A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent requests and 60 per minute. Because streaming holds a slot for the whole reply, concurrency is usually the limit you hit first. Eight users reading long replies at the same moment fill all eight slots.
When you go over, the API returns HTTP 429. Read the error code in the body:
rate_limitedmeans too many requests per minute.concurrencymeans too many requests at once.- A 429 with a
Retry-After: 5header means temporary overload, and you should wait five seconds before trying again.
The response headers X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency tell you the limits for your key, and X-Balance-USD shows the remaining balance. Log X-Request-Id with every call, since it is the first thing to quote if you need help tracing one request.
import time
from openai import OpenAI, RateLimitError
client = OpenAI(base_url="https://api.abliteratedai.top/v1", api_key="YOUR_KEY")
def chat_with_retry(messages):
for attempt in range(4):
try:
return client.chat.completions.create(model="uncensored", messages=messages)
except RateLimitError:
time.sleep(5 * (attempt + 1))
raise RuntimeError("still limited after retries")
For a user-facing app, a small queue in front of the API is better than letting users see errors. Put a request in the queue when all slots are busy and show a short "waiting" state.
Prompting for characters and tone
The model is tuned to answer without content refusals for lawful adult use, so your system prompt can focus on the product instead of defending against refusals. State the role, the voice, the format, and the boundaries you want. Short and specific beats long and vague.
A few habits help in chat products. Put hard rules at the top of the system prompt and repeat the one that matters most at the end. Tell the model not to speak for the user. Give it a sample exchange in the voice you want. For fiction and roleplay, keep a short "scene state" block with location, time and who is present, and update it as the story moves.
One rule is fixed by the service and by you as the operator: no sexual content involving minors. If your app has user-defined characters, validate the character's stated age in your own code and reject anything that fails, instead of relying on the model to catch it. The AI girlfriend API production checklist covers age gating, persistence and moderation hooks in more depth.
Testing the chat before you launch
A chat app fails in ways a single test prompt never shows, so build a short test script before you invite users. Aim for a handful of scenarios and run them after every change to your prompt or trimming code.
- Long session. Replay a scripted 200-message conversation and confirm that trimming kicks in and the character stays consistent.
- Interrupted stream. Close the connection halfway through a reply and check that your server aborts the upstream call and that the partial text is not saved as a full answer.
- Parallel users. Start ten streams at once and watch for 429 responses with the
concurrencycode. Confirm that your queue and retry logic handles them without losing messages. - Empty and huge inputs. Send an empty message and a very large paste. The maximum request body is 8 MB, and a paste that big would also overflow the token window long before that.
- Tool calls. If your bot books scenes, rolls dice or looks up memory through tools, test that streamed
tool_callsarrive complete before you run them, and return results asrole: "tool"messages.
Log the usage numbers from every turn during these tests. A week of real traffic will show you the average tokens per turn, and that number turns a vague idea of cost into a figure you can budget.
Costs, trial and next steps
Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens, pay as you go from prepaid credit. Failed or refused requests are not charged and credit never expires. A chat turn that sends 3,000 tokens of history and gets 400 tokens back costs $0.00045 for input plus $0.0002 for output, or $0.00065 in total. At that size, $1 pays for about 1,500 turns.
To build and test, claim the $0.50 trial on the API key page after signing up with Google or email. It is valid for 7 days and needs no payment method. When you go live, top-ups are crypto only (USDT on TRC20 or USDC on Base), from $20 to $500, with bonuses of 5%, 10% and 15% at $50, $100 and $200. Details are on the pricing page, and the documentation has the full parameter list, tool calling and JSON mode.
More guides
Questions and answers
Can I use the OpenAI SDK for an abliterated AI chat?
Yes. Set the base URL to https://api.abliteratedai.top/v1, use your key, and set the model to uncensored. The rest of the code is the standard chat completions format.
Does the API remember my conversation?
No. You send the full message history with each request, and you decide what to keep or trim. The window is 100,000 tokens for prompt and completion together.
How many users can chat at once?
A full key allows 8 concurrent requests and 300 requests per minute. Streams hold a slot until they end, so queue extra requests on your side.
Are my chats used for training?
No. Prompts are not used for training.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.