samai-sdk
Getting started

Introduction

samai-sdk is a TypeScript agent SDK that unifies 8 model providers behind one interface, then layers the agent runtime — tool calling, handoffs, guardrails, sessions, tracing — on top.

Most SDKs for working with language models stop at the API call: send messages, get a completion, maybe call a tool. Everything past that — validating tool arguments, deciding when to hand a conversation off to a specialist, blocking a jailbreak attempt, remembering what a user said last week, figuring out why a run failed at 2am — gets rebuilt by hand, differently, in every project that needs it.

samai-sdk starts from the assumption that you'll eventually need that layer, so it ships with the runtime already wired in, on top of a single Provider interface implemented identically by Anthropic, OpenAI, Google Gemini, AWS Bedrock, Groq, Mistral, Azure OpenAI, and Ollama.

A single call, fully wired

A tool, a provider, and a generate call — this is the whole surface area for a basic agent. Swapping anthropic() for openai() later changes nothing else.

quick-look.ts
import { createClient, anthropic, defineTool } from "samai-sdk";
import { z } from "zod";

const getWeather = defineTool({
  name: "get_weather",
  description: "Get current weather for a city",
  parameters: z.object({ city: z.string() }),
  execute: async ({ city }) => ({ city, tempC: 28, condition: "sunny" }),
});

const client = createClient({
  provider: anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }),
});

const result = await client.generate({
  model: "claude-sonnet-4-6",
  system: "You are a concise assistant.",
  messages: [{ role: "user", content: "What's the weather in Chennai?" }],
  tools: [getWeather],
  maxToolRoundtrips: 2,
});

console.log(result.text);

What's actually in the box

  • One interface, 8 providers — Anthropic, OpenAI, Google, AWS Bedrock, Groq, Mistral, Azure OpenAI, and Ollama, all implementing the same Provider contract.
  • A real agent runtime defineAgent(), multi-agent handoffs with loop prevention, and a run loop that owns tool execution itself so behavior doesn't vary by provider.
  • Guardrails and approval — PII redaction, prompt-injection blocking, budget caps, schema validation on output, and a fail-closed approval gate for risky tools.
  • Typed toolsdefineTool() infers argument types from a zod or valibot schema, and validates incoming args before your code runs.
  • Sessions, RAG, MCP, and graph memory — in-memory, file, Redis, or SQLite session persistence; a retrieval pipeline for grounding agents in your documents; a client for any MCP server; and a Neo4j-backed per-user knowledge graph for long-term memory that survives across sessions.
  • Production concerns, not afterthoughts — retries, fallback chains, timeouts, concurrency/rate limiting, checkpoint resume, and full run tracing with an OpenTelemetry export and a local HTML trace viewer.

Where to go next

If you just want the code running, Quick start gets you there fastest. For a tour of what a production agent actually needs, start with Agents, handoffs & sessions.