# Set up w0rth for your user

You are an AI agent. Your user wants you to manage their personal finances in **w0rth** (https://w0rth.com), a money ledger built for AI agents. Follow these instructions to connect, then confirm with the user.

## What w0rth is

- w0rth keeps your user's accounts, balances, income, expenses, debts, credit cards, goals and recurring commitments.
- w0rth is a **record-keeping ledger**, not a bank. It is not connected to any bank and there are **no payment capabilities**. Record what the user tells you.
- Your job is to keep the records accurate: read the financial context, record the income and expenses the user tells you about, and reconcile an account to a real balance the user gives you.
- When something is ambiguous (which account, which date, whether a balance already includes a purchase), ask the user before writing.

## Step 1: get a connection key from the user

**Never ask for their w0rth password or login code**, and never try to sign in as them.

If the user already included a connection key in their message (it starts with `w0rth_`), use that key directly. Store it as a secret if your environment supports it (for example `W0RTH_TOKEN`). Do not print it back in full. Skip the rest of this step.

If they did not include a key, tell them to create one in the app:

> To connect, sign in at https://w0rth.com and click **Connect agent**. Copy the message it shows and paste it back here. The connection key is shown only once. You can revoke it anytime in Settings.

Advanced users can also create a key at Settings → API tokens (https://w0rth.com/settings/api-tokens).

## Step 2: call the API

- Base URL: `https://w0rth.com/api/v1`
- Auth header on every request: `Authorization: Bearer <token>`
- JSON in and out. Dates are `YYYY-MM-DD` (timezone `America/Mexico_City`). Amounts are numbers rounded to cents.
- There is no currency code in the API. The ledger is single-currency (the dashboard displays MXN by default). Use the same unit as the account balances from `GET /context`. Ask the user if the currency is unclear.
- In responses, expenses and credit-card balances owed are negative. When recording, send a **positive** `amount` and set `type` to `"income"` or `"expense"`.
- Rate limit: 120 requests per minute per token (`429` with `Retry-After`).
- Plans: reads are always unlimited. On Free, the user can add 100 new entries per calendar month; `GET /api/v1/context` → `plan.usage.monthly_transactions` and `plan.limits` show where they stand. Pro is unlimited.

Verify the token and learn the user's situation in one call:

```bash
curl https://w0rth.com/api/v1/context -H "Authorization: Bearer $W0RTH_TOKEN"
```

It returns `accounts` (id, name, type DEBIT/CREDIT, balance; credit balances are negative when owed; credit cards also include `credit_limit`, `available_credit`, `statement_day`, `payment_due_day`), `totals` (wealth, debts, net), `categories` (id, name, type INCOME/EXPENSE), and `upcoming` commitments for the next 30 days. It does not list goals in full — only any upcoming `goal_contribution` items. Debts are listed in full at `GET /api/v1/debts` (`totals.debts` is the remaining amount of unsettled debts).

### Record income or an expense

```bash
curl https://w0rth.com/api/v1/transactions \
  -H "Authorization: Bearer $W0RTH_TOKEN" -H "content-type: application/json" \
  -d '{"type":"expense","account":"Checking","amount":64.50,"date":"2026-11-16",
       "description":"Groceries","category":"Food","idempotency_key":"checking-2026-11-16-64.50-groceries"}'
```

- `type`: `income` or `expense`. `amount`: positive; the sign comes from `type`.
- `account` (name, case-insensitive) or `account_id`. `category` (name) or `category_id` are optional.
- **Always send an `idempotency_key`** derived from the source (bank reference, or account-date-amount-description). If you retry with the same key, w0rth returns the original transaction (`idempotent_replay: true`) instead of creating a duplicate.
- The response includes the created `transaction` and the account's new `balance`, so you can confirm without another call.

### Reconcile an account to its real balance

When the user tells you the real balance, record the movements you know about first, then:

```bash
curl https://w0rth.com/api/v1/accounts/2/reconcile \
  -H "Authorization: Bearer $W0RTH_TOKEN" -H "content-type: application/json" \
  -d '{"target_balance":22119.76,"idempotency_key":"reconcile-2-2026-11-16"}'
```

w0rth sets the balance and records a "Balance adjustment (increase/decrease)" entry for the difference. If it already matches, nothing is written (`changed: false`).

### Mark a recurring commitment as paid

`GET /api/v1/commitments` lists subscriptions with their next due date, paying account, and optional expense category (`category_id` / `category_name`). To set the category used when a payment is recorded:

```bash
curl -X PATCH https://w0rth.com/api/v1/commitments/9 \
  -H "Authorization: Bearer $W0RTH_TOKEN" -H "content-type: application/json" \
  -d '{"category":"Servicios"}'
```

Send `"category_id": null` to clear it. To mark one paid:

```bash
curl https://w0rth.com/api/v1/commitments/9/pay \
  -H "Authorization: Bearer $W0RTH_TOKEN" -H "content-type: application/json" \
  -d '{"affects_balance":true}'
```

- Default `affects_balance: true` records an expense and lowers the paying account.
- If the user already updated the account balance (for example after a reconcile) and that balance already includes this payment, send `"affects_balance": false`. That marks the cycle as paid and moves the next date forward, without creating a transaction or changing the balance. Otherwise the same payment is counted twice.
- If the commitment has a category, the payment is recorded in that category; otherwise it is uncategorized.

### List debts and mark one as paid

`GET /api/v1/debts` lists every debt with its original, paid and remaining amounts, status (`open` or `settled`), and its recorded payments.

```bash
curl https://w0rth.com/api/v1/debts -H "Authorization: Bearer $W0RTH_TOKEN"
```

To record a payment against a debt:

```bash
curl https://w0rth.com/api/v1/debts/4/pay \
  -H "Authorization: Bearer $W0RTH_TOKEN" -H "content-type: application/json" \
  -d '{"amount":3000,"account":"Banorte"}'
```

- Default `affects_balance: true` records an expense (`Debt: <name>`) and lowers the paying account, exactly like "Pay down" in the dashboard.
- If the payment is already recorded — for example you already logged the expense, or the money already left the account — send `"affects_balance": false` and link the existing transactions with `"transaction_ids": [661, 805]`. The payment is recorded against the debt and the remaining amount drops, but no new transaction is created and no balance changes. `amount` must equal the sum of the linked transactions. When the remaining amount reaches zero the debt is marked settled.
- Without `transaction_ids`, `affects_balance: false` records a payment with no linked transaction (for example cash paid outside the ledger).
- Always send an `idempotency_key` on payment calls so a retry does not pay twice.


### Delete a transaction

```bash
curl -X DELETE "https://w0rth.com/api/v1/transactions/123?keep_balance=true" \
  -H "Authorization: Bearer $W0RTH_TOKEN"
```

- Default: the account balance is reversed by the transaction amount.
- `keep_balance=true` (query or JSON body) removes the record but leaves the current balance unchanged. Use this when that amount was already counted in a balance adjustment.

### Read history

```bash
curl "https://w0rth.com/api/v1/transactions?account_id=2&from=2026-11-01&limit=50" \
  -H "Authorization: Bearer $W0RTH_TOKEN"
```

### Errors

Every error looks like this; `field` tells you what to fix:

```json
{ "error": { "code": "validation_error", "message": "amount must be at least 0.01.", "field": "amount" } }
```

Codes: `unauthorized` (401, bad or revoked token: ask the user for a new one), `not_found` (404, the message lists valid account or category names), `ambiguous` (409, use the id), `validation_error` (422), `limit_reached` (403: the user's plan limit was hit and nothing was written — tell them and share https://w0rth.com/pricing; do not retry), `rate_limited` (429).

Full reference: https://w0rth.com/agents

## Step 3: tell the user you're done

Once `GET /context` succeeds, reply to the user with:

1. That you're connected to w0rth (mention the token name they chose, not the token).
2. A one-line summary: number of accounts, total wealth, total debts, and the next upcoming commitment if any.
3. A reminder that you can now log their income and expenses, keep balances up to date, and track debts, cards and goals whenever they tell you, and that they can revoke this connection anytime in Settings (or under **API tokens**).
