EmbeddingApis/Guide
Uncensored text API for your pipeline
Build an LLM Based Chat Bot With an OpenAI-Style API
An LLM based chat bot is a loop: take the user's message, add it to a stored history, send that history to a model and post the reply. This guide builds that loop in Python, then wraps it for Discord and covers limits and cost.
Updated
Key points
The model is stateless, so your bot must store and resend history.
Use model uncensored with the OpenAI SDK and the site's base URL.
Cap concurrency at 8 and queue the rest to avoid 429 errors.
A typical chat turn costs a fraction of a cent.

What the bot has to do
The API remembers nothing between calls. Every request must contain the whole conversation you want the model to see. So the work of a chat bot is mostly bookkeeping: keep a list of messages per user or channel, add the new message, send the list, store the answer and repeat.
This service is an OpenAI-compatible, text-only API. It runs one open-weight model, operated by an independent provider and tuned to answer without content refusals for lawful adult use. There is no image, audio or embeddings endpoint, despite what the domain name might suggest, so everything below is about chat completions. Sexual content involving minors is not allowed.
The core loop in Python
Install the SDK with pip install openai, export your key as API_KEY, and start with a console version. If you do not have a key yet, the API key page offers $0.50 of trial credit on sign-up.
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.embeddingapis.com/v1", api_key=os.environ["API_KEY"])
SYSTEM = "You are Mira, a friendly assistant for a game community. Keep answers short."
history = [{"role": "system", "content": SYSTEM}]
def reply(user_text: str) -> str:
history.append({"role": "user", "content": user_text})
resp = client.chat.completions.create(
model="uncensored",
messages=history,
temperature=0.8,
max_tokens=400,
)
text = resp.choices[0].message.content
history.append({"role": "assistant", "content": text})
return text
while True:
print(reply(input("you> ")))
That is a working bot. Everything else in this article makes it safe to run for many people at once.
Write a system prompt that holds
The system message is where the bot gets its name, tone and boundaries. A few habits make it hold up over long chats:
- State the role and the audience in one or two sentences.
- Give format rules: length, language, whether to use lists.
- List what the bot should do when it does not know something, for example ask a question.
- Put lasting facts, such as server rules or product details, in the system message and not in the chat turns.
For fiction, roleplay and companion bots for adults, add the setting and the character's voice here, and say that the character stays in role unless the user steps out of it. Test the prompt with ten or fifteen awkward messages before you publish the bot.
Keep one history per conversation
A global list like the one above would mix every user together. Store a separate history per Discord channel, Telegram chat ID or web session. A dictionary works for a prototype; use a database when the bot must survive restarts.
Context is large: 100,000 tokens covering prompt and reply together. Even so, do not send everything forever. Long histories cost more on every turn and slow the answer. A simple policy is to keep the system message plus the last 20 messages:
histories = {}
def trim(msgs, keep=20):
return [msgs[0]] + msgs[1:][-keep:]
def reply_for(chat_id, user_text):
msgs = histories.setdefault(chat_id, [{"role": "system", "content": SYSTEM}])
msgs.append({"role": "user", "content": user_text})
msgs[:] = trim(msgs)
resp = client.chat.completions.create(model="uncensored", messages=msgs)
text = resp.choices[0].message.content
msgs.append({"role": "assistant", "content": text})
return text
For bots that need long memory, such as companions, summarize older messages into a short note every so often and keep the note near the top of the history.
A Discord version
With the discord.py library, the bot answers when it is mentioned. Calls to the API are blocking, so run them in a thread to keep the Discord connection alive.
import asyncio, os
import discord
from openai import OpenAI
client = OpenAI(base_url="https://api.embeddingapis.com/v1", api_key=os.environ["API_KEY"])
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Client(intents=intents)
slots = asyncio.Semaphore(8)
histories = {}
SYSTEM = "You are Mira, a friendly assistant. Keep answers under 120 words."
def ask(chat_id, text):
msgs = histories.setdefault(chat_id, [{"role": "system", "content": SYSTEM}])
msgs.append({"role": "user", "content": text})
msgs[:] = [msgs[0]] + msgs[1:][-20:]
r = client.chat.completions.create(model="uncensored", messages=msgs, max_tokens=300)
out = r.choices[0].message.content
msgs.append({"role": "assistant", "content": out})
return out
@bot.event
async def on_message(message):
if message.author.bot or bot.user not in message.mentions:
return
async with slots:
async with message.channel.typing():
text = await asyncio.to_thread(ask, message.channel.id, message.clean_content)
await message.reply(text[:1900])
bot.run(os.environ["DISCORD_TOKEN"])
The same ask function plugs into a Telegram bot (python-telegram-bot) or a small web endpoint without changes. Only the part that receives and sends messages differs.
Limits, streaming and errors
A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 and 60. The semaphore in the Discord example keeps you under the concurrency cap by making extra messages wait. If you still see HTTP 429, read the error code: rate_limited means too many per minute, concurrency means too many at once, and a Retry-After: 5 header means temporary overload. Wait 5 seconds and try again.
For a web chat window, set stream to true and send tokens to the browser as they arrive, so users see text appear instead of waiting. A stream holds a concurrency slot until it ends, so close it when the visitor leaves. Failed or refused requests are not charged, and each response includes X-Balance-USD, which you can use to warn yourself before credit runs out.
Rules for your community
An uncensored model answers more openly than most hosted assistants, so decide what your own bot should do. The model is meant for lawful adult use, and sexual content involving minors is a hard limit of the service. If your bot runs on a public Discord server or in a Telegram group, add the following yourself:
- An age gate or a restriction to channels marked for adults when the bot is configured for mature fiction.
- A line in the system prompt that sets the topics and tone allowed in that space.
- A short command, such as
/reset, that clears the stored history so users can start over. - Basic per-user rate limiting, for example one request every few seconds, so one person cannot use all 8 concurrency slots.
Platform rules from Discord, Telegram or your web host still apply to the bot. Read them before you invite it into a server.
Run it for real
A prototype on your laptop becomes a service when it survives restarts and tells you when something breaks. A reasonable checklist:
- Keep the key in an environment variable or a secret store, never in the repository.
- Persist histories in SQLite or Redis, keyed by chat ID, and drop ones that are idle for days.
- Log
X-Request-Idand the HTTP status for every call so you can trace odd replies. - Read
X-Balance-USDfrom the response headers and alert yourself when the balance falls below a level you choose. - Set a timeout on the client, for example 60 seconds, and send a short apology message if it fires.
client = OpenAI(base_url="https://api.embeddingapis.com/v1", api_key=os.environ["API_KEY"], timeout=60, max_retries=2)
Tune two settings first when replies feel off. Lower temperature toward 0.5 for factual helpers, and raise it toward 1.0 for creative characters. Use stop sequences if the model tends to write the user's next line, and a small frequency_penalty if it repeats itself.
What a chat costs
Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens. Take a bot that handles 1,000 turns a day, where each turn sends about 2,000 input tokens (system prompt plus history) and returns about 300 tokens.
- Input: 1,000 × 2,000 = 2,000,000 tokens, which is 2 × $0.15 = $0.30.
- Output: 1,000 × 300 = 300,000 tokens, which is 0.3 × $0.50 = $0.15.
- Total: $0.45 per day for 1,000 turns.
Trimming history is the main lever, since input tokens dominate. Credit is prepaid, never expires and there is no subscription. Top up with any whole amount from $20 to $500, by crypto (USDT on TRC20, USDC on Base), with +5% bonus from $50, +10% from $100 and +15% from $200. See the pricing page for details and the docs for the full parameter list. Prompts are not used for training.
More guides
Questions and answers
Do I need a special library to build an LLM based chat bot with this API?
No. The official OpenAI SDKs work after you set the base URL and key. Use the model ID uncensored.
Does the API remember earlier messages?
No. You must send the conversation history with each request. Store it per chat and trim it as it grows.
How many users can the bot serve at once?
A full key allows 8 concurrent requests and 300 per minute. Queue extra messages so your bot stays within those limits.
Can I pay by card?
Yes. Top-ups accept crypto (USDT on TRC20, USDC on Base), from $20 to $500. Card payments are no longer accepted.
Can the same bot also create embeddings or images?
No. The service is text only, with no embeddings, image, audio or video endpoints.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.