# LlamaIndex → PDF with makesPDF

> For AI agents: a documentation index is available at https://makespdf.com/llms.txt — every docs page also has a markdown twin (append .md to the page URL), including this one: https://makespdf.com/docs/integrations/llamaindex.md

The `makespdf[llamaindex]` extra exposes two LlamaIndex `FunctionTool`s over
the [makesPDF](https://makespdf.com/?ref=llamaindex) hosted API — markdown → PDF
and stored-template/inline-DSL → PDF. Both write a temp `.pdf` and return its
path.

## Install

```bash
pip install "makespdf[llamaindex]"
export MAKESPDF_API_KEY=... # mint at https://makespdf.com/settings/api-keys?ref=llamaindex
```

The LlamaIndex import happens inside the factory, so `import makespdf` never
imports a framework. A missing extra raises `ImportError` naming the pip extra.

## The two tools

| Tool | Endpoint | Arguments |
| --- | --- | --- |
| `makespdf_render_md` | `POST /api/v1/md` | `markdown` |
| `makespdf_render` | `POST /api/v1/render` | `template_id` or `dsl`, plus `data_json` |

`makespdf_render` takes exactly one of `template_id` (`"invoice-classic"`) or
`dsl`, plus `data_json` for `{{vars}}`. Both tools return a temp `.pdf` path.

## Example

```python
from makespdf import MakesPDFClient
from makespdf.integrations.demo import MARKDOWN_DEMO, DSL_DEMO
from makespdf.integrations.llamaindex import get_llamaindex_tools

md_tool, render_tool = get_llamaindex_tools(MakesPDFClient())
print(md_tool.call(MARKDOWN_DEMO))  # markdown -> PDF path
print(render_tool.call(dsl=DSL_DEMO, data_json='{"name": "Ada"}'))  # DSL -> PDF path
```

`get_llamaindex_tools()` returns `(md_tool, render_tool)`; `.call()` forwards
the tool's arguments. LangChain agents want the
[LangChain shim](https://makespdf.com/docs/integrations/langchain) instead; CrewAI agents
want the [CrewAI shim](https://makespdf.com/docs/integrations/crewai).

## Demo data

Every framework page here renders the same shared demo values, defined once in
`makespdf.integrations.demo`, so the examples stay directly comparable:

```python
MARKDOWN_DEMO = "# Invoice INV-2026-001\n\nHello **Ada** — total **$7,095.00**.\n"

DSL_DEMO = (
    'const template = doc({ size: "A4" }, page(col(s("Hello {{name}}"))));\n'
    'const sampleData = { name: "World" };\n'
)

DATA_DEMO = {"name": "Ada"}

TEMPLATE_ID_DEMO = "invoice-classic"
```

## Billing and limits

Billing matches the underlying endpoint: both `/md` and `/render` cost 1 credit
per 10 pages on success, and every failure path deducts zero. Markdown input is
capped at 200KB of text — inline `data:` images are excluded from that budget,
the request body is capped at 15MB — and inline DSL at 512KB. Rate limit:
10,000 renders/hour per caller.
