Which framework fits which job
When people search for text based chatbots frameworks, they usually mean one of two things: a library that manages prompts, memory and tools around a language model, or a ready-made bot platform with its own interface. This page covers the first kind, because those are the ones where you choose the model endpoint yourself. The platform kind is covered at the end.
The reason this works at all is that this service speaks the OpenAI chat completions protocol. The endpoints are POST /v1/chat/completions and GET /v1/models, authentication is a bearer token, and the single model ID is uncensored. A framework that lets you override the OpenAI base URL needs nothing else.
| Framework | Language | Best for | Class to use |
|---|---|---|---|
| Plain OpenAI SDK | Python, Node | Small bots, full control | OpenAI |
| LangChain | Python, JS | Chains, memory, tool agents | ChatOpenAI |
| LlamaIndex | Python | Bots that answer from your documents | OpenAILike |
| Vercel AI SDK | TypeScript | Web chat UIs with streaming | createOpenAI |
If you only need a chat loop, skip the framework. The plain SDK is about ten lines and has nothing to break when a library updates. Reach for LangChain or LlamaIndex when you want retrieval, structured pipelines or agents with several tools.
What you need before you start
You need an API key and a funded balance. New users can claim $0.50 of trial credit with one click on the key page after sign-up, valid for 7 days and with no payment details needed. A trial key allows 2 concurrent requests and 60 requests per minute, which is enough to test every snippet below. A full key allows 8 concurrent requests and 300 per minute. You can get a key on the key page, and the quickstart lists every supported parameter.
Store the key in an environment variable named API_KEY so it never lands in source control. Every example below reads it from there.
One boundary to remember: this is a text engine. It does not generate audio, images or video, and it does not produce embeddings. If your bot needs a voice, you pass the reply text to a speech engine of your own. If your retrieval step needs embeddings, you get them elsewhere. Only the chat completion call goes here.
The baseline: plain OpenAI SDK
Start here so you know the connection works before adding layers. A bot is just a list of messages that you keep appending to.
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.nsfwtts.top/v1", api_key=os.environ["API_KEY"])
history = [{"role": "system", "content": "You are Mara, a dry-witted storyteller. Keep replies under 80 words."}]
while True:
user = input("you> ")
history.append({"role": "user", "content": user})
resp = client.chat.completions.create(
model="uncensored",
messages=history,
temperature=0.9,
max_tokens=200,
)
reply = resp.choices[0].message.content
history.append({"role": "assistant", "content": reply})
print("bot>", reply)
Everything a framework adds, such as memory, templates and tools, is a layer on top of this list-of-messages loop. Keeping that in mind makes debugging much easier.
LangChain
LangChain's ChatOpenAI class accepts a base_url, which is all the change needed. Install langchain-openai and pass the three values.
import os
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
llm = ChatOpenAI(
model="uncensored",
base_url="https://api.nsfwtts.top/v1",
api_key=os.environ["API_KEY"],
temperature=0.8,
)
prompt = ChatPromptTemplate.from_messages([
("system", "You write short scene narration for a noir audio drama."),
("human", "{topic}"),
])
chain = prompt | llm | StrOutputParser()
print(chain.invoke({"topic": "A rainy street, a missed train."}))
for piece in chain.stream({"topic": "The detective finds an empty office."}):
print(piece, end="", flush=True)
Streaming works through chain.stream because the API supports SSE with stream: true. For tool agents, bind your tools to the model; the API accepts tools and tool_choice and returns streamed tool_calls, and tool results go back as messages with the role tool. Keep the number of tools small, since each definition is sent as input tokens on every call.
Memory in LangChain is just stored history. Whatever store you pick, the full message list still travels with each request, so token use grows as the chat grows. Trim or summarize older turns once a session gets long.
LlamaIndex and the Vercel AI SDK
LlamaIndex has a dedicated class for OpenAI-compatible servers, OpenAILike, from the llama-index-llms-openai-like package. The important flag is is_chat_model=True, because otherwise it may call the older completions route.
import os
from llama_index.llms.openai_like import OpenAILike
from llama_index.core.llms import ChatMessage
llm = OpenAILike(
model="uncensored",
api_base="https://api.nsfwtts.top/v1",
api_key=os.environ["API_KEY"],
is_chat_model=True,
)
reply = llm.chat([
ChatMessage(role="system", content="Answer in plain, spoken-style sentences."),
ChatMessage(role="user", content="Describe a lighthouse at dusk."),
])
print(reply.message.content)
For a TypeScript web app, the Vercel AI SDK can point its OpenAI provider at a custom URL. Package versions change the details, so check the SDK's own documentation if a name differs in your version.
import { createOpenAI } from "@ai-sdk/openai";
import { streamText } from "ai";
const provider = createOpenAI({
baseURL: "https://api.nsfwtts.top/v1",
apiKey: process.env.API_KEY,
});
const result = streamText({
model: provider.chat("uncensored"),
system: "You are a calm narrator. Short sentences.",
prompt: "Open a story set on a night ferry.",
});
for await (const part of result.textStream) {
process.stdout.write(part);
}
Using provider.chat rather than the default call matters: it selects the chat completions route that this API implements.
Feeding a voice pipeline
This site is aimed at voice workflows, so it is worth showing the handoff. A speech engine sounds natural when it receives complete sentences, not half-words. Stream the model output, collect it in a buffer, and flush each time a sentence ends. Then queue that sentence for synthesis while the model keeps writing.
import os, re
from openai import OpenAI
client = OpenAI(base_url="https://api.nsfwtts.top/v1", api_key=os.environ["API_KEY"])
def speak(sentence):
# hand the sentence to your own speech engine here
print("SPEAK:", sentence)
buf = ""
stream = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "Write for the ear. No lists, no markdown, short sentences."},
{"role": "user", "content": "Tell me about the last tram of the night."},
],
stream=True,
)
for chunk in stream:
if not chunk.choices:
continue
buf += chunk.choices[0].delta.content or ""
parts = re.split(r"(?<=[.?\x21])\s+", buf)
for s in parts[:-1]:
speak(s)
buf = parts[-1]
if buf.strip():
speak(buf)
Tell the model in the system prompt to write for the ear: no markdown, no bullet lists, no parenthetical asides. Those habits look fine on screen and sound strange when read out loud. More ideas for this kind of project are in the TTS checklist.
Generation settings that suit chat bots
Frameworks tend to hide sampling settings in a config object, so it helps to know which ones change a bot's personality. All of the following are passed through by the API, so setting them in LangChain, LlamaIndex or the plain SDK has the same effect.
- temperature. Around 0.7 to 1.0 suits storytelling and character chat. Drop it toward 0.2 when you want the same answer for the same input, such as in a test suite.
- top_p. Change this or temperature, not both at once. Changing two knobs makes it hard to tell which one fixed a problem.
- Frequency and presence penalties. Raise them a little if a character keeps repeating the same phrase every turn.
- seed. Useful when you replay a conversation to debug a regression; combine it with a low temperature.
- stop. Add a stop sequence such as a speaker label if the model starts writing the user's next line for them.
- response_format. JSON mode, set with
{"type":"json_object"}, helps when the bot must return structured fields, for example a reply plus an emotion tag that your speech engine reads. Mention the word JSON and describe the keys in the prompt as well.
Persona consistency mostly comes from the system message. Put the character's voice, the format rules and the length cap there, and repeat nothing in later turns. A short, specific system message beats a long one because it is paid for on every call and because long instructions get diluted by a growing chat history.
Limits, errors and cost control
Frameworks like to parallelize. A LangChain batch call or an agent that fans out tool calls can easily send more than 8 requests at once. The API answers over-limit traffic with HTTP 429. The error code concurrency means too many requests at once, and rate_limited means too many per minute. A temporary overload also returns 429, with a Retry-After: 5 header. Note that a streamed request keeps its slot until the stream ends, so slow voice playback that stalls stream reading will hold a slot longer than you expect.
import asyncio, os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="uncensored", base_url="https://api.nsfwtts.top/v1",
api_key=os.environ["API_KEY"], max_retries=3)
gate = asyncio.Semaphore(8)
async def ask(q):
async with gate:
return (await llm.ainvoke(q)).content
async def main():
qs = [f"One-line caption for scene {i}" for i in range(40)]
out = await asyncio.gather(*(ask(q) for q in qs))
print(len(out))
asyncio.run(main())
The semaphore keeps you inside the concurrency limit, and the client's built-in retries cover a transient 429. For the cost side, input is $0.15 per 1M tokens and output is $0.50 per 1M. A 1,000-token prompt with a 150-token reply costs $0.00015 + $0.000075 = $0.000225. The pricing page has the full table and the top-up bonuses.
The content rule applies as it does elsewhere: the model is tuned to answer without content refusals for lawful adult use, and sexual content involving minors is never allowed.
When a bot platform is the better choice
If you do not want to write code, a hosted bot builder or a self-hosted chat interface may suit you better. Many of them have a field for an OpenAI-compatible endpoint, and you can put the same base URL, key and uncensored model ID there. Check each tool's own documentation for where the field lives. If you need voice, images or embeddings out of the box, pick a platform that bundles them, and use this API only for the text step.
