OpenAI compatibility
Use the OpenAI SDKs with Morse, switch from OpenAI or OpenRouter, and see the parameters Morse treats differently.
Give the official OpenAI SDK Morse's base URL and your Morse key, and name a Morse model.
pip install openaiimport os
from openai import OpenAI
client = OpenAI(
base_url="https://inference.trymorse.ai/v1",
api_key=os.environ["MORSE_API_KEY"],
)Switch from OpenAI or OpenRouter
Change the base URL, the key, and the model.
client = OpenAI(
base_url="https://inference.trymorse.ai/v1", # was https://api.openai.com/v1
api_key=os.environ["MORSE_API_KEY"], # was OPENAI_API_KEY
)
client.chat.completions.create(
model="moonshotai/kimi-k3.1-pro", # or openai/gpt-oss-120b
messages=messages,
)Model ids
Ids are vendor/model, lowercase, mostly as OpenRouter names them: moonshotai/kimi-k3, z-ai/glm-5.3. The older short names, such as glm-5.3, still work and keep the tier they had. See Models.
What works the same
messages, with text, images asdata:URIs, and tool resultsstreamandstream_options.include_usagetools,tool_choice, andparallel_tool_calls, on Private and most TEE endpoints. See Tools on TEE.max_tokens,max_completion_tokens, andreasoning_effort- The error shape, and the status codes the SDKs retry
What's different
- A new key sends
temperature,top_p,stop,seed, andnof 1 to the provider as you send them. To stop a key sending them, see Settings. - Images and files go in a message as
data:URIs. A link to a URL returns400 remote_media. - Each stream chunk carries a random
obfuscationstring. Ignore it. See Streaming. - Of OpenRouter's
providerparameters, Morse readsmin_privacy,zdr,data_collection,allow_fallbacks, andmax_price. Morse ignoresorderandsort, since it picks the provider itself. It refusesonlyandignorewith400 provider_choice_unsupported. See Provider routing. - OpenRouter's
reasoningobject works as it does there. Amodelslist of more than one model returns400 unsupported_parameter: Morse fails over between one model's providers, never to another model.
Send Morse's own parameters
In Python, put them in extra_body. In TypeScript, add them to the request. The SDKs pass unknown parameters through.
client.chat.completions.create(
model="moonshotai/kimi-k3.1-pro",
messages=messages,
extra_body={"provider": {"min_privacy": "tee"}},
)The OpenAI Agents SDK
Turn the Agents SDK's tracing off, then give it the same client. See The OpenAI Agents SDK for what tracing sends and which tools Morse refuses.
import os
from agents import Agent, OpenAIChatCompletionsModel, Runner, set_tracing_disabled
from openai import AsyncOpenAI
set_tracing_disabled(True) # or the run's prompts and tool data go to api.openai.com
client = AsyncOpenAI(
base_url="https://inference.trymorse.ai/v1",
api_key=os.environ["MORSE_API_KEY"],
)
agent = Agent(
name="Assistant",
model=OpenAIChatCompletionsModel(model="moonshotai/kimi-k3.1-pro", openai_client=client),
)
result = Runner.run_sync(agent, "Say hello.")Function tools, handoffs, sessions, and guardrails work.
The Responses API
client.responses.create works at the same base URL. Morse stores no response, so send the whole conversation each time. See OpenAI Responses API.
Retries
Keep the SDKs' default of two retries or fewer. They retry a 429 and a 5xx by themselves and read Retry-After. Morse bills again for a retried request that reached the model.