OpenAI SDK clients
MiRMiR can be used by clients that allow an OpenAI-compatible base URL. Load a
model, run mirmir serve, and point the client at http://127.0.0.1:8080/v1.
Python
from openai import OpenAI
client = OpenAI(
base_url="http://127.0.0.1:8080/v1",
api_key="local-dev",
)
stream = client.chat.completions.create(
model="qwen",
messages=[{"role": "user", "content": "Hello"}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta
if delta.content:
print(delta.content, end="", flush=True)
When MiRMiR has no API key on loopback, the SDK still requires a non-empty
placeholder api_key locally.
JavaScript and TypeScript
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "http://127.0.0.1:8080/v1",
apiKey: "local-dev",
});
const result = await client.chat.completions.create({
model: "qwen",
messages: [{ role: "user", content: "Hello" }],
});
console.log(result.choices[0].message.content);
Browser applications additionally need an exact server.cors_origins entry.
Do not embed a remote-access API key into publicly shipped frontend code.
Compatibility boundary
Use only the endpoints and fields documented in this book. Function tool
calling through tools and tool_choice is supported for chat completions;
see Tool calling. Support for an OpenAI base URL
does not imply support for Responses, Assistants, audio, image generation,
structured response_format output, or undocumented sampling extensions.
Clients that send non-zero presence_penalty or frequency_penalty, or a
reasoning_effort, receive 400 and must omit those fields.