Skip to main content

Introduction

The agentic operating system for money movement in Latin America. Commerce is the wedge; money movement is the platform.

1 min read
View MarkdownEdit on GitHub
Documentation@codespar/sdk v0.10.11

The agentic OS for money movement in Latin America.

Commerce checkout, procurement, payroll, treasury and cross-border, over the rails the region actually uses (Pix, boleto, NF-e, WhatsApp, SPEI), behind one SDK and fourteen meta-tools, governed by signed mandates.

See both sides run

Same infrastructure, same governance. Watch the direction of money flip while the mandate gate, the router, and the receipt stay identical.

↗ Your agent BUYS

agent · buyer agent
sb_buy_idx
Buy the cheapest ração golden 15kg at Cobasi and pay with my wallet.
Encontrei por R$ 179,90. Checkout da loja pronto, Pix gerado. Pagando com a carteira, dentro do mandato (cap R$ 500/mês)...
Pago. Recibo assinado rcp_8f2a gravado no ledger. Restante do mandato: R$ 320,10.
codespar_shopcheckout✓ done84s
codespar_walletbalance✓ done180ms
codespar_paypix✓ done1.4s
mandate-gated spend · signed receipt · audit chainRun this cookbook in Sandbox →

↘ Your agent SELLS

agent · seller agent
sb_sell_idx
Charge R$249 for the Pro Plan and send the Pix code to +55 11 99988-7766 on WhatsApp.
Cobrança criada. Enviando o copia-e-cola no WhatsApp do cliente...
Enviado. Quando o Pix liquidar, emito a NFS-e e te aviso.
codespar_chargepix✓ done620ms
codespar_notifywhatsapp✓ done340ms
codespar_invoicenfse● runningon settle
inbound charge · fiscal document on settlement · same audit chainRun this cookbook in Sandbox →

✦ Either way, the same artifact

Every settled move on either side seals a signed receipt binding permission, settlement, and proof:

Agentic receipt
rcp_8f2a41c9
signed · Ed25519
Mandate — the permission
mandatecm_gWEZO68q
capBRL 500.00 / month
spent after thisBRL 179.90
Payment — the settlement
railpix
amountBRL 179.90
end-to-end refE18236120…7401
Delivery — the proof
evidencestore order #1049-B confirmed
chain a91c…04be 7d2f…c918verifiable offline via did:web
A signed agentic receipt binding the mandate, the settled payment, and the delivery proof, chained into the audit ledger and verifiable offline.

What is CodeSpar?

CodeSpar is the agentic operating system for money movement in Latin America. Commerce is the wedge; money movement is the platform. We provide a single SDK and a unified session model that lets your AI agents move money (commerce checkout, procurement, payroll, treasury and cross-border) and handle everything around it: process payments, issue invoices, ship packages, send notifications, and interact with ERPs, without integrating dozens of regional APIs yourself.

Think of CodeSpar as the Stripe for AI agent money movement. Where Stripe unified web payments behind one API, CodeSpar unifies the rails the region actually uses -- Pix, boleto, Nota Fiscal, Correios, Mercado Envios, WhatsApp Business, and more -- behind one SDK call that any AI agent can invoke.

import { CodeSpar } from "@codespar/sdk";

const codespar = new CodeSpar({ apiKey: process.env.CODESPAR_API_KEY });
const session = await codespar.create("user_123", {
  servers: ["stripe", "mercadopago", "correios"],
});

const tools = await session.tools();
// 24 tools ready for your agent to call

CodeSpar is not another agent framework. It is the commerce layer that plugs into any agent framework -- Claude, OpenAI, Vercel AI SDK, or any MCP-compatible client. You keep your agent architecture; CodeSpar gives it the ability to transact.

Who is CodeSpar for?

AudienceWhat CodeSpar solvesTypical side
AI engineersShip money-movement features in hours instead of weeks. No need to learn Pix settlement, NF-e XML schemas, or carrier APIs.Both
Consumer / agent appsGive an agent a governed wallet and let it shop and pay for the user, inside caps the user signed.Buy
SaaS companiesAdd AI-powered commerce workflows to your product. Let your users' agents sell, invoice, and ship.Sell
Fintechs and ERPsExpose your services to AI agents via MCP without building your own tool layer.Both
AgenciesBuild commerce automations for clients across Latin America with a single integration.Both
Enterprise teamsCentralized governance, usage tracking, and billing across all agent money movement — procurement, payroll, treasury.Buy

What can you build?

Buy-side — the agent spends:

Use caseHow it worksMeta-tools used
Shopping agentSearches a real store, drives the checkout, pays the store's Pix from its governed walletcodespar_shop, codespar_wallet, codespar_pay
Contas a pagar / procurementAgent pays suppliers on schedule, every payment capped by the mandatecodespar_pay, codespar_ledger
Treasury under mandateMove balance between BRL and USDC slots of one wallet, no FX guessingcodespar_wallet
Bulk refundsRefund a batch of payments in parallel, partial failures handledcodespar_pay
Agent with a cardIssue a governed virtual card; every authorization checked server-sidecodespar_issue

Sell-side — the agent collects:

Use caseHow it worksMeta-tools used
AI sales agent on WhatsAppAgent charges via Pix and sends the receipt in the chatcodespar_charge, codespar_notify
Automated invoicingAgent issues the fiscal document after every salecodespar_invoice
Shipping automationAgent quotes carriers, creates labels, tracks packagescodespar_ship
Payment reconciliationAgent monitors incoming Pix, matches to orders, triggers fulfillmentcodespar_charge, codespar_ledger
Marketplace payoutsAgent settles vendors after a sale clearscodespar_pay
End-to-end commerceCharge, invoice, ship, notify — the full loop in one conversationcodespar_charge, codespar_invoice, codespar_ship, codespar_notify

Architecture

CodeSpar sits between your AI agent and every major LatAm commerce API. Both faces converge here: a buy-side spend and a sell-side charge enter the SAME router, hit the SAME mandate and policy gates, and land in the SAME audit ledger — the side only changes which meta-tool the agent calls. The architecture has four layers:

Your Agent (Claude, GPT, Gemini, LangChain, CrewAI, or any MCP client)
    |
    v
@codespar/sdk  <-- Framework adapters: claude, openai, vercel, langchain, google-genai, mastra, crewai, autogen, llama-index, letta, camel, mcp
    |
    v
CodeSpar API (api.codespar.dev)
    |                                  Routing, auth, usage tracking, billing
    v
MCP Server Catalog
    |
    +-- Payments:    Zoop, Asaas, Pagar.me, PagSeguro, Cielo, Stone, EFI, iugu, Vindi, EBANX, Mercado Pago, Conekta, Wompi
    +-- Fiscal:      Nuvem Fiscal, Focus NF-e, Facturapi, AFIP, Siigo
    +-- Logistics:   Melhor Envio, Correios, Skydropx, Andreani, Coordinadora
    +-- Messaging:   Z-API, Evolution API, Zenvia, Take Blip, RD Station
    +-- Banking:     Stark Bank, Inter, Nubank, Nequi, BCRA, Pix BCB, Open Finance, STP/SPEI
    +-- ERP:         Omie, Bling, Tiny, Conta Azul, Colppy, Alegra, Bind ERP, Belvo
    +-- E-Commerce:  VTEX, Mercado Libre, Tienda Nube
    +-- Crypto:      Mercado Bitcoin, Bitso, Circle
    +-- Protocols:   Stripe ACP, Google UCP, x402, AP2 (protocol scaffolds)
    +-- Data:        BrasilAPI

How it flows:

  1. Your agent receives a user request (e.g., "Create a R$49.90 checkout link for the Pro Plan").
  2. The adapter converts the agent's tool call into a CodeSpar SDK call.
  3. The SDK sends the request to api.codespar.dev, which authenticates, routes, and tracks usage.
  4. The API forwards the call to the appropriate MCP server (e.g., the Stripe MCP server).
  5. The MCP server executes the operation against the regional API and returns structured results.
  6. Results flow back through the stack to your agent, which presents them to the user.

You never interact with MCP servers directly. The 14 meta-tools abstract all server routing. Call codespar_charge and CodeSpar routes it to the right payment provider based on your session configuration.

The Complete Loop

Every agent interaction follows a consistent three-phase pattern we call the Complete Loop:

Discover

The agent calls codespar_discover to search the catalog for the right tool. The query is a natural-language string; results are ranked by semantic similarity and biased toward providers already connected to the session.

const result = await session.execute("codespar_discover", {
  query: "charge a buyer in BRL via Pix",
});
{
  "matches": [
    { "tool": "codespar_charge", "server": "asaas", "score": 0.91, "connected": true },
    { "tool": "codespar_charge", "server": "mercadopago", "score": 0.88, "connected": true }
  ]
}

Execute

The agent calls the appropriate meta-tool. CodeSpar routes the request to the correct MCP server based on the session's server configuration.

const result = await session.execute("codespar_charge", {
  method: "pix",
  amount: 4990,
  currency: "BRL",
  description: "Pro Plan",
});
{
  "payment_id": "pay_abc123",
  "pix_code": "00020126580014br.gov.bcb.pix...",
  "qr_code_url": "https://api.codespar.dev/qr/pay_abc123.png",
  "amount": 4990,
  "currency": "BRL",
  "status": "pending"
}

Confirm

CodeSpar returns structured results. The agent can present them to the user, chain into the next step (e.g., send the Pix code via WhatsApp), or store them for later reference.

// Chain: send the Pix code via WhatsApp
const notification = await session.execute("codespar_notify", {
  channel: "whatsapp",
  to: "+5511999887766",
  template: "pix_charge",
  variables: {
    customer_name: "Maria",
    pix_code: result.pix_code,
    amount: "R$49.90",
  },
});

The 14 Meta-Tools

Meta-tools are high-level operations that abstract the underlying MCP servers. Instead of calling provider-specific endpoints, your agent calls a meta-tool and CodeSpar handles the routing. They split by the side your agent plays — the same grouping you see in the sidebar.

Your agent buys — the agent spends, under a signed mandate

Meta-toolPurposeExample operation
codespar_shopSearch and buy from real stores; async checkout session to the store's payable Pix"Find dog food under R$100 and buy the best one"
codespar_walletThe agent's governed funds: balance, statement, top-up; per-currency slots"Show the wallet balance in BRL and USDC"
codespar_payOutbound spend — money leaves the wallet the agent governs"Pay R$1,500 to the supplier via Pix"
codespar_crypto_payOn-chain spend and cross-border ramps (testnet today)"Pay 25 USDC to this 0x address"
codespar_issueSpend cards bound to the same mandate governance"Issue a virtual card for the travel agent"

Your agent sells — the agent collects, as the merchant

Meta-toolPurposeExample operation
codespar_checkoutAssemble a cart and dispatch it as a charge with a hosted payment page"Create a R$99 checkout for the Pro Plan"
codespar_chargeInbound charges — the buyer pays you"Generate a Pix QR code for R$250"
codespar_invoiceFiscal documents (NFS-e default; NF-e, CFDI, Factura AR)"Issue the invoice for order #1234"
codespar_shipQuote, label, and track shipments"Ship 2kg from SP to RJ"
codespar_notifyMessages via WhatsApp, SMS, email"Send the order confirmation via WhatsApp"
codespar_kycVerify counterparties before money moves"Verify this customer before the payout"

Shared rails — both sides, no money direction

Meta-toolPurposeExample operation
codespar_ledgerDouble-entry books + the signed agentic receipts"List this month's entries for the escrow account"
codespar_discoverSemantic search across the catalog"Find tools that charge in BRL via Pix"
codespar_manage_connectionsProviders, credentials, and shopper identity"Connect WhatsApp for notifications"

See Tools and Meta-Tools for the full reference, including input schemas and response formats for each meta-tool.

Platform at a glance

  • Every major LatAm commerce API covered as an MCP server — payments, fiscal, logistics, messaging, banking, ERP, e-commerce, crypto, public data, and agentic commerce protocols
  • 14 meta-tools that abstract all server routing and provide a consistent interface across 60+ catalog rails
  • Every major agent framework supported — Claude, OpenAI, Vercel AI SDK, LangChain, Google Gemini, Mastra, CrewAI, AutoGen, LlamaIndex, Letta, CAMEL-AI, plus raw MCP
  • One SDK@codespar/sdk on npm, with a single session model for all operations
  • Published under @codespar — every server and adapter available as its own npm package
  • Two environmentscsk_test_ keys for sandbox with mock data, csk_live_ for production

Getting Started

Introduction | CodeSpar