- Developer home
- AI API
- Use the official SDKs
Use the official SDKs
The Anthropic and OpenAI SDKs in Python and TypeScript, pointed at this site's base URL, with streaming.
Anthropic SDK
Set base_url (baseURL) to https://mroffice.ai/api/ai; the SDK adds /v1/messages itself.
# pip install anthropic
import os
from anthropic import Anthropic
client = Anthropic(base_url="https://mroffice.ai/api/ai", api_key=os.environ["MR_API_KEY"])
message = client.messages.create(
model="claude-sonnet-5.5",
max_tokens=512,
messages=[{"role": "user", "content": "Write one sentence about the sea."}],
)
print(message.content[0].text)
# streaming
with client.messages.stream(
model="claude-sonnet-5.5",
max_tokens=512,
messages=[{"role": "user", "content": "Count to five."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)// npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ baseURL: "https://mroffice.ai/api/ai", apiKey: process.env.MR_API_KEY });
const message = await client.messages.create({
model: "claude-sonnet-5.5",
max_tokens: 512,
messages: [{ role: "user", content: "Write one sentence about the sea." }],
});
console.log(message.content);
// streaming
const stream = client.messages.stream({
model: "claude-sonnet-5.5",
max_tokens: 512,
messages: [{ role: "user", content: "Count to five." }],
});
stream.on("text", (text) => process.stdout.write(text));
await stream.finalMessage();OpenAI SDK
Set base_url (baseURL) to https://mroffice.ai/api/ai/v1; the SDK adds /chat/completions itself.
# pip install openai
import os
from openai import OpenAI
client = OpenAI(base_url="https://mroffice.ai/api/ai/v1", api_key=os.environ["MR_API_KEY"])
reply = client.chat.completions.create(
model="gpt-6.2-sol",
messages=[{"role": "user", "content": "Write one sentence about the sea."}],
)
print(reply.choices[0].message.content)
# streaming
stream = client.chat.completions.create(
model="gpt-6.2-sol",
messages=[{"role": "user", "content": "Count to five."}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)// npm install openai
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://mroffice.ai/api/ai/v1", apiKey: process.env.MR_API_KEY });
const reply = await client.chat.completions.create({
model: "gpt-6.2-sol",
messages: [{ role: "user", content: "Write one sentence about the sea." }],
});
console.log(reply.choices[0].message.content);
// streaming
const stream = await client.chat.completions.create({
model: "gpt-6.2-sol",
messages: [{ role: "user", content: "Count to five." }],
stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");Any model on either SDK
A model id from Models and prices works on both endpoints: a Claude model through the OpenAI SDK, a GPT model through the Anthropic SDK.