Uncensored AI API integration in a web app
A solid uncensored AI API integration puts a small server of your own between the browser and the API, keeps the chat history there, streams replies back and retries on rate limits. This guide builds that in Node with the OpenAI SDK and base URL https://api.censuresansia.com/v1.
Last updated

Summary
- Never call the API from the browser: keep the key on a backend you control.
- The API is stateless, so your backend stores and resends the history, and trims it to control cost.
- Handle HTTP 429 using Retry-After, and keep concurrency within 8 on a full key.
- Add your own age gate and terms; content involving minors is never allowed.
The architecture in one picture
The shape is simple: the browser talks to your server, your server talks to the API. The key and the system prompt live on the server, so users cannot read or change them.
Browser --POST /chat--> Your backend --POST /v1/chat/completions--> API
^ | keeps: key, system prompt, history
|_____ streamed text ______|
The service is an OpenAI-compatible text API: base URL https://api.censuresansia.com/v1, model ID uncensored, Bearer key. It runs a single open-weight model from an independent provider, tuned to answer without content refusals for lawful adult use. Any official OpenAI SDK works; this guide uses the Node one (npm install openai express). Get a key on the API key page, where new users can also claim a $0.50 trial.
The chat endpoint
This server keeps one history per session in memory, sends it to the API with the system prompt in French, and streams the answer to the browser as server-sent events. For production, replace the Map with a database.
import express from "express";
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.censuresansia.com/v1",
apiKey: process.env.API_KEY,
maxRetries: 0,
});
const SYSTEM = "Tu es un assistant d ecriture creative. Reponds en francais, de facon claire et concise.";
const sessions = new Map();
const app = express();
app.use(express.json({ limit: "1mb" }));
app.post("/chat", async (req, res) => {
const { sessionId, message } = req.body;
if (sessionId === undefined || message === undefined) return res.status(400).json({ error: "bad request" });
const history = sessions.get(sessionId) ?? [{ role: "system", content: SYSTEM }];
history.push({ role: "user", content: message });
res.setHeader("Content-Type", "text/event-stream");
res.setHeader("Cache-Control", "no-cache");
let answer = "";
try {
const stream = await client.chat.completions.create({
model: "uncensored",
messages: history,
stream: true,
temperature: 0.8,
});
for await (const part of stream) {
const piece = part.choices[0]?.delta?.content ?? "";
if (piece) {
answer += piece;
res.write("data: " + JSON.stringify({ t: piece }) + "\n\n");
}
}
history.push({ role: "assistant", content: answer });
sessions.set(sessionId, history);
res.write("data: [DONE]\n\n");
} catch (err) {
res.write("data: " + JSON.stringify({ error: "temporarily unavailable" }) + "\n\n");
}
res.end();
});
app.listen(3000);
The browser reads the stream with fetch and a reader, or with a small SSE helper, and appends each t value to the page. Note that the user's message is pushed to the history before the call; if the call fails, remove it again or the next attempt will send it twice.
History: store it, trim it
The API remembers nothing between requests, so the history you send is the model's entire memory. That gives you control and a cost to manage. Input tokens cost $0.15 per 1M, and the full history is billed again on every turn. A session with a 300-token system prompt and 400 tokens per exchange has cost, by turn 30, about 300 + 29 x 400 = 11,900 input tokens on that single call, which is $0.0018. Not much, but it adds up across thousands of users.
Three practical policies:
- Keep the last N messages (for example 30) plus the system prompt.
- Summarise the oldest part with one extra call and replace it with a short note.
- Store user facts separately and inject them as a line in the system prompt.
The context window is 100,000 tokens in total, so the limit is mostly about cost and focus, not about running out of room.
Errors, retries and rate limits
Limits on a full key are 8 concurrent requests and 300 requests per minute (trial key: 2 and 60). The API returns HTTP 429 when you exceed them: code rate_limited for the minute rate, concurrency for too many at once, and also 429 with Retry-After: 5 during a temporary overload. A streamed request keeps its slot until the stream ends, so a slow client ties up capacity.
In a web app the cleanest approach is a queue on your server that allows at most 8 upstream calls at a time (or fewer, to leave headroom), and a retry that honours the header:
async function withRetry(fn, tries = 3) {
for (let i = 0; i < tries; i++) {
try {
return await fn();
} catch (err) {
if (err.status === 429 && i < tries - 1) {
const wait = Number(err.headers?.["retry-after"] ?? 5);
await new Promise((r) => setTimeout(r, wait * 1000));
} else {
throw err;
}
}
}
}
Failed or refused requests are not charged, so retrying is safe for your balance. Log the X-Request-Id response header with every error. It is the identifier support will ask for. Tell the user something plain, such as "busy, trying again", instead of showing a raw error.
French prompts and the system message
The system message decides tone and language, so write it in the language you want back. A few lines work better than a long manifesto: who the assistant is, the language and register, the length of the answers, and what to do when the user asks for something outside the scope of your product. If you vary the register, say "vouvoiement" or "tutoiement" explicitly.
Do not assume results. French quality depends on your task, so collect 20 real user messages from your product and read the answers before launch. Keep temperature around 0.7 to 0.9 for creative apps and 0.2 or lower for extraction. For structured output, set response_format to {"type":"json_object"} and list the keys in the prompt. Tool calling is available through the standard tools parameter; see the documentation for its format.
Responsibilities on your side
The model is tuned to answer without content refusals for lawful adult use. That puts some duties on you as the app owner. Add an age confirmation and terms of use suited to your audience. Decide what your own product allows and filter accordingly. Content involving minors is never permitted and must not appear in your product. Do not log more user text than you need, and tell users how long you keep it. The service states that prompts are not used for training, but your own database is your responsibility.
Keep the API key on the server, outside version control, and never expose it in browser code. If you also want a plain explanation of what the label means, our article on myths and facts about uncensored AI is a short read.
Going live: a short checklist
- Test with a trial key, then buy a first top-up on the pricing page (from $20, in USDT on TRC20 or USDC on Base).
- Cap upstream concurrency in your queue at 8 or lower.
- Set a history limit and a maximum message length. The request body limit is 8 MB, but you will want far less.
- Log request IDs, token usage and the
X-Balance-USDheader; alert yourself when the balance is low. - Add a visible notice that the service is text only.
A last point on moderation. Because the model answers without content refusals for lawful adult use, your product is the place where house rules live. Put them in the system message, check user input on your server before it reaches the API, and keep a way for users to report problems. Do this before launch, not after the first complaint.
Cost is easy to estimate once you log real usage. A request with 3,000 tokens in and 300 out costs 3,000 x $0.15 / 1M + 300 x $0.50 / 1M = $0.00045 + $0.00015 = $0.0006, so 10,000 such requests cost $6.
More guides
Technical FAQs
Why not call the API directly from the browser?
Your key would be visible to every visitor and anyone could spend your credit. Keep the key on a server.
Does the API store conversation history for me?
No. Each request is independent, so your backend sends the history each time.
What happens if I exceed the rate limit?
You get HTTP 429 with a code of rate_limited or concurrency. Wait for the Retry-After time and try again.
Can I use Python instead of Node?
Yes. The OpenAI Python SDK works the same way with the same base URL, key and model ID.
Generate your API key
Sign up, grab the key, update your base URL. That is the entire configuration.