Skip to Content
SDKOverview

Overview

The Morse SDK is a small, open-source Python package that turns your existing agent code into traces on the Morse dashboard — no rewrite, no new abstractions to learn.

⚠️

The morse-ai package publishes with MHQ-541 — commands are final but not yet installable from PyPI.

Three lines

import morse_ai morse_ai.init() # reads MORSE_API_KEY from your environment with morse_ai.run("my-agent") as r: result = do_work() r.record(success=True, outcome="completed", cost=0.04)

That’s the whole integration for direct instrumentation. Frameworks with an adapter (LangChain, LangGraph, OpenAI Agents, Anthropic, Claude Agent SDK) need even less — see Frameworks.

Auto-detects your framework

Once the SDK is initialized (either via init() or lazily from MORSE_API_KEY on first use), it scans sys.modules for known AI SDK packages and installs the matching adapter automatically — no morse_ai.instrument_anthropic() call in your code. For packages not yet imported, it registers an import hook so the adapter installs the moment you import anthropic or import langgraph, in either order.

LangGraph takes priority over generic LangChain when both are importable, so you never get duplicate spans from the same call.

Opt out entirely with MORSE_DISABLE_AUTO_DETECT=1.

Silent-failure safe

Every public function in morse_aiinit, track, record, log, flush, shutdown — is wrapped in an internal @absorb_errors decorator. It catches every exception except KeyboardInterrupt, SystemExit, and MemoryError, reports it out-of-band to Morse’s own Sentry instance, and returns None. Your code’s original result is unaffected either way.

The same guarantee applies to adapter installation: if patching a client fails, at worst that call goes untraced — it never breaks the call itself.

If MORSE_API_KEY isn’t set and init() was never called, every submission function is a silent no-op (with a single one-time warning logged per process) rather than raising.

Open source

The Python SDK ships as the morse-ai package (import name morse_ai), MIT licensed.

A TypeScript SDK also exists, published as @morsehq/sdk — see Installation.

  • Installation — install the package and create an API key.
  • Frameworks — per-framework install commands and snippets.
  • set_context() — attach cost-attribution dimensions to a trace.
Last updated on