Skip to content

AI Agents Integration

thelawin.dev works well with AI agents. The API is stateless and JSON-based, so any agent that can make HTTP requests can generate invoices.

3 Ways to Integrate

MethodBest forSetup
MCP ServerClaude Code, MCP-capable clientsClone from GitHub
REST API + curlAny agent with HTTP accessNo setup, start immediately
SDKsAgents in Python, TypeScript, etc.Install SDK

The Model Context Protocol server gives Claude Code (and other MCP clients) two tools: thelawin_generate and thelawin_validate.

Installation

bash
git clone https://github.com/steviee/thelawin.dev.git
cd thelawin.dev/mcp-server
npm install && npm run build

Configuration for Claude Code

Add to your Claude Code MCP config:

json
{
  "mcpServers": {
    "thelawin": {
      "command": "node",
      "args": ["/path/to/thelawin.dev/mcp-server/dist/index.js"],
      "env": {
        "THELAWIN_API_KEY": "env_sandbox_demo"
      }
    }
  }
}

Without MCP Server

You can also use thelawin.dev without the MCP server, directly via REST API (curl) or SDKs.

Natural Language → Invoice

After setup, Claude Code can generate invoices from natural language:

"Create a ZUGFeRD invoice for 8 hours of consulting at 150 EUR from Acme GmbH to Customer AG"

Claude automatically uses the thelawin_generate tool and returns the PDF.

REST API with curl

Any agent that can execute HTTP requests can use thelawin.dev. The demo key env_sandbox_demo works immediately without an account.

Minimal Invoice

bash
curl -s -X POST https://api.thelawin.dev/v1/generate \
  -H "Content-Type: application/json" \
  -H "X-API-Key: env_sandbox_demo" \
  -d '{
    "format": "zugferd",
    "template": "minimal",
    "invoice": {
      "number": "RE-2026-001",
      "date": "2026-01-15",
      "seller": {"name": "Acme GmbH", "country": "DE", "vat_id": "DE123456789"},
      "buyer": {"name": "Customer AG", "country": "DE"},
      "items": [{"description": "Beratung", "quantity": 8, "unit": "HUR", "unit_price": 150}]
    }
  }'

Save PDF

bash
curl -s -X POST https://api.thelawin.dev/v1/generate \
  -H "Content-Type: application/json" \
  -H "X-API-Key: env_sandbox_demo" \
  -d '{"invoice":{"number":"001","date":"2026-01-15","seller":{"name":"Test GmbH"},"buyer":{"name":"Kunde AG"},"items":[{"description":"Service","quantity":1,"unit_price":100}]}}' \
  | jq -r '.pdf_base64' | base64 -d > rechnung.pdf

Pre-validation (free)

bash
curl -s -X POST https://api.thelawin.dev/v1/validate \
  -H "Content-Type: application/json" \
  -H "X-API-Key: env_sandbox_demo" \
  -d '{"format":"xrechnung","invoice":{"number":"XR-001","date":"2026-01-15","leitweg_id":"04011000-12345-67","seller":{"name":"GmbH","vat_id":"DE123"},"buyer":{"name":"Amt"},"items":[{"description":"Lizenz","quantity":1,"unit_price":1000}]}}' \
  | jq '.valid, .format'

Extract Data from PDF

bash
PDF_BASE64=$(base64 < rechnung.pdf)
curl -s -X POST https://api.thelawin.dev/v1/retrieve \
  -H "Content-Type: application/json" \
  -H "X-API-Key: env_sandbox_demo" \
  -d "{\"data_base64\": \"$PDF_BASE64\"}" \
  | jq '.invoice'

SDKs for Agent Frameworks

Python (LangChain, CrewAI, AutoGen)

python
from thelawin import ThelawinClient

client = ThelawinClient("env_sandbox_demo")

result = (
    client.invoice()
    .number("RE-2026-001")
    .date("2026-01-15")
    .format("zugferd")
    .seller("Acme GmbH", vat_id="DE123456789", city="Berlin", country="DE")
    .buyer("Customer AG", city="Muenchen", country="DE")
    .add_item("Beratung", quantity=8, unit_price=150, unit="HUR")
    .generate()
)

if result.success:
    result.save_pdf("rechnung.pdf")
bash
pip install git+https://github.com/steviee/thelawin-clients.git#subdirectory=python

TypeScript (Vercel AI SDK, LlamaIndex)

typescript
import { ThelawinClient } from '@thelawin/sdk';

const client = new ThelawinClient('env_sandbox_demo');

const result = await client.invoice()
  .number('RE-2026-001')
  .date('2026-01-15')
  .format('zugferd')
  .seller({ name: 'Acme GmbH', vatId: 'DE123456789', city: 'Berlin', country: 'DE' })
  .buyer({ name: 'Customer AG', city: 'Munich', country: 'DE' })
  .addItem({ description: 'Consulting', quantity: 8, unit: 'HUR', unitPrice: 150 })
  .generate();
bash
npm install github:steviee/thelawin-clients#path:typescript

Supported Formats

FormatDescriptionRegion
zugferdPDF/A-3 + CII XMLGermany
facturxPDF/A-3 + CII XMLFrance
xrechnungPDF/A-3 + UBL XMLGermany B2G
peppolXML (UBL-based)EU/international
fatturapaXMLItaly
ublXMLOASIS standard
ciiXMLUN/CEFACT
pdfPlain PDFUniversal
autoAuto-detectEU

API Key for Production

The demo key (env_sandbox_demo) adds a SANDBOX watermark. For production use:

  1. Sign up (free)
  2. Dashboard → API Keys → Create key
  3. Sandbox keys (env_sandbox_*): 0 credits included, free (buy credit packs for clean PDFs)
  4. Live keys (env_live_*): From 9.50 EUR/month, no watermark

Next Steps

ZUGFeRD 2.4 & Factur-X 1.0.8 compliant