Deep Learning API for Text: Build a Chatbot Fast
A deep learning api for text lets you build a working chatbot in about fifteen minutes, because the model does the language work and you only manage messages. Below is a complete Python chatbot with history, streaming and a token budget, using an OpenAI-compatible endpoint.

Summary
- A chatbot is a loop that appends messages and resends the history each turn.
- Input cost grows with every turn, so trim or summarise old messages.
- Streaming gives usage at the end, which you can use to track spend.
- Dropping old turns cut a 50-turn chat's input tokens by about 62%.
What you need
The model is hosted, so there is nothing to train and no GPU to rent. You need Python 3.9 or newer, the OpenAI SDK (pip install openai) and a key. Sign up, claim the $0.50 trial credit on the API key page, and keep the key in an environment variable:
# endpoint https://api.deepapi.cc/v1, model uncensored
export DEEPAPI_KEY="paste-your-key-here"
The endpoint is https://api.deepapi.cc/v1 and the model ID is uncensored. It is an OpenAI-compatible, text-only API serving one open-weight model run by an independent provider, so the code is the same as for any OpenAI client. There are no embeddings, images or audio here, only text in and text out.
The core idea: the model has no memory
Each request is independent. The API does not remember what you said a minute ago. To have a conversation, you send the whole conversation every time: a system message, then alternating user and assistant messages, ending with the new user message. The reply is appended to the list, and the next turn sends the longer list.
That one fact explains most design choices in a chatbot. It is why long chats cost more per turn, why you need a plan for old messages, and why the context window matters. This service has 100,000 tokens in total for prompt plus completion.
A chatbot in 40 lines
This version streams the reply, keeps history and prints token use after each turn.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.deepapi.cc/v1",
api_key=os.environ["DEEPAPI_KEY"],
)
SYSTEM = {"role": "system", "content": "You are a friendly, concise assistant."}
history = [] # user and assistant messages only
MAX_TURNS = 10 # keep about the last 10 exchanges
def reply(user_text):
history.append({"role": "user", "content": user_text})
window = history[-MAX_TURNS * 2:]
stream = client.chat.completions.create(
model="uncensored",
messages=[SYSTEM] + window,
stream=True,
temperature=0.7,
)
text, usage = "", None
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
piece = chunk.choices[0].delta.content
print(piece, end="", flush=True)
text += piece
if getattr(chunk, "usage", None):
usage = chunk.usage
print()
history.append({"role": "assistant", "content": text})
return usage
while True:
user = input("you> ").strip()
if user in {"", "exit", "quit"}:
break
u = reply(user)
if u:
cost = u.prompt_tokens * 0.15 / 1e6 + u.completion_tokens * 0.50 / 1e6
print(f"[{u.prompt_tokens} in, {u.completion_tokens} out, ${cost:.5f}]")
Run it, chat for a few turns and watch the "in" number rise. The streamed response reports usage at the end, so the figure is exact and does not need a guess.
Token budgeting: why trimming matters
Say the system prompt is 200 tokens, and each turn adds 100 tokens from the user and 250 from the assistant. Without trimming, turn k sends 200 + 350 x (k - 1) + 100 input tokens. Over a 50-turn conversation:
- Input total: 50 x 300 + 350 x (0 + 1 + ... + 49) = 15,000 + 350 x 1,225 = 443,750 tokens
- Output total: 50 x 250 = 12,500 tokens
- Cost: 443,750 x $0.15 / 1M = $0.0666, plus 12,500 x $0.50 / 1M = $0.0063, which is about $0.073
Now keep only the last 10 exchanges. The first 10 turns cost 18,750 input tokens, and each of the remaining 40 sends 3,700, so 148,000. The total is 166,750 input tokens, about 62% fewer than before, for a cost of $0.0250 on input.
The saving matters more with longer messages or more users. A chatbot serving thousands of conversations a day sees the difference in its balance.
Better than dropping: summarise
Dropping old turns loses facts the user mentioned early, like a name or a preference. A common fix is to ask the model for a short summary when the history grows, and carry the summary instead of the old messages.
# uses the client from above (base_url https://api.deepapi.cc/v1)
def compress(history, keep=6):
if len(history) <= keep * 2:
return history
old, recent = history[:-keep * 2], history[-keep * 2:]
summary = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "Summarise this conversation in under 120 words. Keep names, facts and open questions."},
{"role": "user", "content": "\n".join(m["role"] + ": " + m["content"] for m in old)},
],
).choices[0].message.content
return [{"role": "user", "content": "Summary of earlier chat: " + summary}] + recent
Call it every so often, for example when the history passes 20 messages: history = compress(history). The summary call costs a few thousand tokens once, then every later turn is cheaper. Set a rough budget as well. A character count divided by four is a decent token estimate for English, and the usage block gives the real number after each call.
Testing the bot before real users see it
A chatbot that works for three friendly messages can still fail in production. Run through this short checklist first.
- Long answers. Ask for a 1,000-word story and confirm the stream does not stall and the full text lands in
history. - Empty and huge input. Send an empty line and a pasted wall of text. The loop above ignores empty input, but you should also cap the length of a message before it reaches the API.
- Dropped connection. Stop the network in the middle of a stream. The partial reply should not be saved as if it were complete, so append to
historyonly after the loop ends without an exception. - Memory of early facts. Tell the bot your name in turn one, then ask for it in turn fifteen. If it fails, switch from plain trimming to the summary approach.
- Cost per conversation. Run a 20-turn chat and add up the printed costs. Multiply by the number of conversations you expect a day.
Keep the system prompt short and specific. State the bot's role, the tone and any format rules in a few lines, and test changes one at a time. Every word in the system prompt is sent again on each turn, so a 200-token prompt costs about $0.00003 per request in input, which is small but adds up across thousands of requests.
Handling limits and errors
A single-user chatbot rarely hits the limits, but a deployed one will. A full key allows 8 concurrent requests and 300 per minute, a trial key 2 and 60. Past a limit the API returns HTTP 429 with the code rate_limited or concurrency. Temporary overload also returns 429 with Retry-After: 5. Because a streamed request keeps its slot until the stream ends, a web chatbot with many open streams should queue or reject new ones. Failed or refused requests are not charged, so retrying costs nothing extra.
Other useful knobs: temperature and top_p for variety, stop for custom endings, and seed for repeatable test runs. JSON mode and tool calling are available for structured replies and function use. The docs cover all of them.
Putting it on a website
The same pattern works behind a web endpoint. Keep the API key on the server, never in browser JavaScript, because anyone can read client code. The browser sends the new user message to your server, your server loads that user's history, calls the API and streams the reply back.
Three details save trouble. Store history per session so users do not see each other's chats. Cap the length of a user message before you forward it, since a pasted novel costs real money. And limit simultaneous streams per key to the concurrency of your plan: with a full key that is 8 at once, and a ninth should wait in a queue. For a small internal tool this takes a few dozen lines, and the base URL and key are the only provider-specific parts.
Where to go from here
Wrap reply in a small web server, store history per user in a database, and add a character in the system prompt. If you want to compare providers before you commit, the article on DeepSeek API alternatives lists criteria. For costs at your own scale, see the pricing page. Top-ups run from $20 to $500, in crypto only, with bonuses from $50, and the credit never expires.
More guides
FAQs
Do I need to train a model to use a deep learning API for text?
No. The model is already trained and hosted. You send messages over HTTPS and get text back.
Does the API remember previous messages?
No. Each request is independent, so your code must resend the conversation history on every turn.
How many tokens can one conversation use?
The context window is 100,000 tokens for prompt plus completion. Trim or summarise before you get near that.
Can I use this from JavaScript?
Yes. Use the OpenAI Node SDK with baseURL set to https://api.deepapi.cc/v1 and the model uncensored, or call the endpoint with fetch.
Get your API key instantly
Sign up, copy your key, update your base URL. That is all.