Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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. Support for an OpenAI base URL does not imply support for Responses, Assistants, audio, image generation, tool calling, or undocumented sampling extensions.