curl
BASE=https://mirobody-api.thetahealth.ai/v1
KEY="mb_live_..."
# 1) Grounded answer (Answers API)
curl $BASE/chat/completions \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{"model":"mirobody-flash","messages":[{"role":"user","content":"How is my fasting glucose trending?"}],"user":"alice"}'
# 2) Write a record (retention is REQUIRED), then ask again
curl $BASE/data \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{"user":"alice","retention":"permanent","records":[{"indicator":"fasting_glucose","value":5.4,"unit":"mmol/L","time":"2026-06-16T07:30:00Z"}]}'
# 3) Upload a report (OCR/parse), then ask about it
curl $BASE/files -H "Authorization: Bearer $KEY" -F "user=alice" -F "file=@report.pdf"
# 4) Agent API (Responses)
curl $BASE/responses \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{"model":"mirobody-flash","input":"How is my fasting glucose trending?","user":"alice"}'
Python (OpenAI SDK)
from openai import OpenAI
client = OpenAI(api_key="mb_live_...", base_url="https://mirobody-api.thetahealth.ai/v1")
# Answers API — non-streaming
resp = client.chat.completions.create(
model="mirobody-flash",
messages=[{"role": "user", "content": "How is my fasting glucose trending?"}],
user="alice",
)
print(resp.choices[0].message.content)
# Answers API — streaming
stream = client.chat.completions.create(
model="mirobody-flash",
messages=[{"role": "user", "content": "Summarize my last checkup."}],
user="alice",
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta
if getattr(delta, "content", None):
print(delta.content, end="", flush=True)
# Agent API (Responses) — stored by default, chainable
r1 = client.responses.create(model="mirobody-flash",
input="How is my fasting glucose trending?", user="alice")
print(r1.output_text)
r2 = client.responses.create(model="mirobody-flash",
input="And compared with last quarter?",
previous_response_id=r1.id, user="alice")
print(r2.output_text)
# File upload uses multipart, so call the REST endpoint directly
import requests
up = requests.post(
"https://mirobody-api.thetahealth.ai/v1/files",
headers={"Authorization": "Bearer mb_live_..."},
data={"user": "alice"},
files={"file": open("report.pdf", "rb")},
)
print(up.json()) # {"object": "file", "id": "...", "filename": "report.pdf",
# "bytes": 20544, "status": "processed", "created_at": 1782924296,
# "subject": "alice"}
openai-agents SDK (your tools + Mirobody’s agent)
The openai-agents SDK works against the Agent API by changing only the base URL:from agents import Agent, ModelSettings, Runner, function_tool, set_default_openai_client, set_tracing_disabled
from openai import AsyncOpenAI
set_default_openai_client(AsyncOpenAI(
base_url="https://mirobody-api.thetahealth.ai/v1", api_key="mb_live_..."))
set_tracing_disabled(True) # tracing would call api.openai.com
@function_tool
def book_appointment(date: str) -> str:
"""Book a clinic appointment for the end user (ISO date)."""
return f"Booked: {date} 09:30, Dr. Chen"
agent = Agent(name="Health assistant", model="mirobody-flash", tools=[book_appointment],
model_settings=ModelSettings(extra_body={"user": "alice"}))
result = Runner.run_sync(agent, "Check my recent glucose and book a follow-up if it's trending up.")
print(result.final_output)
Node.js (OpenAI SDK)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.MIROBODY_API_KEY,
baseURL: "https://mirobody-api.thetahealth.ai/v1",
});
// Answers API — non-streaming
const resp = await client.chat.completions.create({
model: "mirobody-flash",
messages: [{ role: "user", content: "How is my fasting glucose trending?" }],
user: "alice",
});
console.log(resp.choices[0].message.content);
// Answers API — streaming
const stream = await client.chat.completions.create({
model: "mirobody-flash",
messages: [{ role: "user", content: "Summarize my last checkup." }],
user: "alice",
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
// Agent API (Responses)
const r = await client.responses.create({
model: "mirobody-flash",
input: "How is my fasting glucose trending?",
user: "alice",
});
console.log(r.output_text);