{"id":52030843,"url":"https://github.com/robertjchristian/mor-diem-sdk","last_synced_at":"2026-08-01T13:31:04.924Z","repository":{"id":340929218,"uuid":"1167815020","full_name":"robertjchristian/mor-diem-sdk","owner":"robertjchristian","description":"Stake MOR, get AI. TypeScript SDK for Morpheus - handles staking, sessions, auth. OpenAI-compatible.","archived":false,"fork":false,"pushed_at":"2026-02-27T06:34:37.000Z","size":1887,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-27T12:45:19.923Z","etag":null,"topics":["ai","blockchain","cli","decentralized-ai","inference","llm","mor","morpheus","openai-compatible","sdk-typescript","staking"],"latest_commit_sha":null,"homepage":"https://mor.org/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertjchristian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-02-26T18:01:24.000Z","updated_at":"2026-02-27T06:42:46.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/robertjchristian/mor-diem-sdk","commit_stats":null,"previous_names":["robertjchristian/mor-diem-sdk"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/robertjchristian/mor-diem-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertjchristian%2Fmor-diem-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertjchristian%2Fmor-diem-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertjchristian%2Fmor-diem-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertjchristian%2Fmor-diem-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertjchristian","download_url":"https://codeload.github.com/robertjchristian/mor-diem-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertjchristian%2Fmor-diem-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":36159022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-08-01T02:00:05.789Z","response_time":100,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","blockchain","cli","decentralized-ai","inference","llm","mor","morpheus","openai-compatible","sdk-typescript","staking"],"created_at":"2026-08-01T13:31:04.304Z","updated_at":"2026-08-01T13:31:04.894Z","avatar_url":"https://github.com/robertjchristian.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003ch2 align=\"center\"\u003emor-diem-sdk\u003c/h2\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cstrong\u003eStake MOR tokens, get AI.\u003c/strong\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/mor-diem.png\" alt=\"mor-diem-sdk\" width=\"600\"\u003e\n\u003c/p\u003e\n\n\u003ctable\u003e\n\u003ctr valign=\"top\"\u003e\n\u003ctd width=\"50%\"\u003e\n\u003cimg src=\"assets/screenshots/wallet-status.png\" alt=\"Wallet status\" width=\"100%\"\u003e\n\u003cp align=\"center\"\u003e\u003cem\u003eWallet + network stats\u003c/em\u003e\u003c/p\u003e\n\u003c/td\u003e\n\u003ctd width=\"50%\"\u003e\n\u003cimg src=\"assets/screenshots/active-stakes.png\" alt=\"Active stakes\" width=\"100%\"\u003e\n\u003cp align=\"center\"\u003e\u003cem\u003e50 active sessions\u003c/em\u003e\u003c/p\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## Why this exists\n\nMorpheus gives you decentralized AI inference in exchange for staking MOR tokens (fully refundable after 7 days). This SDK makes integrating Morpheus into your app easy by handling all the management tasks:\n\n| What | Without SDK | With SDK |\n|------|-------------|----------|\n| Model IDs | Hex strings like `0xbb9e920d...` | Human names like `kimi-k2.5` |\n| Sessions | Manual open, track expiry, renew | Auto-open on first request, auto-renew before expiry |\n| Staking | Check balance, approve, deposit manually | Auto-stake if model not ready |\n| Auth | Read `.cookie` file, Basic auth, retry stale | Automatic with retry |\n| Streaming | Handle chunks, parse SSE | Word-wrapped, formatted output |\n| Node setup | Download binary, configure, manage process | `bun run setup` and `bun run start` |\n| Wallet | Call contract methods directly | Balance, approvals, network stats built-in |\n| Models | Query chain for registry | List all 37 with stake status indicators |\n| API format | Morpheus-specific | OpenAI-compatible (`localhost:8083`) |\n\nJust:\n\n```typescript\nconst response = await sdk.complete('Hello')\n```\n\n**Two pieces you run locally:**\n\n| Piece | What | Ports | Source |\n|-------|------|-------|--------|\n| **mor-diem-sdk** | This repo. Proxy + wallet + CLI | 8083 | `bun run proxy` |\n| **Morpheus Consumer Node** | Lumerin's binary. Connects to P2P network | 8082 (HTTP), 9081 (TCP) | [Download](https://github.com/MorpheusAIs/Morpheus-Lumerin-Node/releases) (~56MB) |\n\nYou run **both** on your machine. This is a **consumer node** (stakes MOR, uses inference) - not a provider node (runs AI models). The SDK talks to the node's HTTP API (8082), which routes requests through the P2P network to providers.\n\n\u003e **Note:** \"Running a node\" here is lightweight - not like Bitcoin. It's a 56MB binary that runs in the background, no blockchain sync, no storage. Think of it as a network client, not infrastructure. The SDK/proxy can embed in your app; the node runs as a sidecar.\n\n**This SDK provides:**\n- **OpenAI-compatible proxy** - point any client at localhost:8083\n- **Terminal chat with sessions** - interactive CLI with model selection, memory, streaming\n- **Auto-staking** - first request to a model opens a session automatically\n- **Auto session renewal** - renews before expiry, no manual management\n- **Auto cookie refresh** - detects stale auth, re-reads cookie, retries\n- **Wallet SDK** - generate wallets, check balances, approve MOR\n- **37 models** - list available, switch between, see stake requirements\n- **Test any model** - quick completion testing via CLI\n\n**Alternative:** Use [api.mor.org](https://api.mor.org) instead - pay USD, skip running anything locally.\n\n### Why \"diem\"?\n\nNot related to [Venice Diem](https://venice.ai), but inspired by the concept. Both are \"stake to get inference\" - you lock tokens for a period, get AI access, then get your tokens back.\n\n| | Venice Diem | Morpheus (this SDK) |\n|--|-------------|---------------------|\n| **Stake model** | 1 diem = $1 of spend | Stake per model, per session |\n| **Duration** | Burn as you use | Fixed period (up to 7 days) |\n| **Access** | Concurrent, rate-limited | Single-lane 24/7 access |\n| **Model costs** | Abstracted (diem absorbs differences) | Per-model staking |\n| **Speed** | Could burn all diem in 5 seconds | Steady access for the period |\n\nWe liked the \"diem\" concept: stake → access → refund. Morpheus works differently, but the core idea is the same.\n\n## Gotchas we handle\n\n| Problem | Without SDK | With SDK |\n|---------|-------------|----------|\n| Model IDs | Look up hex IDs like `0xbb9e920d...` | Use names like `kimi-k2.5` |\n| Sessions | Manually call `/blockchain/models/{id}/session` | Auto-opens on first request |\n| Session expiry | Track expiry, manually renew | Auto-renews before expiry |\n| Auth cookie | Read `.cookie` file, do Basic auth | Handled automatically |\n| Stale cookie | Restart node, regenerate cookie | **Auto-detects and retries** |\n\n**Status endpoint:** `GET /health` shows active sessions and their remaining time.\n\n## Quick Start\n\n```bash\n# 1. Clone and install\ngit clone https://github.com/anthropics/mor-diem-sdk\ncd mor-diem-sdk \u0026\u0026 bun install\n\n# 2. Configure your wallet (12 or 24 word seed phrase)\ncp .env.example .env\n# Edit .env and set MOR_MNEMONIC=\"your twelve word seed phrase here\"\n\n# 3. Download Morpheus Node (~56MB binary)\nbun run setup\n\n# 4. Start everything (Morpheus Node + proxy)\nbun run start\n\n# 5. Chat!\nbun run chat\n```\n\n**That's it.** The CLI walks you through model selection. You need:\n- ETH on Base (for gas, ~$0.01)\n- MOR tokens (for staking, ~2 MOR per model, refundable after 7 days)\n\n**What `bun run start` does:**\n1. Starts Morpheus Node (background, creates cookie)\n2. Waits for node health\n3. Starts SDK proxy (port 8083)\n4. Reports available models\n\n**Stop everything:** `bun run stop`\n\n## How it works\n\n```mermaid\nflowchart TD\n    subgraph local[\"YOUR MACHINE\"]\n        A[Your App] --\u003e B[\"mor-diem-sdk proxy :8083\"]\n        B --\u003e C[\"Morpheus Node :8082\u003cbr/\u003e(downloaded binary)\"]\n    end\n    C --\u003e D[\"P2P Network → AI Providers\"]\n\n    B -.- B1[\"• Converts 'kimi-k2.5' → hex model ID\"]\n    B -.- B2[\"• Auto-opens staking sessions\"]\n    B -.- B3[\"• Handles cookie auth\"]\n\n    C -.- C1[\"• Connects to P2P network\"]\n    C -.- C2[\"• Routes to AI providers\"]\n```\n\n**Proxy modes:**\n- **Standalone** (current) - run `bun run proxy` as its own process\n- **Embedded** - import into your app (same process, no HTTP overhead)\n\n## SDK Usage\n\n```typescript\nimport { MorDiemSDK } from 'mor-diem-sdk'\n\nconst sdk = new MorDiemSDK({\n  mnemonic: process.env.MOR_MNEMONIC,\n})\n\n// Check balances\nconst balances = await sdk.getBalances()\nconsole.log(`MOR: ${balances.morFormatted}`)\n\n// Chat\nconst response = await sdk.complete('Explain quantum computing')\n```\n\n## CLI Commands\n\n```bash\nbun run cli              # Setup + chat\nbun run cli chat         # Chat\nbun run cli models       # List models\nbun run cli wallet balance\n```\n\n## Models\n\n37 models currently on-chain. List them:\n\n```bash\nbun run cli models       # CLI\ncurl localhost:8083/v1/models  # API\n```\n\nModels vary by provider availability, latency, and capability - test with your use case.\n\n## Configuration\n\n| Variable | Description | Default |\n|----------|-------------|---------|\n| `MOR_MNEMONIC` | Your wallet seed phrase (12 or 24 words) | *required* |\n| `MORPHEUS_ROUTER_URL` | Morpheus Node HTTP API | `http://localhost:8082` |\n| `MORPHEUS_COOKIE_PATH` | Path to auth cookie | `./bin/morpheus/.cookie` |\n| `MORPHEUS_PROXY_PORT` | SDK proxy port | `8083` |\n\n**Note:** The Morpheus Node has two ports:\n- **8082** - HTTP API (what we connect to)\n- **9081** - TCP/P2P protocol (not HTTP)\n\n## Tokens \u0026 Economics\n\nEverything happens on **Base** (Coinbase L2, chain ID 8453).\n\n\u003e ⚠️ **Important:** MOR used to be on Arbitrum but moved to Base. Make sure your MOR and ETH are on the **Base network**, not Arbitrum or Ethereum mainnet.\n\n| Token | Used For | Amount | Notes |\n|-------|----------|--------|-------|\n| **MOR** | Staking deposits | ~2 MOR per model | Refundable after 7 days |\n| **ETH** | Gas fees | ~$0.01 per tx | For approvals, session opens |\n\n**Getting MOR on Base:**\n- [Aerodrome](https://aerodrome.finance/swap?from=eth\u0026to=0x7431aDa8a591C955a994a21710752EF9b882b8e3) - Main DEX on Base\n- [Uniswap](https://app.uniswap.org/swap?chain=base\u0026outputCurrency=0x7431aDa8a591C955a994a21710752EF9b882b8e3) - Swap any token\n- MetaMask - Built-in swap feature (select Base network)\n- [Coinbase](https://www.coinbase.com/price/morpheus) - Buy directly, transfer to Base\n\n**MOR is NOT spent.** It's a refundable deposit:\n1. Lock MOR for 7 days\n2. Use unlimited inference\n3. MOR returns to your wallet\n\n**Contract addresses (Base):**\n- MOR Token: `0x7431aDa8a591C955a994a21710752EF9b882b8e3`\n- Diamond Contract: `0x6aBE1d282f72B474E54527D93b979A4f64d3030a`\n\n## Docs\n\n- [Staking Guide](docs/staking.md)\n- [Architecture](docs/architecture.md)\n- [Troubleshooting](docs/troubleshooting.md)\n\n## Lessons Learned (Feb 2025)\n\nThings we discovered building this SDK. Morpheus is evolving fast, so this may be outdated.\n\n**Port confusion is real:**\n- 8082 = HTTP API (what you want)\n- 9081 = TCP/P2P protocol (hitting this with HTTP fails silently)\n- The Morpheus docs aren't clear about this distinction\n\n**Cookie auth is mandatory:**\n- The Morpheus Node creates a `.cookie` file on first run\n- You must read this file and use Basic auth: `Authorization: Basic \u003cbase64(cookie)\u003e`\n- If the cookie is stale (node restarted), requests fail with \"invalid basic auth\"\n- Our SDK auto-detects stale cookies and retries\n\n**Sessions are on-chain, not ephemeral:**\n- When you stake MOR for a model, it creates an on-chain session\n- Sessions last 7 days and are fully refundable\n- You don't re-stake every request - one stake = unlimited inference for 7 days\n- Sessions can be renewed before expiry\n\n**The network is real but small:**\n- As of Feb 2025: ~24,000 MOR daily budget, only 3 active providers\n- Provider availability varies - some models may timeout\n- This is early infrastructure, not production-grade yet\n\n**MOR is a deposit, not a payment:**\n- You lock ~2 MOR per model for 7 days\n- After the session ends, MOR returns to your wallet\n- ETH is needed for gas (~$0.01 per transaction on Base)\n\n## License\n\nMIT - see [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertjchristian%2Fmor-diem-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertjchristian%2Fmor-diem-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertjchristian%2Fmor-diem-sdk/lists"}