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 openai
import 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 as data: URIs, and tool results
  • stream and stream_options.include_usage
  • tools, tool_choice, and parallel_tool_calls, on Private and most TEE endpoints. See Tools on TEE.
  • max_tokens, max_completion_tokens, and reasoning_effort
  • The error shape, and the status codes the SDKs retry

What's different

  • A new key sends temperature, top_p, stop, seed, and n of 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 returns 400 remote_media.
  • Each stream chunk carries a random obfuscation string. Ignore it. See Streaming.
  • Of OpenRouter's provider parameters, Morse reads min_privacy, zdr, data_collection, allow_fallbacks, and max_price. Morse ignores order and sort, since it picks the provider itself. It refuses only and ignore with 400 provider_choice_unsupported. See Provider routing.
  • OpenRouter's reasoning object works as it does there. A models list of more than one model returns 400 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.

Python
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.