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

# Lovable

> Connect your Lovable app to Infi: a key over HTTP and the SDK on the server.

<Tip>
  **Two paths: MCP or one HTTP call.** Use `infi_onboard` over **MCP stdio** (`npx -y @beinfi/mcp`) when the editor
  supports that transport. With no shell and no MCP, the agent provisions through
  the API below. The [agent onboarding](https://beinfi.com/en/agent-onboarding) guide covers the
  required versions, the questions, and resuming the same account.
</Tip>

## 1. Prepare the account

The agent first looks for an existing Infi integration in the app. If there is
one, it reuses that account. For a new integration, it asks for an email, the
app name and the billing intent. With the answers it calls `infi_onboard` or
makes the POST below with the real values:

```bash theme={null}
curl -X POST https://api-sandbox.beinfi.com/public/v1/claimables \
  -H 'Content-Type: application/json' \
  -d '{"ref":"lovable","email":"founder@example.com","accountName":"Acme"}'
```

The response carries `apiKeySecret` (`sk_test_*`, once only), `publishableKey`
(`pk_test_*`), `accountName`, `tenantSlug`, `expiresAt`, the seed `productId` and
the `claimUrl` (`https://app-sandbox.beinfi.com/claim/{id}`). The
`ref: "lovable"` is what marks the tenant's `signup_source`. Field by field in
[quickstart](https://beinfi.com/en/inicio-rapido).

## 2. Keep the link to finish later

The agent hands the `claimUrl` back and continues the integration in the
sandbox. With the claim-email update, supplying an address also queues a notice
with the account name, the link and the deadline. Delivery is asynchronous and
limited to one notice per address every 24 hours. The email does not contain the
keys; `201` confirms creation, not delivery.

You sign in to Infi later, through the link from the conversation or the email,
and take over the same account. The default window is 30 days; the returned
`expiresAt` is what counts. The name is already filled in, and products, keys
and slug are preserved. Do not create another account if the email is slow.
Details in [Claim](https://beinfi.com/en/sandbox).

## 3. Env in the Lovable app

```bash theme={null}
INFI_SECRET_KEY=sk_test_...
INFI_PUBLISHABLE_KEY=pk_test_...
INFI_TENANT_SLUG=your-tenant
```

Save `INFI_SECRET_KEY` in your server functions' secrets. Only
`INFI_PUBLISHABLE_KEY` may be exposed in the browser when a client API requires
one; it is Infi's, not the payment provider's. Never expose the secret in a
`VITE_*` variable. The agent needs neither your password nor a verification
code.

Do not set `INFI_AUTH_BASE_URL` / `INFI_PAY_BASE_URL` — they are legacy and
nothing reads them. The hosts come from the key's prefix.

## 4. Create the product

The seed product is good for neither selling nor metering (version in `draft`,
no meter). Create and publish your own — three calls in
[catalog](https://beinfi.com/en/catalogo). Keep the `productId`: it goes into the payment
link, `checkout()` and every usage event.

## 5. Integrate the SDK

Infi does not log your user in — use the auth the app already has (Supabase, in
the typical Lovable case) and pass that id to Infi.

```ts theme={null}
// server — enrollment + usage metering
import { Infi } from "@beinfi/sdk";

const infi = new Infi({ secretKey: process.env.INFI_SECRET_KEY! });

// yourUserId comes from YOUR auth (e.g. Supabase)
const enrollment = await infi.products.enroll(productId, {
  externalId: yourUserId,
  email: userEmail,
});

await infi.track({
  customerId: enrollment.id,
  productId,               // required once the tenant has more than one product
  meter: "tokens",
  value: "1200",
});
```

To charge, send a [payment link](https://beinfi.com/en/link-de-pagamento). To know they paid,
[polling in sandbox](https://beinfi.com/en/webhooks) — registering a webhook answers `503`
with a test key.

## MCP tools

A reference for what the MCP server exposes. Point your MCP client at it like
this:

```json theme={null}
{
  "mcpServers": {
    "infi": { "command": "npx", "args": ["-y", "@beinfi/mcp"] }
  }
}
```

| Tool                                 | What for                                                         |
| ------------------------------------ | ---------------------------------------------------------------- |
| `infi_onboard`                       | Questions → prepared account → setup → link to finish signing up |
| `infi_bootstrap`                     | Direct provisioning + `infi.company.ts` + sync + doctor          |
| `infi_claim_create`                  | Provisions the claimable tenant only                             |
| `infi_doctor`                        | Setup health (JSON + fix commands)                               |
| `infi_go_live_status`                | Guidance for claim → KYC → `sk_live_`                            |
| `infi_sync_plan` / `infi_sync_apply` | Dry-run / apply of the company file                              |
| `infi_set_app_url`                   | Updates the app's origins                                        |
| `infi_pull`                          | Backend → `infi.company.ts`                                      |
