---
sidebar_position: 1.4
slug: /developers/claude-code-gpu
title: Give Claude Code a GPU in 60 seconds
description: Hand Claude Code (or any coding agent) a Lium GPU through the lium CLI, with a scoped API key, a server-enforced daily budget and automatic removal. Every command and output on this page comes from a real run against lium.io.
---

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lium.io/llms.txt
> Use this file to discover all available pages before exploring further.
>
> Lium (lium.io) is a GPU rental marketplace: rent NVIDIA GPUs by the hour, billed per second.

# Give Claude Code a GPU in 60 seconds

Claude Code already runs shell commands, so the `lium` CLI is all it needs to rent a GPU, run code on it, bring results back and remove the pod. Setup takes three things from you: an API key with narrow scopes and a budget, one `pip install`, and a short instruction for the agent.

In the run this page was written from (15 Oct 2026, CLI 0.16.1), `lium up` returned a ready RTX 5070 Ti pod on the default PyTorch template in **26 seconds**, and the first `lium exec` output arrived **30 seconds** after `lium up` started. The whole test cost $0.006: billing is per second with no minimum.

## 1. Create a key for the agent

Give the agent its own key, not your account's default key. This one can list nodes and rent pods (`read`, `rent`), sees only the pods it created, and may spend at most $5 per UTC day.

Sign in for a session token, then create the key with it. The session token is a secret too; keep it in a variable and do not hand it to the agent.

```bash
API=https://lium.io/api

JWT=$(curl -s $API/users/login -H "Content-Type: application/json" \
  -d '{"email": "you@example.com", "password": "…"}' | jq -r .token)

RESP=$(curl -s $API/keys -H "Authorization: Bearer $JWT" -H "Content-Type: application/json" \
  -d '{"name": "claude-code-20261015", "scopes": ["read", "rent"], "pod_visibility": "own", "daily_budget_usd": 5}')

export LIUM_API_KEY=$(jq -r .key <<<"$RESP")   # the agent's new key; the next step hands it to the CLI
```

`$RESP` carries the key and its budget (trimmed, key redacted):

```json
{
  "id": "e9140f46-…",
  "name": "claude-code-20261015",
  "key": "sk_…",
  "masked_key": "sk_9ON3vu0T********",
  "scopes": ["read", "rent"],
  "daily_budget_usd": 5.0,
  "monthly_budget_usd": null,
  "max_budget_usd": null,
  "pod_visibility": "own",
  "spent_today_usd": 0.0
}
```

You can also add a monthly (`monthly_budget_usd`) or lifetime (`max_budget_usd`) budget, or `"pod_visibility": "own"` so the agent sees only the pods it rented. See [API keys](../pod-users/api-keys.md#budgets).

## 2. Install the CLI and hand it the key

```bash
pip install lium.io
lium config set api.api_key "$LIUM_API_KEY"   # or just export LIUM_API_KEY; the CLI reads it
ssh-keygen -t ed25519 -N "" -f ~/.ssh/id_ed25519   # only if you have no SSH key yet; lium uses it to reach the pod
lium whoami
```

```text
API key  sk_9ON…q8U8  (config:~/.lium/config.ini [api] api_key)
Account  076ed099-…
Balance  $176.10
API      https://lium.io/api  reachable, 1713 ms
CLI      lium 0.16.1
```

## 3. Tell Claude Code how to use it

Paste this into your project's `CLAUDE.md` (or give it as the first instruction):

```markdown
## GPU compute (Lium)

You can rent GPUs with the `lium` CLI. The API key is already configured (LIUM_API_KEY / ~/.lium/config.ini);
never print it. Rules:

- Pick a node with `lium ls --count 1 --format json` (cheapest first) unless I ask for a specific GPU.
- Always rent with a name and a deadline: `lium up <huid> --name <name> --ttl 1h -y --json`.
  Never rent without `--ttl` (or `--until`).
- Run work with `lium exec <name> "<command>"`; use `lium exec <name> -d "<command>"` for anything long.
- Bring results back with `lium scp <name> <remote-path> <local-dir> -d`.
- When the work is done, or anything fails, run `lium rm <name> -y`, then `lium ps` to confirm it is gone.
- Check spend with `lium spend`. If a rent is refused with API_KEY_BUDGET_EXCEEDED, stop and tell me.
```

## 4. What the agent runs

These are the exact commands from the test run, with their output.

**Pick the cheapest single-GPU node:**

```bash
NODE=$(lium ls --count 1 --format json | jq -r '.[0].huid')   # gentle-eagle-11, 1×RTX 5070 Ti, $0.40/h
```

`--count 1` keeps to nodes that rent as one GPU. The bare `lium up --gpu A4000` at the time of the test matched only a 6-GPU node that does not split, and exited 1 with `node_selection_failed` and no pod created, so filtering in `lium ls` first is the reliable path.

**Rent it with auto-removal after one hour:**

```bash
lium up "$NODE" --name cc-demo --ttl 1h -y --json
```

Progress goes to stderr, the ready pod as JSON to stdout:

```text
Est. deploy time: ~1m 0s (image: ~4.9 GB, download: 315 Mbps)
renting gentle-eagle-11…
pod cc-demo (id: 37943de0-…) created; waiting for it to become ready
removal of pod cc-demo scheduled for 2026-10-15 04:04 UTC (in 1.0h), whether or not it becomes ready
waiting for noble-comet-c6… PENDING (4 s) · est. ready any moment now (phase: mounting encrypted volume)
waiting for noble-comet-c6… RUNNING (6 s)
Pod noble-comet-c6 (name: cc-demo, id: 37943de0-…) ready
```

```json
{
  "pod": {
    "huid": "noble-comet-c6",
    "name": "cc-demo",
    "status": "RUNNING",
    "gpu_type": "RTX5070",
    "template": "Pytorch (Cuda + DinD)",
    "price_per_hour": 0.4,
    "removal_scheduled_at": "2026-10-15T04:04:47.189699",
    "api_key_name": "claude-code-20261015"
  },
  "termination_time": "2026-10-15T04:04:47.189699+00:00"
}
```

The removal is scheduled as soon as the pod exists, so it holds even if the agent's session ends before cleanup.

**Run code on the GPU:**

```bash
lium exec cc-demo "nvidia-smi --query-gpu=name,memory.total --format=csv"
```

```text
Executing on noble-comet-c6
name, memory.total [MiB]
NVIDIA GeForce RTX 5070 Ti, 16303 MiB
```

The first connection to a pod also prints one line on stderr as the CLI pins the pod's SSH host key.

```bash
lium exec cc-demo "python -c 'import torch;print(torch.cuda.is_available())'"
```

```text
Executing on noble-comet-c6
True
```

`lium exec` exits with the remote command's exit code, so the agent can branch on it.

**Collect output:**

```bash
lium exec cc-demo "mkdir -p /root/out && nvidia-smi --query-gpu=name,memory.total --format=csv > /root/out/gpu.csv \
  && python -c 'import torch;print(torch.__version__, torch.cuda.get_device_name(0))' >> /root/out/gpu.csv"
lium scp cc-demo /root/out/gpu.csv ./dl/ -d
cat dl/gpu.csv
```

```text
name, memory.total [MiB]
NVIDIA GeForce RTX 5070 Ti, 16303 MiB
2.12.0+cu130 NVIDIA GeForce RTX 5070 Ti
```

`lium scp` uploads by default; `-d` downloads. For whole directories going up, use `lium rsync`.

**Check spend, then clean up:**

```bash
lium spend
lium rm cc-demo -y
lium ps
```

```text
Pod        Config     $/h  Uptime  Spent  Since (UTC)
cc-demo    RTX5070  $0.40      1m  $0.01  2026-10-15 03:04

Removed 1 pod(s): noble-comet-c6
removed cc-demo — 1m at $0.40/h ≈ $0.01
```

After `lium rm`, `lium ps` no longer lists `cc-demo`. Billing stopped at removal; the key's `spent_today_usd` read $0.006 for the run.

**Delete the key when you are done with it** (from your session, not the agent's):

```bash
curl -X DELETE $API/keys/$KEY_ID -H "Authorization: Bearer $JWT"
```

## Why this is safe to hand to an agent

- **Scoped key.** The key carries only `read` and `rent` and sees only its own pods, so it cannot touch other pods on the account. It cannot create other keys or raise its own budget: those need your signed-in session.
- **A budget the server enforces.** A rent that would take the key past its daily budget is refused with `402 API_KEY_BUDGET_EXCEEDED`, and if running pods take the key to its budget, the pods that key created are removed. This happens on Lium's side, whatever the agent does. Details in [API keys → Budgets](../pod-users/api-keys.md#budgets).
- **Automatic removal.** `--ttl` schedules the pod's removal on the platform the moment the pod exists, so a crashed or forgotten session still ends with no pod running. A key at its budget cannot push that removal later. See [Scheduled termination](../pod-users/scheduled-termination.md).
- **Per-second billing.** A short experiment costs cents; this whole test cost under one cent.

For the full agent integration (signup without a browser, self-funding, the agent skill), see [AI Agents](./agents.md) and [Scripting for agents](./agent-scripting.md).
