Regions & Integration
SDK Examples
End-to-end /v1 examples in curl / Python / Node.js — Answers, Agent (Responses), data, files.
Minimal end-to-end examples against the hosted API.
BASE=https://api.mirobody.ai/v1KEY="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 againcurl $BASE/data \ -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \ -d '{"user":"alice","retention":"permanent","records":[{"indicator":"fasting_glucose","value":97,"unit":"mg/dL","time":"2026-06-16T07:30:00Z"}]}'
# 3) Upload a report. The original is stored immediately; its extracted text follows shortly after.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)
Section titled “Python (OpenAI SDK)”from openai import OpenAI
client = OpenAI(api_key="mb_live_...", base_url="https://api.mirobody.ai/v1")
# Answers API — non-streamingresp = 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 — streamingstream = 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, chainabler1 = 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.# status="processed" means the original was accepted, not that text extraction is finished.import requests
up = requests.post( "https://api.mirobody.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)
Section titled “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_disabledfrom openai import AsyncOpenAI
set_default_openai_client(AsyncOpenAI( base_url="https://api.mirobody.ai/v1", api_key="mb_live_..."))set_tracing_disabled(True) # tracing would call api.openai.com
@function_tooldef 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)See Function calling for the underlying handoff protocol.
Node.js (OpenAI SDK)
Section titled “Node.js (OpenAI SDK)”import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.MIROBODY_API_KEY, baseURL: "https://api.mirobody.ai/v1",});
// Answers API — non-streamingconst 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 — streamingconst 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);More: Answers API · Agent API · Data · Files · Standardize.