NewJobs: scheduled actions created from chat, personal or shared.Learn more
Guides

OpenAI SDKs

Python and JavaScript examples, including agent mode and the memtro options.

Open Memtro

Any OpenAI SDK works unchanged: set the base URL and your Memtro key. The examples below show the memtro options too.

Python

from openai import OpenAI

client = OpenAI(base_url="https://platform.memtro.com/v1", api_key="sk-memtro-...")

# A quick question, routed by difficulty
r = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "Who owns the billing migration?"}],
)
print(r.choices[0].message.content)

# A full investigation in agent mode, streamed with progress
stream = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "Have a look at Help Scout ticket #2450"}],
    stream=True,
    extra_body={"memtro": {"mode": "agent", "memory": "org"}},
)
for chunk in stream:
    delta = chunk.choices[0].delta if chunk.choices else None
    if delta is None:
        continue
    progress = getattr(delta, "reasoning_content", None)
    if progress:
        print("[working]", progress, end="")
    if delta.content:
        print(delta.content, end="")

JavaScript / TypeScript

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://platform.memtro.com/v1", apiKey: process.env.MEMTRO_API_KEY });

const stream = await client.chat.completions.create({
  model: "auto:agent",
  messages: [{ role: "user", content: "Summarise open VIP tickets older than a day" }],
  stream: true,
  // @ts-expect-error Memtro extension
  memtro: { memory: "org", show_progress: true },
});

for await (const chunk of stream) {
  const delta = chunk.choices[0]?.delta as { content?: string; reasoning_content?: string } | undefined;
  if (delta?.reasoning_content) process.stderr.write(delta.reasoning_content);
  if (delta?.content) process.stdout.write(delta.content);
}

Reading the Memtro fields

Non-streaming responses carry memtro next to choices:

r = client.chat.completions.create(model="auto", messages=[...])
extra = r.model_extra.get("memtro", {})
print(extra.get("routing"), extra.get("tools"))

Client-declared tools

Pass tools the OpenAI way and execute the returned tool_calls yourself. Memtro's own tools still run server-side in the same request. Client tools are not available with claude-code/* models.

Embeddings

client.embeddings.create(model="openai/text-embedding-3-small", input=["billing migration"])

Uses your OpenAI or Google key. model="memtro" picks the default embedding model.