Skip to main content

Build a Chatbot

Build a streaming chatbot using the AINative Chat Completions API.

Prerequisites

Python

import requests

API_KEY = "your-api-key"
BASE = "https://api.ainative.studio/api/v1/public"
HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}

messages = [{"role": "system", "content": "You are a helpful assistant."}]

while True:
user_input = input("You: ")
if user_input.lower() in ("quit", "exit"):
break

messages.append({"role": "user", "content": user_input})

response = requests.post(f"{BASE}/chat/completions", headers=HEADERS, json={
"model": "meta-llama/llama-3.3-70b-instruct",
"messages": messages,
})

assistant_message = response.json()["choices"][0]["message"]["content"]
messages.append({"role": "assistant", "content": assistant_message})
print(f"Assistant: {assistant_message}")

curl

curl -X POST https://api.ainative.studio/api/v1/public/chat/completions \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "meta-llama/llama-3.3-70b-instruct",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is ZeroDB?"}
]
}'

What to Try Next