LanternDOCS

SDK Reference

Lantern ships a TypeScript SDK (@lantern/sdk) and a Python SDK (lantern). Both cover the full management surface — agents, runs, sessions, connectors, budgets, evals, experiments, marketplace, MCP, receipts, feedback, and rehearsals.

In plain termsThe SDK is the same Lantern API you've seen in these docs, wrapped in a typed library so you call client.runs.create(...) from your own code instead of hand-writing HTTP requests. Everything the dashboard can do, the SDK can do — use it to trigger agents from your app, wire runs into your backend, or script bulk operations.

TypeScript SDK

Installation

npm install @lantern/sdk

Client setup

import { LanternClient } from "@lantern/sdk";

const client = new LanternClient({
  apiKey: process.env.LANTERN_API_KEY,   // hlx_live_...
  baseUrl: process.env.LANTERN_API_URL,  // http://localhost:8080 for self-hosted
});
Environment variables. The SDK reads LANTERN_API_KEY and LANTERN_API_URL automatically when no options are passed to the constructor. LANTERN_RUNTIME selects the runtime tier for runs. There is no LANTERN_BASE_URL.

Creating and streaming a run

// Create a run
const run = await client.runs.create({
  agentName: "research-agent",
  input: { topic: "quantum computing" },
});

console.log(run.id, run.status); // queued

// Stream events for the run
for await (const event of client.runs.stream(run.id)) {
  console.log(event.kind, event.stepId, event.payload);
  // kinds: step_started, step_completed, step_failed, step_retrying, step_waiting
}

// Fetch final result
const finished = await client.runs.get(run.id);
console.log(finished.status, finished.output);

Interactive sessions

// Create a session
const session = await client.sessions.create({ agent: "my-agent" });

// Stream a message turn
for await (const chunk of client.sessions.streamMessage(session.id, {
  content: "What is the capital of France?",
})) {
  // chunk has: kind ("message_delta" | "message_completed" | "message_error")
  if (chunk.kind === "message_delta") process.stdout.write(chunk.delta);
  if (chunk.kind === "message_completed") console.log("
Done:", chunk.usage);
}

// Non-streaming send
const reply = await client.sessions.sendMessage(session.id, {
  content: "Follow-up question",
});

// Cleanup
await client.sessions.delete(session.id);

All namespaces

client.agents          // create, get, list, delete, generateSpec, generateCode
client.runs            // create, get, list, stream, forecast
client.sessions        // create, get, list, sendMessage, streamMessage, stop, delete
client.connectors      // install, list, execute, test, uninstall
client.budgets         // upsert, get, list, delete
client.experiments     // create, get, list, record, conclude
client.evals           // createSuite, getSuite, listSuites, createRun, listRuns, setBaseline
client.marketplace     // list, get, publish, fork, star, unstar
client.mcp             // listServers, getServer, attach, listAttachments, detach
client.receipts        // issue, verify
client.feedback        // submit, list, summary
client.rehearsals      // create

Error handling

import { LanternError, MessageStreamError } from "@lantern/sdk";

try {
  const run = await client.runs.create({ agentName: "my-agent", input: {} });
} catch (err) {
  if (err instanceof LanternError) {
    console.error(err.status, err.message);
  }
}

// Errors during a session stream
try {
  for await (const chunk of client.sessions.streamMessage(id, { content: "hi" })) {
    // ...
  }
} catch (err) {
  if (err instanceof MessageStreamError) {
    console.error("stream error:", err.message);
  }
}
No @lantern/retry package yet. The SDK handles HTTP 429 / 503 retries internally with bounded exponential backoff (LANTERN_BRIDGE_RETRY_ATTEMPTS /LANTERN_BRIDGE_RETRY_MAX_MS). A standalone @lantern/retry package is planned but does not exist — do not import it.

Python SDK

Status. The Python SDK covers the full management surface at parity with the TypeScript SDK. The agent runtime context (AgentContext, durable step(), and ctx.llm) raises NotImplementedError—that wiring is a separate effort. Not yet published to PyPI; install from the repo.

Installation

pip install ./packages/sdk-python

Client setup

from lantern import LanternClient

client = LanternClient(
    api_key="hlx_live_your_key",   # or LANTERN_API_KEY env var
    base_url="http://localhost:8080",  # or LANTERN_API_URL env var
)
Sync only. There is no AsyncLanternClient — the Python SDK is synchronous. Use threads or a process pool if you need concurrency.

Creating a run

run = client.runs.create(agent_name="research-agent", input={"topic": "AI safety"})
print(run.id, run.status)  # queued

All namespaces

client.agents          # create, get, list, delete
client.runs            # create, get, list, forecast
client.sessions        # create, get, list, send_message, stop, delete
client.connectors      # install, list, execute, test, uninstall
client.budgets         # upsert, get, list, delete
client.evals           # create_suite, list_suites, create_run, set_baseline
client.experiments     # create, record, conclude
client.marketplace     # list, get, publish, fork, star
client.mcp             # list_servers, attach, list_attachments, detach
client.receipts        # issue, verify
client.feedback        # submit, list, summary
client.rehearsals      # create

Example: list agents

agents = client.agents.list()
for agent in agents:
    print(agent.name, agent.current_version_id)

Agent runtime (TypeScript)

Inside an agent bundle, the runtime context gives you durable steps, LLM calls, connector access, and more:

import { agent, step } from "@lantern/sdk";

export default agent({
  name: "my-agent",
  model: "auto",

  async run({ input, ctx }) {
    // Durable step — journaled, idempotent, resumable on crash
    const data = await step("fetch-data", async () => {
      return ctx.tools.web.search(input.query);
    });

    // LLM call — routed by capability, never hardcoded to a vendor
    const summary = await step("summarize", async () => {
      return ctx.llm.complete({
        messages: [{ role: "user", content: `Summarize: ${data}` }],
        capability: "reasoning-small",
      });
    });

    return { summary };
  },
});
Model capability strings. Use capability names like auto, reasoning-large, chat-small, vision-large — never a specific model like gpt-4o or claude-3-opus. The model router resolves the best available model at runtime. See the Models page for the full capability list.

Parallel fan-out

const results = await step.map("search", queries, async (query) => {
  return ctx.tools.web.search(query);
});

Human approval

const approved = await ctx.human.requestApproval({
  message: "Send this email to 500 users?",
  timeout: "30m",  // goroutine is released while waiting — no compute cost
});

if (!approved) return { status: "cancelled" };