Create Word document (.docx)
POST /api/docx-createTurn markdown into a real Word document (.docx) in one call. Send POST /api/docx-create with the required field markdown and pay $0.003 per call over x402 or MPP (there is no free tier). It returns a JSON object with docxBase64, bytes, contentType, filename, blocks and 5 more.
Send "markdown" and an optional "title": headings, paragraphs, bold, italic, strikethrough, inline code, bullet and numbered lists (nested), task lists, tables, code blocks, block quotes, horizontal rules and links come out as native Word formatting. A link is written as a hyperlink; an image is written as its alt text linked to its address and is never fetched. Up to 100,000 characters, 5,000 blocks, tables of 200 rows by 20 columns and 25,000 table cells in all (a short row counts at its header's width), nesting 8 levels of blocks and 16 of inline formatting. The request body may be up to 2 MB. Returns the file as base64 with its size, content type and filename.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
markdown | string | yes | Document body as markdown (GitHub flavor), up to 100,000 characters |
title | string | no | Optional title, written as the document's Title paragraph and its title property (up to 500 characters) |
filename | string | no | File name for the answer (default "document.docx") |
Example request
curl -i -X POST https://agent402.tools/api/docx-create \
-H "Content-Type: application/json" \
-d '{"title":"Quarterly update","markdown":"## Highlights\n\nRevenue grew **12%** and churn fell to *2.1%*.\n\n- Two new regions\n- Support hours extended\n\n1. Hire two engineers\n2. Ship the billing export\n\n| Region | Units |\n|---|---:|\n| North | 1200 |\n| South | 860 |\n\n```\nnpm run report\n```\n\nDetails at [the status page](https://agent402.tools/status).","filename":"update.docx"}'
Without payment this returns HTTP 402 Payment Required with the exact price for docx-create; any x402 v2 or MPP client pays it and retries.
Example response
{
"docxBase64": "UEsDBAoAAAAAAG...",
"bytes": 10520,
"contentType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"filename": "update.docx",
"blocks": 10,
"headings": 1,
"tables": 1,
"listItems": 4,
"codeBlocks": 1,
"links": 1
}
| Field | Type | Always present | In the example |
|---|---|---|---|
docxBase64 | string | yes | UEsDBAoAAAAAAG... |
bytes | number | yes | 10520 |
contentType | string | yes | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
filename | string | yes | update.docx |
blocks | number | yes | 10 |
headings | number | yes | 1 |
tables | number | yes | 1 |
listItems | number | yes | 4 |
codeBlocks | number | yes | 1 |
links | number | yes | 1 |
From an MCP client
catalog.call {
"slug": "docx-create",
"params": {
"title": "Quarterly update",
"markdown": "## Highlights\n\nRevenue grew **12%** and churn fell to *2.1%*.\n\n- Two new regions\n- Support hours extended\n\n1. Hire two engineers\n2. Ship the billing export\n\n| Region | Units |\n|---|---:|\n| North | 1200 |\n| South | 860 |\n\n```\nnpm run report\n```\n\nDetails at [the status page](https://agent402.tools/status).",
"filename": "update.docx"
}
}
The hosted connector at https://agent402.tools/mcp needs a payment for docx-create; the stdio package pays it from a wallet or from an AGENT402_CREDITS_KEY issued earlier. Local install: npx -y [email protected].
Errors and behavior
markdownis required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement runs after the tool and only on a successful response. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Wallet-only: this tool reaches the network or stored state, so it has no proof-of-work tier. A prepaid card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - A
GETorHEADto /api/docx-create returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB is not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.003" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/api/docx-create", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"title": "Quarterly update",
"markdown": "## Highlights\n\nRevenue grew **12%** and churn fell to *2.1%*.\n\n- Two new regions\n- Support hours extended\n\n1. Hire two engineers\n2. Ship the billing export\n\n| Region | Units |\n|---|---:|\n| North | 1200 |\n| South | 860 |\n\n```\nnpm run report\n```\n\nDetails at [the status page](https://agent402.tools/status).",
"filename": "update.docx"
}),
});
Related tools
Create PowerPoint deck (.pptx)
POST /api/pptx-createTurn slide outlines into a real PowerPoint deck (.pptx, 16:9) in one call.
Create Excel spreadsheet (.xlsx)
POST /api/xlsx-createTurn rows of data into a real Excel workbook (.xlsx) in one call.
Base / radix convert
POST /api/base-convertConvert an integer between number bases (radix 2-36), e.g. binary↔hex↔decimal.
CSV to JSON
POST /api/csv-to-jsonParse CSV (quoted fields supported) into a JSON array of objects, using the first row as headers (header=false.
CSV to Markdown table
POST /api/csv-to-mdConvert CSV into a GitHub-flavored Markdown table (first row is the header).
HTML to Markdown
POST /api/html-to-markdownConvert an HTML fragment or document you already have into clean markdown.