# Run a coding agent on a budget

Start Claude Code on the exchange with a key that cannot spend more than you set.

In about ten minutes, you start Claude Code through `liquid` with a key limited to $5 each day. Then you read the receipt of your first job.

## Before you start

- You need a workspace with a balance. See the [Quickstart](https://inference.ai.exchange/docs/quickstart.md).
- You must be an owner or an admin of the workspace. Only they can make keys.
- Claude Code must be on your `PATH`. The installer supports macOS and Linux.

## Steps

1. Install the Liquid CLI.

   ```bash
   curl -fsSL https://inference.ai.exchange/cli/install.sh | bash
   ```

   The installer checks the checksum and puts `liquid` in `~/.local/bin`.

2. Sign in with permission to manage keys.

   ```bash
   liquid login --keys
   ```

   Your browser opens. Approve the request. The terminal shows that you are signed in. This token lasts one day and cannot place jobs.

3. Make a key with a spending limit and save it for your coding agents.

   ```bash
   liquid keys create agent --spend-limit 5 --period day --save
   ```

   The terminal prints `created agent` and the key id. The command does not print a saved key, so you cannot lose it in your scrollback.

   The limit is $5 each day. When the key reaches it, jobs fail with `402 budget_exhausted`, even if the workspace has more balance. Use `--period week` or `--period month` for a longer period.

4. Start Claude Code with a cap on each request.

   ```bash
   liquid claude --model liquid/auto:cheapest --cap 0.50
   ```

   Claude Code opens. `--cap` is the most that one request can cost in USD. The key limit bounds the total. The cap bounds each request.

5. Give the agent one small task. For example:

   ```text
   Explain what this repository does in five lines.
   ```

6. Leave Claude Code. When the session ends, `liquid` prints the number of requests, the cost and the largest charge against your cap.

## Check it works

List your latest jobs:

```bash
liquid job
```

Each row shows the job id, the model, the provider and the amount charged. Type to filter and press Enter to open one job. You can also pass the id:

```bash
liquid job <job-id>
```

Look for three things:

- **Provider.** This is the provider that answered.
- **Outcome.** A normal job shows `completed`.
- **Charged.** The exchange charged the tokens used. It is never more than your cap.

The receipt adds the supplier charge and the fee. See [Receipts](https://inference.ai.exchange/docs/receipts.md) for every field. To check the limit itself, open **API keys** in the console. The key `agent` shows its limit and period.

## Add a guardrail (optional)

A spending limit stops one key. A guardrail also limits which offers can serve a call, and it can block sensitive text.

1. Open **Rules** in the console, then **Guardrails**.
2. Choose **New guardrail** and select the key `agent` under **Select keys**.
3. Set a budget, then save.

The next call follows the new rules. See [Guardrails](https://inference.ai.exchange/docs/guardrails.md).

## If something goes wrong

- **`liquid keys` says you need a token.** Run `liquid login --keys` again. A member cannot approve this token. Ask an owner or an admin to make a key, then run `liquid login --key sk-liquid-...`.
- **Claude Code does not start.** A `.claude/settings.json` file may set `ANTHROPIC_API_KEY`, `ANTHROPIC_AUTH_TOKEN` or `ANTHROPIC_BASE_URL`. Remove that value from `env`. See [Claude Code](https://inference.ai.exchange/docs/connect-claude-code.md).
- **A job fails with `402`.** The key reached its limit, or the workspace has no balance. Check the balance with `liquid workspace balance`.

## Next steps

- [API keys](https://inference.ai.exchange/docs/keys.md): scopes, expiry and revocation.
- [Purchasing rules](https://inference.ai.exchange/docs/rules.md): choose price, speed or region for each request.
- [Liquid CLI](https://inference.ai.exchange/docs/cli.md): models, cap and workspace settings.
