> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getlago.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build with Lago using your AI agent

> Give your coding agent Lago's documentation, then build and verify a billing integration with the API, CLI, or MCP.

Use Lago's public documentation, REST API, CLI, and MCP server with your AI agent. Start with a product description or pricing model; open your application repository when you are ready to implement. **No Lago plugin is required.**

## Start with a prompt

Paste this into your coding agent:

```text theme={"dark"}
Read https://getlago.com/llms.txt and follow the relevant Lago guides for this
project. Use https://swagger.getlago.com/openapi.yaml for exact API fields.
Help me design and implement a billing integration. Ask before live access.
```

Describe what your customers pay for. Your agent can use public documentation to propose the customer identifiers, billable metrics, plans, and subscription lifecycle before connecting to a live environment.

## Get a first result

Ask your agent to calculate an expected bill before writing the integration. This example follows one customer action through usage, pricing, included credits, and overage, using fictional prices:

| Step | Example result |
| - | - |
| Customer agreement | \$99 subscription with \$10 of included AI usage |
| Credit remaining before the action | \$0.20, after \$9.80 has already been used |
| New usage charge | \$0.37 from input and output token records |
| Identical event replay | No additional charge when `transaction_id` and `timestamp` match |
| Credit applied to this action | \$0.20 |
| Overage from this action | \$0.17 |

This is an offline calculation, not proof that your environment is configured correctly. Live validation checks actual Lago results separately. Amounts exclude tax and payment processing. Automated monthly wallet renewal is edition-dependent.

### Apply it to your product

Give the agent a product description or pricing page:

```text theme={"dark"}
We sell an AI research product. Customers pay a subscription with included usage,
then overages. Help me model who pays, what we meter, and how the amount is
calculated in Lago. Identify the smallest integration we can verify.
```

Other starting points:

* **API usage:** "Model a subscription with included API calls and usage overages."
* **Prepaid credits:** "Help me model prepaid usage, wallet consumption, and what my application should do when credit runs out."
* **Existing billing:** "Help me add Lago usage billing to my existing architecture. Identify which system owns subscriptions, invoicing, and payments."

### Implement in your application

Open the application repository and ask:

```text theme={"dark"}
Implement Lago in this application. Inspect the codebase, propose the smallest
billing slice, and add usage events and tests. Ask before accessing any live
Lago environment.
```

Review the proposed customer identifiers, billable metrics, plans, and subscription lifecycle. Your application should use an official Lago SDK or the REST API. It should not shell out to the CLI or require an MCP server at runtime.

A useful first validation checks the expected charge, retries the same logical event with the same `transaction_id` and explicit `timestamp`, and compares the resulting Lago usage or invoice data with the independently calculated expectation. On organizations using the ClickHouse-based event pipeline, both fields must match for Lago to treat a retry as the same event. A different or omitted timestamp creates a distinct billable event. See [Idempotency and deduplication](/guide/events/ingesting-usage#idempotency-and-deduplication). A successful API response alone does not establish billing correctness.

## Choose how your agent connects

| Tool | Use it for | Requirements |
| - | - | - |
| Lago CLI | Terminal workflows, diagnostics, scripts, and structured billing results | Installed CLI; configured credentials for live requests |
| Product MCP | Read billing data and perform supported operations through connected tools | MCP client, Docker, Lago API key, and target API URL |
| Documentation MCP | Search and retrieve public Lago documentation | Compatible MCP client |
| REST API or SDK | Your application's production integration | Server-side API credentials and the correct regional or self-hosted API URL |

Choose the interface your agent supports. The API, CLI, and MCP work independently; you do not need to install all three. Application code should use the REST API or an official SDK.

### Build with the API or an SDK

Start with the [API reference](/api-reference/intro) and [developer resources](/developers) for supported SDKs. Give your agent the [complete OpenAPI specification](https://swagger.getlago.com/openapi.yaml) for exact fields. Keep credentials server-side and confirm the US, EU, or self-hosted API URL before sending requests.

### Use the CLI

Install with Homebrew on macOS or Linux:

```bash theme={"dark"}
brew install getlago/tap/lago
```

For Go installation and Windows releases, see the [CLI setup guide](/guide/lago-cli/overview).

Inspect the installed version and available commands before building a script:

```bash theme={"dark"}
lago version
lago --help
```

Follow the [configuration guide](/guide/lago-cli/overview) to select the environment and store credentials. After authorizing live access, verify the resolved target:

```bash theme={"dark"}
lago whoami --output json
lago doctor --output json
```

These commands contact the configured Lago environment. Review each command's help for JSON output and dry-run support. A CLI mode named `test` is not an isolated Lago sandbox.

### Connect the product MCP

Follow the [MCP server setup guide](/guide/ai-agents/mcp-server) for the Docker configuration. Set `LAGO_API_URL` explicitly to the US, EU, or self-hosted API endpoint and provide `LAGO_API_KEY` through your client's secret configuration.

Start with an authorized read, such as:

```text theme={"dark"}
List the invoices for this customer. Do not change billing data.
```

Available operations are listed in the [Lago Agent Toolkit](https://github.com/getlago/lago-agent-toolkit). The product MCP accesses live billing data; it is separate from the public documentation MCP.

## Give your agent the documentation

Use these sources to keep generated code aligned with Lago’s current API and workflows.

* **Documentation index:** [llms.txt](https://getlago.com/llms.txt)
* **Documentation MCP:** `https://docs.getlago.com/mcp`
* **Complete OpenAPI contract:** [openapi.yaml](https://swagger.getlago.com/openapi.yaml)
* **Developer resources:** [API, SDKs, authentication, and webhooks](/developers)

Configure the documentation MCP as a remote HTTP server in a compatible client. It provides documentation access, not access to your Lago organization.

## Validate before live billing

Keep API keys out of prompts, source control, and browser code. Confirm the organization, API URL, affected records, and expected billing impact before live work. Ask your agent to show the proposed changes before executing financial or destructive operations.

Use an isolated self-hosted instance for synthetic demos. Lago has no built-in sandbox, and calling a Cloud organization "test" does not isolate it. Follow the [integration testing guide](/guide/integration-testing) when validating your own application.

## Optional: install the Lago plugin

The plugin packages Lago billing guidance, worked examples, and an implementation workflow for Claude Code and Codex. It is an optional shortcut for the same API, CLI, and MCP workflows.

<Info>
  The plugin's public release is in preparation. The installation instructions below apply once the public repository is available. The API, CLI, MCP, and documentation paths above are available now.
</Info>

The plugin supports Claude Code and Codex. Exploring its offline example and designing an integration require no Lago account, API key, CLI, or MCP connection.

<Tabs>
  <Tab title="Claude Code">
    Once the public release is available, run these commands in Claude Code:

    ```text theme={"dark"}
    /plugin marketplace add getlago/lago-plugin
    /plugin install lago@lago-plugins
    ```

    Then start with:

    ```text theme={"dark"}
    /lago:implementation show me what Lago can do
    ```
  </Tab>

  <Tab title="Codex">
    Once the public release is available, run these commands in your terminal:

    ```bash theme={"dark"}
    codex plugin marketplace add getlago/lago-plugin
    codex plugin add lago@lago-plugins
    ```

    Start a new Codex task, then ask:

    ```text theme={"dark"}
    $lago:implementation show me what Lago can do; do not assume this workspace is my application
    ```
  </Tab>
</Tabs>

The plugin is distributed from Lago's repository. This installation path does not imply an official OpenAI or Anthropic marketplace listing. Installation identifiers above follow the v0.2.0 release candidate.

[Explore Lago's tools for AI agents](https://getlago.com/for-agents)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.