Skip to content

procohq/examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

procohq/examples

Ready-to-run examples for building payment-enabled AI agents with Proco.

This repo contains practical examples showing how to wire up Proco payments in the most popular agent frameworks — from a single-agent LangChain tool to multi-agent CrewAI workflows with shared budgets.


Prerequisites

npm install @proco/sdk

You'll need a Proco API key. Get one at procohq.com/sign-in — or use the sandbox for free testnet USDC.

export PROCO_API_KEY=sk_sandbox_...

Examples

1. Basic payment

The simplest possible Proco integration — create a wallet and execute a payment.

// examples/basic/index.ts
import { Proco } from '@proco/sdk'

const proco = new Proco({ apiKey: process.env.PROCO_API_KEY, env: 'sandbox' })

const wallet = await proco.wallets.create({
  agentId: 'demo-agent',
  policies: { dailyCap: 10_00, currency: 'USDC' }
})

const tx = await proco.payments.create({
  wallet: wallet.id,
  amount: 1_00,
  vendor: 'api.example.com',
  memo:   'demo payment'
})

console.log(`✓ Payment ${tx.id} settled in ${tx.settlementMs}ms`)

2. x402 native fetch

Use proco.fetch() to call any x402-compatible API. Payment is handled automatically when the server responds with HTTP 402.

// examples/x402-fetch/index.ts
import { Proco } from '@proco/sdk'

const proco = new Proco({ apiKey: process.env.PROCO_API_KEY, env: 'sandbox' })

const wallet = await proco.wallets.create({
  agentId: 'x402-agent',
  policies: { dailyCap: 20_00, currency: 'USDC' }
})

// Proco intercepts the 402, pays, and returns the 200 response
const res = await proco.fetch('https://api.x402-demo.com/data', {
  wallet: wallet.id
})

const data = await res.json()
console.log('Response:', data)

3. LangChain agent with payment tool

Adds Proco as a LangChain tool so your agent can pay for APIs as part of a reasoning chain.

// examples/langchain/agent.ts
import { ChatOpenAI } from '@langchain/openai'
import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents'
import { ProcoPaymentTool } from '@proco/sdk/langchain'
import { Proco } from '@proco/sdk'
import { pull } from 'langchain/hub'

const proco = new Proco({ apiKey: process.env.PROCO_API_KEY, env: 'sandbox' })

const wallet = await proco.wallets.create({
  agentId: 'langchain-research-agent',
  policies: {
    dailyCap:   50_00,
    vendors:    ['api.perplexity.ai', 'serper.dev'],
    currency:   'USDC'
  }
})

const tools = [
  new ProcoPaymentTool({ wallet: wallet.id, proco }),
]

const llm    = new ChatOpenAI({ model: 'gpt-4o', temperature: 0 })
const prompt = await pull('hwchase17/openai-functions-agent')
const agent  = await createOpenAIFunctionsAgent({ llm, tools, prompt })

const executor = new AgentExecutor({ agent, tools, verbose: true })

const result = await executor.invoke({
  input: 'Research the latest AI agent papers and pay for any paywalled queries'
})

console.log(result.output)

4. CrewAI with shared procurement budget

# examples/crewai/crew.py
import os, requests
from crewai import Agent, Task, Crew

PROCO_API_KEY = os.environ['PROCO_API_KEY']
PROCO_BASE    = 'https://sandbox.api.procohq.com/v1'

def create_wallet(agent_id: str, daily_cap_cents: int) -> str:
    res = requests.post(f'{PROCO_BASE}/wallets', json={
        'agentId': agent_id,
        'policies': { 'dailyCap': daily_cap_cents, 'currency': 'USDC' }
    }, headers={ 'Authorization': f'Bearer {PROCO_API_KEY}' })
    return res.json()['id']

researcher_wallet = create_wallet('crewai-researcher', 30_00)

researcher = Agent(
    role='Market Researcher',
    goal='Find data on competitor pricing',
    backstory='Expert at sourcing market intelligence',
    tools=[]
)

task = Task(
    description='Research competitor pricing',
    expected_output='Structured pricing comparison',
    agent=researcher
)

crew   = Crew(agents=[researcher], tasks=[task], verbose=True)
result = crew.kickoff()
print(result)

5. AutoGen multi-agent settlement

// examples/autogen/settlement.ts
import { Proco } from '@proco/sdk'

const proco = new Proco({ apiKey: process.env.PROCO_API_KEY, env: 'sandbox' })

const orchestratorWallet = await proco.wallets.create({ agentId: 'orchestrator' })
const workerWallet       = await proco.wallets.create({ agentId: 'worker-01' })

const invoice = await proco.invoices.create({
  from:        workerWallet.agentId,
  to:          orchestratorWallet.agentId,
  amount:      5_00,
  description: 'Document extraction — 12 files'
})

const settlement = await proco.invoices.settle(invoice.id, {
  wallet: orchestratorWallet.id
})

console.log(`✓ Settled: ${settlement.txHash}`)

6. Policy enforcement demo

// examples/policy-enforcement/index.ts
import { Proco, PolicyViolationError } from '@proco/sdk'

const proco = new Proco({ apiKey: process.env.PROCO_API_KEY, env: 'sandbox' })

const wallet = await proco.wallets.create({
  agentId: 'policy-demo-agent',
  policies: { dailyCap: 5_00, perTx: 2_00 }
})

try {
  await proco.payments.create({
    wallet: wallet.id,
    amount: 10_00,
    vendor: 'expensive-api.com'
  })
} catch (e) {
  if (e instanceof PolicyViolationError) {
    console.log('Payment blocked:', e.reason)
    // → 'Payment blocked: exceeds daily cap ($5.00)'
  }
}

Running the examples

git clone https://github.com/procohq/examples
cd examples
npm install

export PROCO_API_KEY=sk_sandbox_...

npx ts-node examples/basic/index.ts
npx ts-node examples/langchain/agent.ts
npx ts-node examples/x402-fetch/index.ts

Getting a sandbox key

  1. Go to procohq.com/sandbox
  2. Create a sandbox account — no credit card required
  3. Your wallet starts with 1,000 testnet USDC

Contributing

Have a framework integration we're missing? Open a PR.

  1. Fork this repo
  2. Add your example under examples/<framework-name>/
  3. Include a README.md explaining prerequisites and how to run
  4. Open a pull request

Related


MIT · Built by Proco

About

Examples and templates for building with Proco — programmable wallets, conditions, settlement, treasury automation. MCP, SDK, and framework integrations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors