Skip to main content

Introduction

Commerce infrastructure for AI agents in Latin America. Every commerce API, one SDK.

1 min read · updated
Documentation@codespar/sdk v0.9.0

Commerce infrastructure for AI agents in Latin America.

Every LatAm commerce API — payments, fiscal, logistics, messaging — behind one SDK and nine meta-tools. Your agent keeps its architecture; CodeSpar gives it the ability to transact.

What is CodeSpar?

CodeSpar is commerce infrastructure for AI agents in Latin America. We provide a single SDK and a unified session model that lets your AI agents 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 commerce. Where Stripe unified web payments behind one API, CodeSpar unifies the entire Latin American commerce stack -- 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 solves
AI engineersShip commerce features in hours instead of weeks. No need to learn Pix settlement, NF-e XML schemas, or carrier APIs.
SaaS companiesAdd AI-powered commerce workflows to your product. Let your users' agents sell, invoice, and ship.
Fintechs and ERPsExpose your services to AI agents via MCP without building your own tool layer.
AgenciesBuild commerce automations for clients across Latin America with a single integration.
Enterprise teamsCentralized governance, usage tracking, and billing across all agent commerce operations.

What can you build?

Use caseHow it worksMeta-tools used
AI sales agent on WhatsAppAgent discovers tools, charges via Pix, sends receiptcodespar_discover, codespar_charge, codespar_notify
Automated invoicingAgent issues Nota Fiscal (NFS-e default, or NF-e for products) after every salecodespar_invoice
Shipping automationAgent quotes carriers, creates labels, tracks packages via Melhor Enviocodespar_ship
Payment reconciliationAgent monitors incoming Pix, matches to orders, triggers fulfillmentcodespar_charge, codespar_discover
Marketplace payoutsAgent settles vendors after a sale clearscodespar_pay
Multi-channel notificationsAgent sends order updates via WhatsApp, SMS, and emailcodespar_notify
End-to-end commerceAgent handles the full loop: charge, invoice, ship, notifycodespar_charge, codespar_invoice, codespar_ship, codespar_notify

Architecture

CodeSpar sits between your AI agent and every major LatAm commerce API. 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, Celcoin, 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, UnblockPay
    +-- Protocols:   Stripe ACP, Google UCP, x402, AP2
    +-- 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 9 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 9 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.

Meta-toolPurposeExample operation
codespar_discoverSemantic search across the catalog for tools and servers"Find tools that charge in BRL via Pix"
codespar_manage_connectionsInspect connected providers and start connection flows"Connect Z-API for WhatsApp"
codespar_payOutbound transfers — payouts to recipients"Pay R$1,500 to vendor via Pix"
codespar_chargeInbound charges — buyer pays merchant"Generate a Pix QR code for R$250"
codespar_invoiceIssue fiscal documents (NFS-e default; NF-e, CFDI, Factura AR)"Issue an NF-e for order #1234"
codespar_shipQuote, label, and track via Melhor Envio"Ship 2kg from SP to RJ"
codespar_notifySend messages via WhatsApp, SMS, email"Send order confirmation via WhatsApp"
codespar_crypto_payCrypto payments via Coinbase Commerce or Bitso"Pay 0.05 ETH to vendor wallet"
codespar_kycIdentity verification via Persona, Sift, Konduto, Truora"Verify customer ID before high-value payout"

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
  • 9 meta-tools that abstract all server routing and provide a consistent interface across 53 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

Edit on GitHub

Last updated on