Decide what the bot is allowed to do
Before any code, write a one-page scope. List the questions the bot may answer (order status, opening hours, how to reset a password), the ones it must pass to a person (refunds above a limit, legal complaints, anything involving safety) and the things it must never do (invent policies, promise outcomes, give medical or legal advice).
This scope becomes your system prompt and your test set. A support bot that tries to answer everything will, sooner or later, state something false with confidence. A narrow bot with a quick handoff is better for customers and for you.
Also decide whether the model is the right one. This API serves a single open-weight model tuned to answer without content refusals for lawful adult use. That is a feature for fiction and adult-oriented products. For a typical company help desk it is closer to a risk, and the last section covers that in detail.
The core call: prompt plus your own facts
The simplest reliable design is retrieval by hand. You keep help articles in your database, find the two or three that match the customer's question, and paste them into the prompt. The model then answers from that text only.
from openai import OpenAI
client = OpenAI(
base_url="https://api.apertusaichat.com/v1",
api_key="YOUR_API_KEY",
)
SYSTEM = """You are the support assistant for Northwind Outdoor.
Answer only from the HELP TEXT below. If the text does not contain the answer,
say you are not sure and offer to connect the customer with a person.
Keep replies under 120 words. Never invent prices, dates or policies."""
def answer(question, help_text, history):
messages = [{"role": "system", "content": SYSTEM + "\n\nHELP TEXT:\n" + help_text}]
messages += history[-6:]
messages.append({"role": "user", "content": question})
r = client.chat.completions.create(
model="uncensored",
messages=messages,
temperature=0.2,
max_tokens=250,
)
return r.choices[0].message.content
Two settings matter here. A low temperature (0.2) reduces creative drift, which you do not want in support. And history[-6:] keeps only the last six messages, so input cost stays flat however long the chat runs.
Route intent with JSON mode
Do not make one prompt do everything. A cheap first call can classify the message, and your code then decides what to do. JSON mode makes the reply machine-readable.
import json
# uses the client created above (base_url https://api.apertusaichat.com/v1, model uncensored)
def classify(message):
r = client.chat.completions.create(
model="uncensored",
response_format={"type": "json_object"},
temperature=0,
messages=[
{"role": "system", "content": 'Return JSON with keys "intent" (one of order_status, returns, billing, other) and "angry" (true or false).'},
{"role": "user", "content": message},
],
max_tokens=60,
)
return json.loads(r.choices[0].message.content)
Use the result to pick which help articles to load, to skip the model entirely for fixed answers, or to jump straight to a person when angry is true. Always wrap json.loads in a try block, because a model can still return malformed output on rare occasions.
Hand off to a human with a tool call
The API supports tool calling, so you can give the model an explicit way to escalate instead of hoping it writes a polite refusal. Define a function, let the model call it, and let your code do the real work.
# same client: base_url https://api.apertusaichat.com/v1, model uncensored
tools = [{
"type": "function",
"function": {
"name": "handoff_to_human",
"description": "Transfer the chat to a support agent when you cannot answer from the help text, or the customer asks for a person.",
"parameters": {
"type": "object",
"properties": {"reason": {"type": "string"}},
"required": ["reason"],
},
},
}]
r = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": SYSTEM},
{"role": "user", "content": "I was charged twice and I want a person to look at it."},
],
tools=tools,
tool_choice="auto",
max_tokens=200,
)
msg = r.choices[0].message
if msg.tool_calls:
print("Escalate:", msg.tool_calls[0].function.arguments)
else:
print(msg.content)
When a tool call arrives, create the ticket, tell the customer a person will reply, and stop the bot from answering that thread. Also hand off by rule: after two failed answers in a row, or when the customer types "agent", skip the model altogether.
What it costs
Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens. A support message with the system prompt, two help articles and a short history might send 3,000 input tokens and receive a 300-token reply. Input costs 3,000 x $0.15 / 1M = $0.00045. Output costs 300 x $0.50 / 1M = $0.00015. That is $0.0006 per reply.
Ten thousand replies cost $6.00. Add a classification call of 200 input and 40 output tokens ($0.00003 plus $0.00002, so $0.00005) and ten thousand conversations still cost $6.50. Failed or refused requests are not charged. See the pricing page for top-up tiers and bonuses.
Plan for the limits as well: a full key allows 8 concurrent requests and 300 per minute. A busy desk should queue requests and retry on HTTP 429 after the Retry-After: 5 delay. A streamed reply holds its slot until it finishes.
When an uncensored model is the wrong choice
Be straight about this. A model that is tuned to avoid content refusals is built for freedom, not for brand safety. In a public support chat, a customer can steer the conversation anywhere, and you want the bot to decline off-topic or abusive requests. A model with strong built-in restraint does some of that work for you. This one does less, so the whole job falls on your system prompt and your filters.
It makes sense when the support product itself is adult-oriented, for example a companion or fiction platform where members ask about their account in the same chat as their stories. It also makes sense for internal tools, where the audience is your own staff. For a general retail or banking desk, a conventional assistant with built-in policies is the safer default.
If you do use it, add guardrails in code: restrict the topics in the system prompt, reject long off-topic exchanges, log conversations for review and keep the human handoff one message away. The hard limit on sexual content involving minors applies in every case. A fuller list of release checks is in the uncensored AI chat production checklist.
Keep answers consistent as your help text grows
The prompt above works while the help text is short. Once you have hundreds of articles, sending all of them is wasteful and confuses the model. Keep each help article small, one topic per entry, and store a title and a few keywords with it. Pick the best two or three for each question with a simple keyword or search match, and send only those.
Date your help articles and remove the old ones. A bot that quotes last year's returns policy is worse than a bot that says it is not sure. When a customer reports a wrong answer, find which article the bot read, fix that article, and add the question to your test set so the mistake cannot come back unnoticed.
Finally, keep a plain log of each reply with the article titles that were sent along with it. When someone complains, you can then see in a minute whether the fault was the model, the retrieval step or the help text itself.
Test before launch
Build a set of fifty real customer messages, including angry ones, vague ones and ones the bot should not answer. Run them all, read the replies and count how often the bot invents something. Fix the prompt, then rerun the whole set.
You can try this end to end for free: the API key page lets new users claim $0.50 of trial credit with one click. At $0.0006 per reply that is more than 800 test replies. Trial keys allow 2 concurrent requests, so run the test set in a simple loop. Request details are in the docs.
