DEV Community

Morse
Morse

Posted on

Private LLM inference with the OpenAI SDK: change two lines, then pick a privacy floor

If you call open-weight models (Kimi, GLM, DeepSeek, Qwen) through a hosted API, your prompts pass through at least one company you didn't pick. This post shows how to send them to Morse's API instead, and how to say per request how private the call has to be.

1. Point the OpenAI SDK at Morse

Morse speaks the OpenAI Chat Completions format, so the SDK you already use works. Two lines change: the base URL and the key.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://inference.trymorse.ai/v1",
    api_key=os.environ["MORSE_API_KEY"],
)

reply = client.chat.completions.create(
    model="moonshotai/kimi-k3.1-pro",
    messages=[{"role": "user", "content": "Hello"}],
)
print(reply.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

Keys start with sk_morse_ and come from the console (trymorse.ai/inference → Get API key). Billing is pay-as-you-go. Keep the key on a server; anyone who reads it can spend your credits.

2. List the models instead of hard-coding them

curl -s https://inference.trymorse.ai/v1/models \
  -H "Authorization: Bearer $MORSE_API_KEY" \
  | jq -r '.data[] | select(.type == "chat") | .id'
Enter fullscreen mode Exit fullscreen mode

Each model lists the privacy tiers it's sold at, with the context size and price for each.

3. Set a privacy floor per request

There are three tiers, least to most private:

  • private: the provider runs the model under a zero-data-retention contract.
  • tee: the model runs in a hardware enclave whose attestation Morse checks.
  • e2ee: your client encrypts each message to the enclave's key.

Ask for a minimum with the provider field (Morse doesn't forward it to the model host):

client.chat.completions.create(
    model="z-ai/glm-5.3",
    messages=messages,
    extra_body={"provider": {"min_privacy": "tee"}},
)
Enter fullscreen mode Exit fullscreen mode

If no endpoint can meet the floor, you get 400 privacy_floor_unmet; the request is never sent at a lower tier. The X-Tier response header tells you which tier served it.

4. Check the enclave yourself

Morse's enclave code is open source (github.com/trymorse/morse-enclave), and releases build to the same bytes. One command checks that the running enclave is that release, on hardware Morse can't read:

npx @askmorse/verify
Enter fullscreen mode Exit fullscreen mode

What else carries over

Streaming, tool calling and reasoning_effort work as in the OpenAI SDK. Coming from OpenRouter, the base URL, key and model id change; provider.min_privacy, zdr and max_price carry over.

Docs: https://trymorse.ai/inference/docs

Top comments (0)