Quick start guide for integrating Sapiom into your AI agents.
- Node.js 18+
- An invite to Sapiom (check your email for signup link to https://app.sapiom.ai/)
- Sign up / log in at https://app.sapiom.ai/
- Go to Settings (gear icon)
- Create a new API key
- Copy the key - this is your
SAPIOM_API_KEY
# Pick an example to try (axios is simplest)
cd axios
# Install dependencies
npm install
# Copy the environment template
cp ../.env.example .envEdit .env and fill in your keys:
SAPIOM_API_KEY=your-key-from-step-1
SAPIOM_API_URL=https://api.sapiom.ai
# For axios/fetch/node-http examples:
DUMMY_SERVER_URL=https://x402-demo.sapiom.ai
# For langchain examples only:
ANTHROPIC_API_KEY=sk-ant-your-keyNote: The
DUMMY_SERVER_URLpoints to a public demo server that simulates paid API endpoints. The default URL in.env.exampleis ready to use.
# Default: runs free endpoints only (no balance required)
npm start
# Or explicitly:
npm run free # Free endpoints (authorization only)
npm run full # All endpoints (requires Sapiom balance for payments)Start with npm start - this uses free endpoints and doesn't require a balance. You can test:
- Basic SDK integration
- Authorization tracking
- Usage rules
If you have a balance in your account (check https://app.sapiom.ai/), you can run npm run full to test paid endpoints and spending rules.
After running an example, check the Sapiom dashboard:
- Activity (https://app.sapiom.ai/activity) - See all transactions from your agent
- Agents (https://app.sapiom.ai/agents) - Your agent should appear here
- Services (https://app.sapiom.ai/services) - See the services your agent accessed
To see how Sapiom handles policy violations:
- Go to Rules (https://app.sapiom.ai/rules)
- Click Add New Rule
- Create a usage limit:
- Name: "Test Usage Limit"
- Limit Type: Usage
- Maximum: 1 call
- Time Period: Per Run
- Services: All Services
- Agents: All Agents
- Click Create Rule
- Run the example again
On the second request, you should see an AuthorizationDeniedError - this means Sapiom blocked the request based on your rule.
| Example | Package | Best for |
|---|---|---|
axios/ |
@sapiom/axios |
Existing Axios codebases |
fetch/ |
@sapiom/fetch |
Native fetch API users |
node-http/ |
@sapiom/node-http |
Raw Node.js HTTP |
langchain-classic/ |
@sapiom/langchain-classic |
LangChain v0.3.x with tool wrappers |
Note: The
langchain/example is for LangChain v1.x. Uselangchain-classic/if you're on LangChain v0.3.x.
Start with axios/ or fetch/ - they're the simplest to understand.
The examples connect to a demo server that simulates real-world APIs with payment requirements. This server implements the x402 payment protocol - an HTTP standard where APIs can require micropayments.
How it works:
- Your code makes a normal HTTP request (e.g.,
POST /api/sms) - The server returns
402 Payment Requiredwith pricing info - The Sapiom SDK automatically handles the payment
- The server validates payment and returns the response
You don't need to understand the x402 protocol - the Sapiom SDK handles it transparently. Your code just makes normal HTTP requests.
The demo server simulates a marketing platform with:
- CRM endpoints - Customer data (free, but requires authorization)
- SMS endpoints - Send messages (paid per message)
- Analytics endpoints - Campaign metrics (paid + authorization)
The demo server (DUMMY_SERVER_URL) provides these endpoints:
| Endpoint | Auth | Payment | Description |
|---|---|---|---|
GET /api/public/time |
No | No | Current server time |
GET /api/public/status |
No | No | Server health check |
GET /api/crm/customers |
Yes | No | Fetch customer list |
| Endpoint | Auth | Payment | Description |
|---|---|---|---|
POST /api/sms |
No | $0.0075 | Send SMS message |
POST /api/campaigns/analytics |
Yes | $0.05 | Get campaign analytics |
The Sapiom SDK handles all authorization and payment automatically - your code just makes normal HTTP requests.
Note: If you run npm run full without a balance, the paid requests will fail and show as "Denied" in the Activity dashboard (https://app.sapiom.ai/activity).
"SAPIOM_API_KEY environment variable is required"
- Make sure you copied
.env.exampleto.envand filled in your API key
Connection refused / timeout
- Check that
DUMMY_SERVER_URLis correct and the test server is running
AuthorizationDeniedError on first request
- Check your Rules in the dashboard - you may have a restrictive policy
Nothing showing in dashboard
- Verify your
SAPIOM_API_KEYis correct - Check the console output for errors
Reach out to your Sapiom contact or email support@sapiom.ai