EN ▾
Uncensored Chatbot APIDirect API access to one uncensored LLMGet API key

Uncensored Chatbot APISafety

Chatbot API Integration: Wire a Chat Endpoint Into Your App

A chatbot API integration has one rule you cannot skip: the browser never holds the API key. Put a small backend proxy in the middle, stream replies through it, and the rest is ordinary web development.

Updated

Glass conduit linking a browser cube and a server cube through a locked gate, showing a backend chat proxy

Key points

  • The browser talks to your server; your server talks to the chat API with the key.
  • Stream with server-sent events so replies appear word by word.
  • Cap history, set per-user limits and handle 429 responses with a short wait.
  • The endpoint is OpenAI-compatible, so the official SDK works after a base URL change.

The pattern in one picture

Every safe chatbot api integration looks the same from above. A page in the browser sends the user's message to your own endpoint. Your server adds the system prompt, trims the history, attaches the API key and forwards the call. The reply streams back the same way.

Browser  --POST /api/chat-->  Your server  --POST /v1/chat/completions-->  Chat API
Browser  <--SSE stream------  Your server  <--SSE stream-----------------  Chat API

The proxy exists for four reasons: it hides the key, it lets you check who is calling, it lets you cap cost per user, and it gives you one place to change the model settings later. A key placed in front-end JavaScript is public the moment the page loads, and someone else would spend your prepaid credit.

The API follows the OpenAI format. The base URL is https://api.uncensoredchatbotapi.com/v1, the model is uncensored, and auth is Authorization: Bearer YOUR_KEY. Get a key on the key page.

Step 1: the server proxy

This Express server accepts a conversation, adds a system prompt, calls the API with streaming and relays the text. Install the dependencies with npm i express openai and set CHAT_API_KEY in the environment.

import express from "express";
import OpenAI from "openai";

const app = express();
app.use(express.json({ limit: "200kb" }));
app.use(express.static("public"));

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

const SYSTEM = "You are a helpful companion for adults. Keep replies under 150 words.";

app.post("/api/chat", async (req, res) => {
  const incoming = Array.isArray(req.body.messages) ? req.body.messages : [];
  const clean = incoming
    .filter((m) => ["user", "assistant"].includes(m.role) && typeof m.content === "string")
    .slice(-20)
    .map((m) => ({ role: m.role, content: m.content.slice(0, 4000) }));

  res.writeHead(200, { "Content-Type": "text/event-stream", "Cache-Control": "no-cache" });
  try {
    const stream = await client.chat.completions.create({
      model: "uncensored",
      messages: [{ role: "system", content: SYSTEM }, ...clean],
      stream: true,
    });
    for await (const part of stream) {
      const t = part.choices[0]?.delta?.content;
      if (t) res.write(`data: ${JSON.stringify(t)}\n\n`);
    }
    res.write("data: [DONE]\n\n");
  } catch (e) {
    res.write(`event: error\ndata: ${JSON.stringify(e.status === 429 ? "busy" : "failed")}\n\n`);
  }
  res.end();
});

app.listen(3000);

Note the filter. The client can send anything, so the server keeps only user and assistant messages, truncates each, and ignores any system message the browser tries to inject. The system prompt always comes from your code.

Step 2: the browser side

The browser reads the stream with fetch and appends text as it arrives. No library is required.

const messages = [];

async function send(text, out) {
  messages.push({ role: "user", content: text });
  const res = await fetch("/api/chat", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ messages }),
  });

  const reader = res.body.getReader();
  const dec = new TextDecoder();
  let reply = "", buf = "";

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    buf += dec.decode(value, { stream: true });
    const events = buf.split("\n\n");
    buf = events.pop();
    for (const ev of events) {
      if (ev === "data: [DONE]") break;
      if (ev.startsWith("data: ")) {
        reply += JSON.parse(ev.slice(6));
        out.textContent = reply;
      }
    }
  }
  messages.push({ role: "assistant", content: reply });
}

The buffer matters. Network chunks do not align with event boundaries, so you split on the blank line and keep the unfinished tail for the next read. For a walk-through of the page itself, see the web chat tutorial, and for the wider picture of adding a bot to a site, how to implement a chatbot in a website.

Limits, errors and retries

A full key allows 8 concurrent requests and 300 per minute. A trial key allows 2 and 60. A streamed request occupies its slot until the stream ends, so with 8 slots you can serve at most 8 live replies at once. If your site has more simultaneous users than that, queue requests in your server and answer "one moment" instead of failing.

  • 429 with concurrency: too many requests are in flight. Queue and retry.
  • 429 with rate_limited: too many requests per minute. Slow down.
  • 429 with a Retry-After: 5 header: temporary overload. Wait 5 seconds and try again.
  • 401: wrong or missing key.
  • Body above 8 MB: rejected, so trim what you send.

Add a tiny in-memory counter so your own server never opens more than 8 upstream streams:

let active = 0;
const MAX = 8;

app.use("/api/chat", (req, res, next) => {
  if (active >= MAX) return res.status(503).json({ error: "busy" });
  active++;
  res.on("close", () => { active--; });
  next();
});

Register this middleware before the chat route. The close event fires when the response ends or the user leaves, so the counter does not leak.

Control the cost of each conversation

The price is $0.15 per 1M input tokens and $0.50 per 1M output tokens. Because each turn resends history, the cap on history is your biggest lever. With the last 20 messages at roughly 60 tokens each plus a 100-token system prompt, a request carries about 1,300 input tokens. A 150-token reply adds output.

Cost per turn: 1,300 / 1,000,000 x $0.15 = $0.000195, plus 150 / 1,000,000 x $0.50 = $0.000075, so $0.00027. A 30-turn session at that size costs $0.0081 at most, since early turns are shorter. Per-user daily caps, for example 100 messages, bound your worst case at 100 x $0.00027 = $0.027 per user per day. For more on pricing a site bot, read the page on chatbot on website cost, and use the docs for parameters such as max_tokens.

Who is calling your proxy

The proxy protects the key, but it also becomes a free chat endpoint for anyone who finds the URL. Decide who may use it before you ship.

For a public site, a signed session cookie set at login is the usual answer. Check it at the top of the route and return 401 when it is missing. For a quick prototype, a per-IP limit with a package such as express-rate-limit is better than nothing, though shared networks make IP limits blunt. Whatever you pick, count messages per user, not per connection, and store the count where a restart cannot reset it.

Keep conversation history on the server once the app grows. Sending the whole history from the browser on every turn is easy to build, but users can edit it. Store messages in a database under a conversation id, load the last 20 on each request, and append the reply after the stream ends. That also lets a user close the tab and come back to the same chat.

Before you launch

A short checklist keeps launch day quiet.

  1. The key lives only in an environment variable on the server, and the repository does not contain it.
  2. The server ignores any system message from the client.
  3. Each user has a message cap per day and a message length cap.
  4. Errors show a friendly message and never print internal details.
  5. You log request ids from the X-Request-Id header and token counts, not the full text.
  6. You watch X-Balance-USD and get an alert when credit runs low.
  7. Your terms state the adult-only audience, and the bot never produces sexual content involving minors.

The last point is shared with the guidance on adult chatbot safety. The model behind this API is tuned to answer without content refusals for lawful adult use, which makes your own age gating and moderation rules more important, not less. Top-ups here are crypto only (USDT on TRC20 or USDC on Base), from $20 to $500, and new users can claim a $0.50 trial first.

Questions and answers

Why can't I call the API straight from JavaScript in the browser?

Because the key would be visible to anyone who opens the network tab. A backend proxy keeps the key on your server and lets you add limits per user.

Does the API support streaming?

Yes. Set stream to true and the API sends server-sent events, with usage at the end. Your proxy can relay those events to the browser.

Which SDK should I use?

Any OpenAI SDK or HTTP client works. Change the base URL to https://api.uncensoredchatbotapi.com/v1, use your key, and set the model to uncensored.

What happens if too many users chat at once?

A full key allows 8 concurrent requests. Beyond that the API returns 429 with the code concurrency, so queue extra requests in your server and retry shortly.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API keyRead the docs