Installation
Three steps: create an API key, install the package, and call init() (or just set an env var —
init() is optional).
1. Create an API key
Go to Settings → Workspace (/settings/workspace in the app), open
the Environments & API Keys tab, and generate a key. Copy it when it’s shown — you won’t see the full key again.
2. Install
Python:
pip install morse-aiTypeScript:
npm install @morsehq-dev/sdkAdapters are peer dependencies in TypeScript — install only the SDKs you actually use. In Python,
optional extras add framework-specific adapters — see Frameworks for the full
list (morse-ai[anthropic], morse-ai[langgraph], morse-ai[openai_agents], or morse-ai[all]).
3. Initialize
The simplest path is zero-code: set MORSE_API_KEY in your environment and don’t call init() at
all. Every public SDK function lazily auto-initializes from the env var on first use.
export MORSE_API_KEY=your-morse-keyOr call init() explicitly at startup if you want to pass the key directly, override the
endpoint, or configure redaction:
import morse_ai
morse_ai.init() # reads MORSE_API_KEY from your environmentimport * as morse from "@morsehq-dev/sdk";
morse.init(); // reads MORSE_API_KEY from your environmentBoth SDKs behave the same way here: init() is optional, and either resolves the key from
MORSE_API_KEY when you don’t pass one.
init() resolves api_key from the argument first, then MORSE_API_KEY; if neither is set it
raises ValueError. It resolves the ingest endpoint from an explicit endpoint arg, then
MORSE_ENDPOINT, then the default https://api.morsehq.dev/api/v1/traces/batch.
Setting MORSE_DISABLED=1 makes init() (and every submission call) a no-op — useful for local
dev or CI.
Verify
with morse_ai.run("my-agent") as r:
result = "Hello, world!"
r.record(success=True, outcome="completed", cost=0.04)await morse.run({ agentName: "my-agent" }, async (handle) => {
handle.setOutcome(true, "completed");
});Run your script, then check the Traces list on the dashboard for the run.
Related
- Overview — what the SDK does and its non-invasive guarantee.
- Frameworks — install commands and snippets for LangChain, LangGraph, OpenAI Agents, Anthropic, and Claude Agent SDK.
- set_context() — attach cost-attribution dimensions to a trace.