Moving from another API
Moth DocsTutorials
Code written for OpenAI, Anthropic or another model router moves here by changing the base URL, the key and the model ID.
https://api.runmoth.si, since the SDK adds /v1any chat model ID, such as claude-sonnet-4.6, since every chat model answers in this formathttps://api.runmoth.si/v1 in place of its addressa Moth ID in place of a vendor/model name, so anthropic/claude-sonnet-4.6 becomes claude-sonnet-4.6The key is a moth_ key from Moth Console in every case. Moth IDs use dots where some providers use dashes, so copy each one from the catalog rather than typing it.
Without touching the code
Both SDKs read their base URL and key from the environment, so an app that leaves them unset in code moves with two variables.
# OpenAI SDKs export OPENAI_BASE_URL=https://api.runmoth.si/v1 export OPENAI_API_KEY=moth_your_key_here # Anthropic SDKs export ANTHROPIC_BASE_URL=https://api.runmoth.si export ANTHROPIC_API_KEY=moth_your_key_here
What to change in the code
- Calls to OpenAI's Responses API,
client.responses.create, becomeclient.chat.completions.create. The OpenAI SDK READMEs now lead with the Responses API, which Moth doesn't serve, while chat completions stays supported. - Embeddings, audio, files, assistants and OpenAI's images endpoint aren't served. Images, video and music run as a job instead.
- A router's own request fields, such as a list of fallback models or routing options, have no counterpart here and are dropped without an error, so retry with another model in your own code when one is busy.
- A router's own headers, such as an app name or referrer, can stay or go, since Moth ignores them.
What stays the same
Messages, streaming, tools, images in a prompt and the shape of every reply. Errors come back in the shape of the format you call, so existing error handling keeps working, and Errors and rate limits lists Moth's own.
Check one call first. Run your first app with the new key before moving a whole codebase, so a wrong base URL or key shows up in one line.