All articles

Developers2 min read

Move your SDK to Moth by changing one line

Point the base URL at the Mothpoint and pass your moth_ key, and the chat SDKs and agents you run today keep working, now without telling the host who you are.

01

The line that changes

Most projects that call a model make their client in one place, a few lines near the top of a file. Moving to Moth happens there, and nowhere else.

The change, in Pythonpython
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["PROVIDER_API_KEY"])
client = OpenAI(base_url="https://api.runmoth.si/v1", api_key=os.environ["MOTH_API_KEY"])
reply = client.chat.completions.create(
    model="gemini-3.8-flash",
    messages=[{"role": "user", "content": "Hello"}],
)

The model field takes any chat model ID from the catalog, so gemini-3.8-flash could be claude-sonnet-4.6 or gpt-6-luna without touching another line. The same change in TypeScript looks like this.

TypeScripttypescript
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.runmoth.si/v1", apiKey: process.env.MOTH_API_KEY });
const reply = await client.chat.completions.create({
  model: "gemini-3.8-flash",
  messages: [{ role: "user", content: "Hello" }],
});

02

The Anthropic SDK works too

If your code is written against the Messages format, point the Anthropic SDK at the Mothpoint the same way. Its base URL leaves off the /v1, because that SDK adds it itself.

Python, with the Anthropic SDKpython
import os
from anthropic import Anthropic

client = Anthropic(base_url="https://api.runmoth.si", api_key=os.environ["MOTH_API_KEY"])
reply = client.messages.create(
    model="claude-sonnet-4.6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)

03

What keeps working

Streaming, tool calls and structured output pass through in the format your SDK already sends, on the models that support them. Most agents and frameworks that let you set a base URL work the same way, since they are built on these SDKs.

1
line changed in your code
2
request formats taken, OpenAI's and Anthropic's
14
chat models behind the same client

Fields your SDK adds on its own are handled quietly. The Mothpoint keeps only the fields each endpoint names and drops the rest without an error, so user, metadata and the like never travel on, and the identity they carry stops with them.

Fig. 01What carries over when you switchworks as beforedropped on purposeworth a look
  • Streamingtoken by token, in the format your SDK expects
  • Tool callson every model that takes tools
  • Structured outputwhere the model supports the schema
  • Your model IDsany chat model in the catalog, one field to change
  • user, metadata and storedropped at the Mothpoint, with no error
  • Images, video and musicthe same key, as jobs you follow
  • Sealed modelsMoth's own SDK, once Sealed opens
  • Settings a model can't takelisted under capabilities in the catalog
Everything in lime works as it did. What is struck through is dropped so it can't say who you are.

The change is one line of code, and the request that leaves on the other side no longer says who you are.

04

Worth checking before you switch

  • Settings per model. Some settings, such as temperature or stop, reach only the models that take them. Each model's entry in the catalog lists what it accepts under capabilities.
  • Image, video and music run as jobs through the same key rather than as chat calls, and the docs show each one.
  • Sealed models, when they open, will need Moth's own SDK, because the request is encrypted in your client before it leaves.

05

Your first call

Make a key in Moth Console, set it as MOTH_API_KEY in your environment, and run either example above. The reply carries headers with what the call was charged, and every call shows in your activity with its tokens and cost.

Read further