Runnable examples
Run a script to print a chat reply or read it as it arrives.
Set your Meikai token before running a script. The scripts use meta-llama/Llama-3.3-70B-Instruct. To use another text model, set MEIKAI_AI_MODEL to its ID from List models.
Shell chat
This script uses curl to send a request and jq to read the reply. Save it as chat.sh and run bash chat.sh "Why does bread rise?".
#!/usr/bin/env bash
# Minimal chat request. Run: MEIKAI_AI_KEY=mk-... ./chat.sh "your question"
set -euo pipefail
: "${MEIKAI_AI_KEY:?Set MEIKAI_AI_KEY first — ask your Meikai administrator for a token.}"
PROMPT="${*:-Explain DNS in two sentences.}"
curl -sS https://ai.meikai.net/v1/chat/completions \
-H "Authorization: Bearer $MEIKAI_AI_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg p "$PROMPT" --arg model "${MEIKAI_AI_MODEL:-meta-llama/Llama-3.3-70B-Instruct}" '{
model: $model,
messages: [{role: "user", content: $p}],
max_tokens: 2048,
temperature: 0.7
}')" \
| jq -r '.choices[0].message.content'Python chat
Run python3 -m pip install requests. Save the script as chat.py and run python3 chat.py "Why does bread rise?".
#!/usr/bin/env python3
"""Minimal chat request. Run: MEIKAI_AI_KEY=mk-... python3 chat.py "your question" """
import os
import sys
import requests
key = os.getenv("MEIKAI_AI_KEY")
if not key:
sys.exit("Set MEIKAI_AI_KEY first — ask your Meikai administrator for a token.")
prompt = " ".join(sys.argv[1:]) or "Explain DNS in two sentences."
response = requests.post(
"https://ai.meikai.net/v1/chat/completions",
headers={"Authorization": f"Bearer {key}"},
json={
"model": os.getenv("MEIKAI_AI_MODEL", "meta-llama/Llama-3.3-70B-Instruct"),
"messages": [{"role": "user", "content": prompt}],
# Reasoning models can use part of this budget before answering.
"max_tokens": 2048,
"temperature": 0.7,
},
timeout=120,
)
response.raise_for_status()
choice = response.json()["choices"][0]
print(choice["message"]["content"])
print(f"\n[{choice['finish_reason']}] {response.json()['usage']}", file=sys.stderr)Python streaming chat
Run python3 -m pip install openai. Save the script as stream.py and run python3 stream.py "Write a haiku about bread". You’ll see the reply as the model writes it.
#!/usr/bin/env python3
"""Streaming chat via the OpenAI SDK. Run: pip install openai && python3 stream.py "..." """
import os
import sys
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MEIKAI_AI_KEY"],
base_url="https://ai.meikai.net/v1",
)
stream = client.chat.completions.create(
model=os.getenv("MEIKAI_AI_MODEL", "meta-llama/Llama-3.3-70B-Instruct"),
messages=[{"role": "user", "content": " ".join(sys.argv[1:]) or "Write a haiku about DNS."}],
max_tokens=2048,
stream=True,
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="", flush=True)
print()