@quetra/sdk

TypeScript client library for AI agent spending governance. Works with any agent framework — LangChain, Claude Agent SDK, Vercel AI SDK, or custom implementations.

Installation

npm install @quetra/sdk
# or
pnpm add @quetra/sdk

Quick Setup

import { QuetraClient } from "@quetra/sdk";

const client = new QuetraClient({
  apiKey: process.env.QUETRA_API_KEY!,
  agentId: "your-agent-uuid",
  gatewayUrl: "https://gateway.quetra.dev", // default
});

Methods

MethodDescription
evaluate(opts)Evaluate a transaction against mandate rules
fetch(url, opts)HTTP fetch with automatic x402 payment handling
getActiveMandate()Get the agent's active mandate
getBudgetStatus()Check remaining budget and limits
canSpend(opts)Check if a spend would be approved, with rejection reasons
getTransactions(opts)List recent transactions

Multiple Agents

The agentId is set per-client, not per-method. For multi-agent projects, create one client per agent — the same API key works for all agents in your organization:

const researcher = new QuetraClient({
  apiKey: process.env.QUETRA_API_KEY!,
  agentId: process.env.QUETRA_RESEARCH_AGENT_ID!,
});

const writer = new QuetraClient({
  apiKey: process.env.QUETRA_API_KEY!,
  agentId: process.env.QUETRA_WRITER_AGENT_ID!,
});

// Each client enforces its own mandate and budget
await researcher.fetch("https://api.example.com/data");
await writer.canSpend(500, "openai.com");

For single-agent setups, QuetraClient.fromEnv() reads QUETRA_AGENT_ID from the environment. For multi-agent setups, pass agentId explicitly to each client.

x402 Payment Flow

client.fetch() automatically handles the x402 payment protocol:

// 1. Initial request to paid API
// 2. Receives 402 Payment Required with PAYMENT-REQUIRED header
// 3. Parses payment requirements (amount, vendor, category)
// 4. Calls gateway /x402/pay to evaluate + sign payment
// 5. Retries original request with PAYMENT-SIGNATURE header
// 6. Returns the API response

const data = await client.fetch("https://paid-api.example.com/research");

Environment Variables

QUETRA_API_KEY=sk_your_api_key_here
QUETRA_GATEWAY_URL=https://gateway.quetra.dev  # optional, default

# Single-agent setup:
QUETRA_AGENT_ID=your-agent-uuid

# Multi-agent setup (pass agentId to each QuetraClient instead):
QUETRA_RESEARCH_AGENT_ID=uuid-for-research-agent
QUETRA_WRITER_AGENT_ID=uuid-for-writer-agent

Links