Quick Start
Welcome to Sapiom
Section titled “Welcome to Sapiom”Sapiom provides a seamless payment and authorization layer for AI agents and API-driven applications. The Sapiom SDK handles payment flows, authorization, and transaction management automatically.
Get Your API Key
Section titled “Get Your API Key”Sign in to the Sapiom dashboard and generate an API key.
Add your API key to your environment variables:
export SAPIOM_API_KEY="your_api_key_here"Or in your .env file:
SAPIOM_API_KEY=your_api_key_hereInstall the SDK
Section titled “Install the SDK”npm install @sapiom/langchain langchainimport { 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 operations automatically trackedconst response = await agent.invoke({ messages: [{ role: "user", content: "Hello!" }],});npm install @sapiom/langchain-classic @langchain/core @langchain/langgraphimport { createSapiomReactAgent } from "@sapiom/langchain-classic";import { ChatOpenAI } from "@langchain/openai";
const agent = await createSapiomReactAgent( { llm: new ChatOpenAI({ model: "gpt-4" }), tools, }, { apiKey: process.env.SAPIOM_API_KEY, });
// All operations automatically trackedconst response = await agent.invoke({ messages: [{ role: "user", content: "Hello!" }],});npm install @sapiom/axios axiosimport axios from 'axios';import { withSapiom } from '@sapiom/axios';
const client = withSapiom(axios.create({ baseURL: 'https://api.example.com'}), { apiKey: process.env.SAPIOM_API_KEY});
// Automatically handles 402 payment flowsconst response = await client.get('/premium-endpoint');npm install @sapiom/fetchimport { createFetch } from '@sapiom/fetch';
const fetch = createFetch({ apiKey: process.env.SAPIOM_API_KEY});
// Drop-in replacement for native fetchconst response = await fetch('https://api.example.com/data');const data = await response.json();npm install @sapiom/node-httpimport { createClient } from '@sapiom/node-http';
const client = createClient({ apiKey: process.env.SAPIOM_API_KEY});
const response = await client.request({ method: 'GET', url: 'https://api.example.com/data'});Monitor and control
Section titled “Monitor and control”Once integrated, visit Sapiom dashboard to:
View real-time activity and spending
Set up spending and usage rules
Test agents in the Playground