• agents
  • llms-txt
  • api
  • mcp

Build receipt printing with an AI agent: llms.txt, OpenAPI and scoped keys

How a coding agent reads Tillcast, signs in with a scoped key and builds an integration without real paper.

An AI coding agent can build a Tillcast integration today from public text: an llms.txt file, a Markdown copy of every docs page, the OpenAPI document and the SDK packages. It signs in with a restricted API key that a person makes in the dashboard, and it calls the REST API or an SDK. This post shows what the agent reads, how to hand it a key safely, and how to test its work without a printer.

What an agent can read

Tillcast treats what an agent reads as part of the product. These are the sources:

  • tillcast.com/llms.txt states the facts in plain text: how to create a job and how to set up printers for customers.
  • docs.tillcast.com/llms.txt is the index of the documentation. Every docs page also has a Markdown copy: add .md to its address, as in docs.tillcast.com/create-a-print-job.md. Each copy starts with a short directive for agents.
  • api.tillcast.com/openapi.json is the OpenAPI document of the API. The documentation’s own address, docs.tillcast.com/openapi.json, redirects to it.
  • The SDKs, @tillcast/sdk for TypeScript and tillcast for Python, are pre-1.0, so an agent should pin the version.
  • The docs search server at docs.tillcast.com/_mcp/server is an MCP server run by the documentation host. It searches the docs.
  • Tillcast’s own MCP server at https://api.tillcast.com/mcp gives an AI assistant the API’s tools, with the same restricted key. What is MCP? says which assistants connect to it and how.
  • The docs page Build with an agent has a snippet for an AGENTS.md file and prompts to start from.

The website itself is open to robots: robots.txt allows everything and names the sitemap.

How an agent integrates Tillcast today. It reads, it writes code, and the code calls the REST API or an SDK with a key a person made.An AI agent reads Tillcast's public text, writes code that calls the REST API or an SDK with a restricted API key that a person made, and tests it against a fake client and the offline renderer. In production the job is queued, the printer polls and prints it.AI agentwrites the codellms.txtwhat Tillcast is1OpenAPIthe API contract2REST APIyour code calls it3MCP servertools, with a keyJob queuequeued4Printerprints56the code reads the status
  1. The agent reads tillcast.com/llms.txt and the Markdown copy of a docs page.
  2. It reads the OpenAPI document at api.tillcast.com/openapi.json.
  3. It writes code that calls the REST API or an SDK with a restricted API key that a person made in the dashboard, and tests that code against a fake client and the offline renderer, never against the live API.
  4. In production the code creates the job: POST /v1/printers/{printer}/jobs with a document of blocks and an Idempotency-Key. The job is queued.
  5. The printer asks for work, receives the job and prints it.
  6. The code reads the job and sees its status: printed, failed, expired or cancelled.
How an agent integrates Tillcast today. It reads, it writes code, and the code calls the REST API or an SDK with a key a person made. An AI agent reads Tillcast's public text, writes code that calls the REST API or an SDK with a restricted API key that a person made, and tests it against a fake client and the offline renderer. In production the job is queued, the printer polls and prints it.

What the agent should be told

The facts an agent needs fit in a few sentences, and they are in llms.txt already:

  • Create a job with POST https://api.tillcast.com/v1/printers/{printer}/jobs, with a key that has the scope jobs:write.
  • The body carries document, an array of blocks, or receiptline, ReceiptLine text. Send exactly one of the two. Blocks are the recommended way.
  • The nine block types are text, row, table, rule, image, barcode, qr, cut and feed. The text of a block prints as it is written, so it needs no escaping.
  • Send an Idempotency-Key with every job. A job is queued, delivered and printed; it can also fail, expire or be cancelled.

When the agent is unsure, the rule is to verify against llms.txt and the docs, which are the source of truth.

How the agent signs in

With an API key, sent as Authorization: Bearer <key>. A person makes the key in the dashboard, under API keys, and chooses what it may do, resource by resource. Only a hash of the key is stored and the key is shown once, so it goes straight into an environment variable and never into code or a prompt.

Scope Allows
jobs:write Create and cancel jobs, and queue a test print
jobs:read Read jobs
printers:read Read printers and their status
printers:write Add, change, move and delete printers, and rotate a printer’s secret
customers:read, customers:write Read, create and change customers and locations

An agent that only prints needs jobs:write, plus jobs:read if it should read the result. A key made for printing cannot read your customers, and a key may be limited to one customer. An agent should not make keys, customers or printers on its own: a person makes the keys in the dashboard, and a person types a printer’s URL into the printer. If an agent leaks a key, revoke it in the dashboard.

An example: print a bill

You give the agent a task and the rules that keep it off real paper:

Add receipt printing to our order service.
- Read https://tillcast.com/llms.txt, then https://docs.tillcast.com/create-a-print-job.md.
- Use the Tillcast SDK. Send "document" blocks, not "receiptline".
- One Idempotency-Key for each print you intend: order-<id>-bill.
- Pass maxRetries 0 (max_retries 0 in Python) and keep the key in an environment variable.
- Do not create API keys, customers or printers.
- Do not call the live API, create a job or open a printer URL. Test with a fake client.

It should come back with something like this. The function builds the document from your own list of order lines, in a loop, and sends the whole receipt as one job:

Choose a language
export function billDocument(order) {
  return [
    { type: "text", text: "Harbour Cafe", align: "center", bold: true, size: 2 },
    { type: "text", text: `Table ${order.table}`, align: "center" },
    {
      type: "table",
      columns: ["*", { width: 9, align: "right" }],
      rows: [
        ...order.lines.map((line) => [line.name, line.price]),
        { type: "rule" },
        [{ text: "Total", bold: true }, { text: order.total, bold: true }],
      ],
    },
  ];
}

export function printBill(client, printerId, order) {
  return client.jobs.create(
    {
      printer: printerId,
      "Idempotency-Key": `order-${order.id}-bill`,
      document: billDocument(order),
      client_reference_id: `order-${order.id}`,
    },
    { maxRetries: 0 },
  );
}
def bill_document(order):
    return [
        {"type": "text", "text": "Harbour Cafe", "align": "center", "bold": True, "size": 2},
        {"type": "text", "text": f"Table {order['table']}", "align": "center"},
        {
            "type": "table",
            "columns": ["*", {"width": 9, "align": "right"}],
            "rows": [
                *[[line["name"], line["price"]] for line in order["lines"]],
                {"type": "rule"},
                [{"text": "Total", "bold": True}, {"text": order["total"], "bold": True}],
            ],
        },
    ]


def print_bill(client, printer_id, order):
    return client.jobs.create(
        printer=printer_id,
        idempotency_key=f"order-{order['id']}-bill",
        document=bill_document(order),
        client_reference_id=f"order-{order['id']}",
        request_options={"max_retries": 0},
    )

The SDKs retry a 408, 429 or 5xx answer on their own (the Python SDK also a 409) and wait for Retry-After inside the call, which is why the prompt asks for no retries inside a request handler. They do not retry a timeout or a dropped connection, because the job may already exist. The code should record the print before the call, and on a timeout send the same request again with the same key and the same body.

How the agent tests without a printer

Every key is live and a job made with it prints on a real printer. Creating a job and cancelling it at once is not a test, because a printer takes a job within about 5 seconds, so the agent tests offline.

What an agent can do is check the document offline. @tillcast/html-render is the same renderer the service uses, compiled to WebAssembly. In Node it draws a document as text, as it would print, and with the profile of your printer it returns the warnings the job would have. It does not know how large the printer’s output will be, so a document that is too large for a job (413 rendered_too_large) can pass here and be refused by the API. Save the TypeScript module above as print-bill.mjs (it has no type annotations, so it runs as plain JavaScript) and the test below as print-bill.test.mjs, run npm install @tillcast/html-render, then node --test. The renderer needs Node 20.19 or 22.12 or later. The test uses a fake client for the call and the renderer for the paper:

import assert from "node:assert/strict";
import { test } from "node:test";
import { createRendererSync, isError } from "@tillcast/html-render";
import { billDocument, printBill } from "./print-bill.mjs";

const order = {
  id: "4711",
  table: "7",
  lines: [{ name: "Flat white", price: "3.40" }, { name: "Lemon cake", price: "4.20" }],
  total: "7.60",
};

test("the bill reads as a bill on a Star printer's 80 mm paper, with no warnings", () => {
  const paper = createRendererSync().render({ document: billDocument(order), profile: "star-starprnt-utf8-80mm", format: "text" });
  assert.ok(!isError(paper));
  assert.deepEqual(paper.warnings, []);
  assert.match(paper.content, /Flat white\s+3\.40/);
  assert.match(paper.content, /Total\s+7\.60/);
});

test("one key for each bill, and no retries inside the call", async () => {
  const calls = [];
  const fake = { jobs: { create: async (request, options) => { calls.push({ request, options }); return { id: "job_fake", status: "queued" }; } } };
  const job = await printBill(fake, "prn_fake", order);
  assert.equal(job.status, "queued");
  assert.equal(calls[0].request["Idempotency-Key"], "order-4711-bill");
  assert.equal(calls[0].options.maxRetries, 0);
});

The agent can read the drawing of the paper, see a warning such as a character the printer cannot print, and fix the document before a person ever runs it with a key. The browser preview does the same for a person.

If a person does give the agent a key to try, the rule is the one in llms.txt: never call the live API, create a job or open a printer URL unless the person gave the agent the key and named the printer. A key limited to one customer sees nothing of the others. A test print is the gentlest first call: it is a job of kind test, it is never billed, and a printer takes at most 5 a minute and 3 waiting at a time.

Next steps