curl
BASE=https://mirobody-api.thetahealth.ai/v1
KEY="mb_live_..."
# 1) grounded 回答(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) 写入一条记录(retention 必填),再问一次
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) 上传报告(OCR/解析),再就它提问
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 —— 非流式
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 —— 流式
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)—— 默认即存储、可链式续聊
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)
# 文件上传是 multipart,直接调 REST 端点
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(你的工具 + Mirobody 的智能体)
openai-agents SDK 只需改 base URL 即可对接 Agent API: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 会请求 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 —— 非流式
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 —— 流式
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);