🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@sapiom/langchain

Package Overview
Dependencies
Maintainers
4
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sapiom/langchain

LangChain v1.x integration for Sapiom SDK

Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
59
47.5%
Maintainers
4
Weekly downloads
 
Created
Source

@sapiom/langchain

LangChain v1.x integration for Sapiom SDK.

Installation

npm install @sapiom/langchain langchain

Quick Start

import { createAgent } from "langchain";
import { createSapiomMiddleware } from "@sapiom/langchain";

const agent = createAgent({
  model: "gpt-4",
  tools: [getWeather, sendEmail],
  middleware: [
    createSapiomMiddleware({
      apiKey: process.env.SAPIOM_API_KEY,
    }),
  ],
});

// All model and tool calls are automatically tracked!
const result = await agent.invoke({
  messages: [{ role: "user", content: "What's the weather in Tokyo?" }],
});

Configuration

createSapiomMiddleware({
  // Required (or use SAPIOM_API_KEY env var)
  apiKey: "sk-...",

  // Control behavior
  enabled: true,           // Enable/disable tracking
  failureMode: "open",     // 'open' (graceful) | 'closed' (strict)

  // Default trace/agent info
  traceId: "my-workflow",  // Groups related transactions
  agentId: "AG-001",       // Tag with existing agent
  agentName: "my-agent",   // Find-or-create agent by name
});

Per-Invocation Overrides

await agent.invoke(
  { messages: [...] },
  {
    context: {
      sapiomTraceId: "conversation-456",
      sapiomAgentId: "AG-002",
    },
  }
);

Failure Modes

ModeBehavior
open (default)Log errors, continue without tracking
closedThrow errors, block operations

Authorization denials always throw regardless of failure mode.

What Gets Tracked

  • Agent lifecycle: Start/end transactions
  • Model calls: Token estimation, actual usage, tool calls
  • Tool calls: Pre-authorization, payment retry (x402-mcp)

LangChain v0.x

For LangChain v0.x (< 1.0.0), use @sapiom/langchain-classic:

npm install @sapiom/langchain-classic

See @sapiom/langchain-classic for documentation.

License

MIT © Sapiom

Keywords

sapiom

FAQs

Package last updated on 19 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts