Introduction
Commerce infrastructure for AI agents in Latin America. Every commerce API, one SDK.
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.sessions.create({
servers: ["stripe", "mercadopago", "correios"],
});
const tools = await session.tools();
// 24 tools ready for your agent to callCodeSpar 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?
| Audience | What CodeSpar solves |
|---|---|
| AI engineers | Ship commerce features in hours instead of weeks. No need to learn Pix settlement, NF-e XML schemas, or carrier APIs. |
| SaaS companies | Add AI-powered commerce workflows to your product. Let your users' agents sell, invoice, and ship. |
| Fintechs and ERPs | Expose your services to AI agents via MCP without building your own tool layer. |
| Agencies | Build commerce automations for clients across Latin America with a single integration. |
| Enterprise teams | Centralized governance, usage tracking, and billing across all agent commerce operations. |
What can you build?
| Use case | How it works | Meta-tools used |
|---|---|---|
| AI sales agent on WhatsApp | Agent discovers products, creates checkout links, processes Pix payments, sends receipt | codespar_discover, codespar_checkout, codespar_notify |
| Automated invoicing | Agent issues Nota Fiscal (NF-e) after every sale via fiscal MCP servers | codespar_invoice |
| Shipping automation | Agent quotes carriers, creates shipping labels, tracks packages | codespar_ship |
| Payment reconciliation | Agent monitors incoming Pix, matches to orders, triggers fulfillment | codespar_pay, codespar_discover |
| Multi-channel notifications | Agent sends order updates via WhatsApp, SMS, and email | codespar_notify |
| End-to-end commerce | Agent handles the full loop: checkout, payment, invoice, shipping, notification | All 6 meta-tools |
Architecture
CodeSpar sits between your AI agent and 57 regional commerce APIs. The architecture has four layers:
Your Agent (Claude, GPT, Gemini, LangChain, CrewAI, or any MCP client)
|
v
@codespar/sdk <-- 12 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
57 MCP Servers
|
+-- 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: BrasilAPIHow it flows:
- Your agent receives a user request (e.g., "Create a R$49.90 checkout link for the Pro Plan").
- The adapter converts the agent's tool call into a CodeSpar SDK call.
- The SDK sends the request to
api.codespar.dev, which authenticates, routes, and tracks usage. - The API forwards the call to the appropriate MCP server (e.g., the Stripe MCP server).
- The MCP server executes the operation against the regional API and returns structured results.
- Results flow back through the stack to your agent, which presents them to the user.
You never interact with MCP servers directly. The 6 meta-tools abstract all server routing. Call codespar_checkout 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 find available tools for a given commerce domain. This is how the agent learns what it can do.
const result = await session.execute({
name: "codespar_discover",
arguments: { domain: "payments" },
});{
"domain": "payments",
"servers": ["stripe", "mercadopago", "asaas", "pagarme"],
"tools": [
{ "name": "codespar_checkout", "description": "Create a checkout session for a product or service" },
{ "name": "codespar_pay", "description": "Process a payment via Pix, boleto, or card" }
],
"capabilities": ["pix", "boleto", "credit_card", "checkout_link"]
}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({
name: "codespar_checkout",
arguments: {
provider: "stripe",
amount: 4990,
currency: "BRL",
description: "Pro Plan",
payment_methods: ["pix", "card"],
},
});{
"checkout_id": "chk_abc123",
"url": "https://checkout.stripe.com/c/pay/cs_live_...",
"amount": 4990,
"currency": "BRL",
"status": "open",
"expires_at": "2026-04-15T23:59:59Z"
}Confirm
CodeSpar returns structured results. The agent can present them to the user, chain into the next step (e.g., send the checkout link via WhatsApp), or store them for later reference.
// Chain: send the checkout link via WhatsApp
const notification = await session.execute({
name: "codespar_notify",
arguments: {
channel: "whatsapp",
to: "+5511999887766",
template: "checkout_link",
variables: {
customer_name: "Maria",
checkout_url: result.url,
amount: "R$49.90",
},
},
});The 6 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-tool | Purpose | Example operation |
|---|---|---|
codespar_discover | Find available tools and capabilities by domain | "What payment methods are available?" |
codespar_checkout | Create checkout sessions and payment links | "Create a R$99 checkout link via Stripe" |
codespar_pay | Process payments (Pix, boleto, card) | "Generate a Pix QR code for R$250" |
codespar_invoice | Issue fiscal documents (NF-e, NFS-e) | "Issue an NF-e for order #1234" |
codespar_ship | Quote carriers, create labels, track packages | "Ship 2kg from SP to RJ via Correios" |
codespar_notify | Send messages via WhatsApp, SMS, email | "Send order confirmation via WhatsApp" |
See Tools and Meta-Tools for the full reference, including input schemas and response formats for each meta-tool.
Key Numbers
- 57 MCP servers across 10 domains: payments, fiscal, logistics, messaging, banking, ERP, e-commerce, crypto, public data, and agentic commerce protocols
- 6 meta-tools that abstract all server routing and provide a consistent interface
- 12 framework adapters -- Claude, OpenAI, Vercel AI SDK, LangChain, Google Gemini, Mastra, CrewAI, AutoGen, LlamaIndex, Letta, CAMEL-AI, and MCP
- 1 SDK --
@codespar/sdk@0.2.0on npm, with a single session model for all operations - 71 packages on npm under the
@codesparscope - 2 environments --
csk_test_keys for sandbox with mock data,csk_live_for production
Getting Started
Quickstart
Install the SDK, create a session, and make your first tool call in under 5 minutes
Sessions
Understand the session lifecycle, server selection, and scoping model
Tools and Meta-Tools
Learn how the 6 meta-tools work and what each one does
Claude Adapter
Build a commerce agent with the Anthropic Claude SDK
OpenAI Adapter
Integrate commerce tools with GPT-4o and the OpenAI SDK
Vercel AI SDK
Streaming-first commerce agents for Next.js applications
MCP
Use CodeSpar tools in Claude Desktop, Cursor, and other MCP clients
Authentication
API keys, environments, and security model