How to build an AI chatbot with Vikasit AI
A chatbot is the simplest way to ship value with an LLM: take user messages, keep conversation history, and stream replies back. Because the Vikasit API is OpenAI-compatible, you can build one in a few lines and swap models without rewriting code.
Recommended model
Vikasit 3
A balanced generalist with low per-token cost — ideal for general conversation. Drop down to Vikasit 3 Flash for snappier, cheaper turns, or Vikasit 3 Max for harder questions.
Steps
- 1
Create a Vikasit API key at vikasit.ai/auth and set it as the VIKASIT_API_KEY environment variable.
- 2
Install the OpenAI SDK (pip install openai) and point its base_url at https://api.vikasit.ai/v1.
- 3
Maintain a messages list, starting with a system prompt that defines the assistant's persona.
- 4
On each user turn, append the user message, call chat.completions.create, and append the assistant reply.
- 5
Enable streaming (stream=True) so tokens appear as they are generated for a responsive feel.
- 6
Trim or summarize old history once the conversation grows to keep token costs down.
Code
The Vikasit Inference API is OpenAI-compatible, so this uses the standard OpenAI Python SDK pointed at https://api.vikasit.ai/v1.
from openai import OpenAI
client = OpenAI(
base_url="https://api.vikasit.ai/v1",
api_key="sk-vikasit-...", # get one at vikasit.ai/auth
)
messages = [
{"role": "system", "content": "You are a helpful assistant."},
]
while True:
user = input("You: ")
if not user:
break
messages.append({"role": "user", "content": user})
stream = client.chat.completions.create(
model="vikasit-3",
messages=messages,
stream=True,
)
reply = ""
print("Bot: ", end="", flush=True)
for chunk in stream:
delta = chunk.choices[0].delta.content or ""
print(delta, end="", flush=True)
reply += delta
print()
messages.append({"role": "assistant", "content": reply})Build your AI chatbot today
Get an API key and 2M free tokens a day on Vikasit Nova. Pay-as-you-go, no minimums, OpenAI-compatible.