TL;DR

  • → AgentGen turns HTML templates into downloadable PDF invoices via a single POST request
  • → Works as a tool in any AI agent framework — LangChain, OpenAI, AutoGen, CrewAI
  • → 2 tokens per page (~$0.03 at Growth tier). No subscription, tokens never expire

AI Agent Invoice Generator

AI agents are great at collecting information — but delivering a professional PDF invoice at the end of a conversation is where most agents fall flat. AgentGen closes that gap: give your agent a single tool call and it can produce a pixel-perfect, downloadable invoice in under 2 seconds.

Why HTML → PDF for invoices?

HTML is the natural output format for LLMs. Your agent can write or template HTML directly, inject dynamic data (client name, line items, due date), and hand it to AgentGen for rendering. The result is identical every time — no PDF libraries, no layout wrestling, no operating-system font dependencies.

Step 1 — Define your invoice template

Write a Python function that maps invoice data to styled HTML. Using inline styles ensures Chromium renders it identically regardless of environment:

def build_invoice_html(data: dict) -> str:
    rows = "".join(
        f"""<tr>
          <td style="padding:8px 0;border-bottom:1px solid #f3f4f6">{item['desc']}</td>
          <td style="padding:8px 0;text-align:right;border-bottom:1px solid #f3f4f6">{item['qty']}</td>
          <td style="padding:8px 0;text-align:right;font-weight:600;border-bottom:1px solid #f3f4f6">
            ${item['qty'] * item['price']:.2f}
          </td>
        </tr>"""
        for item in data["line_items"]
    )
    return f"""<!DOCTYPE html>
    <html><head><meta charset="UTF-8"></head>
    <body style="font-family:'Helvetica Neue',sans-serif;padding:48px;color:#111">
      <div style="display:flex;justify-content:space-between;margin-bottom:40px">
        <h1 style="margin:0;font-size:24px">Invoice #{data['number']}</h1>
        <p style="color:#6b7280">{data['date']}</p>
      </div>
      <p>Bill to: <strong>{data['client']}</strong></p>
      <table style="width:100%;border-collapse:collapse;margin:24px 0">
        <thead>
          <tr style="border-bottom:2px solid #e5e7eb;text-align:left">
            <th style="padding-bottom:8px">Description</th>
            <th style="padding-bottom:8px;text-align:right">Qty</th>
            <th style="padding-bottom:8px;text-align:right">Total</th>
          </tr>
        </thead>
        <tbody>{rows}</tbody>
      </table>
      <p style="font-size:22px;font-weight:800;color:#4f46e5;text-align:right">
        Total: ${data['total']:.2f}
      </p>
      <p style="color:#9ca3af;font-size:12px;margin-top:40px">
        Due: {data['due_date']} · Thank you for your business.
      </p>
    </body></html>"""

Step 2 — Call the AgentGen API

import os, requests

def generate_invoice_pdf(data: dict) -> str:
    """Generate a PDF invoice and return a CDN download URL."""
    html = build_invoice_html(data)
    response = requests.post(
        "https://www.agent-gen.com/api/v1/generate/pdf",
        headers={
            "X-API-Key": os.environ["AGENTGEN_API_KEY"],
            "Content-Type": "application/json",
        },
        json={"html": html, "format": "A4"},
        timeout=30,
    )
    response.raise_for_status()
    return response.json()["url"]  # permanent CDN link

Step 3 — Register as a LangChain tool

from pydantic import BaseModel, Field
from langchain_core.tools import StructuredTool
from typing import List

class LineItem(BaseModel):
    desc: str
    qty: int
    price: float

class InvoiceInput(BaseModel):
    number: str = Field(description="Invoice number, e.g. INV-001")
    client: str = Field(description="Client or company name")
    date: str = Field(description="Invoice date")
    due_date: str = Field(description="Payment due date")
    line_items: List[LineItem]

def _create_invoice(number, client, date, due_date, line_items) -> dict:
    items = [i.dict() if hasattr(i, "dict") else i for i in line_items]
    total = sum(i["qty"] * i["price"] for i in items)
    url = generate_invoice_pdf({
        "number": number, "client": client, "date": date,
        "due_date": due_date, "line_items": items, "total": total,
    })
    return {"pdf_url": url, "total": total}

invoice_tool = StructuredTool.from_function(
    func=_create_invoice,
    name="create_invoice",
    description="Generate a professional PDF invoice. Returns a download URL. Cost: 2 tokens.",
    args_schema=InvoiceInput,
)

Step 4 — Use it in an agent

from langchain_anthropic import ChatAnthropic
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate

llm = ChatAnthropic(model="claude-opus-4-6", temperature=0)
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are an invoicing assistant. Collect invoice details and generate a PDF."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

executor = AgentExecutor(
    agent=create_tool_calling_agent(llm, [invoice_tool], prompt),
    tools=[invoice_tool],
    verbose=True,
)

result = executor.invoke({
    "input": "Invoice Acme Corp $5,000 for consulting work in March, due April 15"
})
print(result["output"])
# → "Here's your invoice: https://cdn.agent-gen.com/output/abc123.pdf"

Pricing

Each one-page invoice costs 2 tokens. At the Growth tier ($39 for 2,500 tokens) that's ~1,250 invoices for $39 — about 3 cents each. Tokens never expire, so unused balance carries over forever.

Start generating invoices today

Create a free account and get 50 tokens instantly. No credit card required.