Guides / Building with AI

Use an AI agent (Claude Code) with Vast.ai GPUs and Hugging Face to build models

Let Claude Code do the grunt work of machine learning — preparing data, renting a GPU, fine-tuning, evaluating and publishing to Hugging Face — while you decide what to build.

Updated September 2026 · 9 min read

Short answer: Run Claude Code on an always-on server, give it a Vast.ai API key to rent GPUs by the hour and a Hugging Face token to pull base models and push results. The agent writes the training script, starts the GPU, watches the run, evaluates, publishes — and shuts the GPU down so you only pay for what you use.

Claude CodeHugging FaceVast.aiGoogle ColabPyTorch

Training or fine-tuning a model is mostly plumbing: finding a base model, cleaning a dataset, picking a GPU, fixing CUDA and dependency errors, babysitting a run for hours, then evaluating and uploading. That's exactly the kind of long, fiddly, tool-heavy work an agent like Claude Code is good at — as long as it has a real machine and the right accounts connected.

The setup in one picture

PieceRole
Always-on server (CPU, plenty of RAM)Where Claude Code lives: terminal, browser, code, logs, datasets. Cheap to keep running 24/7.
Claude CodeThe agent: plans, writes and runs code, reads errors, iterates.
Vast.aiA marketplace for renting GPUs by the hour. The agent starts an instance only when it needs to train, then destroys it.
Hugging FaceWhere base models and datasets come from, and where finished models, adapters and demos get published.

The key idea: don't keep a GPU running for the agent to think on. The agent's home is a normal server; GPUs are rented for the minutes or hours of actual training.

What the agent does, step by step

  1. Understand the goal. "Fine-tune a small open model to classify our support tickets into 12 categories" or "Make a model that writes product descriptions in our tone."
  2. Prepare the data. It cleans your CSVs or exports, removes duplicates, splits train/test, formats examples, and can push the dataset privately to the Hugging Face Hub.
  3. Pick a base model. It searches the Hub for suitable open models, checks licences and sizes, and recommends one that fits your budget.
  4. Write the training script. Typically Hugging Face transformers with peft (LoRA) or trl for supervised fine-tuning — tested first on a tiny sample on the CPU server.
  5. Rent a GPU on Vast.ai. Using the vastai CLI, it searches offers by GPU type, VRAM, price and reliability, starts an instance from a PyTorch image, and copies the code over.
  6. Run and watch. It launches training, tails the logs, and fixes the usual problems — out-of-memory errors, wrong batch sizes, missing packages — without you waking up at 3 a.m.
  7. Evaluate. It scores the model on the held-out set and compares against the base model, so you see whether training actually helped.
  8. Publish and clean up. It pushes the model or LoRA adapter to Hugging Face (private or public), writes a model card, optionally builds a small demo — then destroys the Vast.ai instance so billing stops.

Connecting the accounts

Store keys as environment variables or in the CLI's config on the server — never paste them into prompts or commit them to a repo.

Where Google Colab fits

Google Colab is great for poking at a dataset or trying an idea in a notebook with a free or cheap GPU. The agent can write notebooks you open in Colab to explore data and look at results, while the real training runs happen on Vast.ai where runs can last for hours and you choose the exact GPU. Many people use both: Colab to explore, Vast.ai to train.

What does it cost?

Vast.ai prices are set by the hosts and change constantly, but consumer cards like an RTX 4090 are often well under a dollar an hour and data-centre GPUs like A100s and H100s cost a few dollars an hour. A LoRA fine-tune of a small open model on a few thousand examples often finishes in well under a few hours — so the GPU bill for an experiment can be a few dollars. Always check current prices on Vast.ai.

The biggest cost risk isn't the training — it's a GPU left running by accident. Tell the agent, in writing, to destroy instances when a run finishes or fails, and to check for running instances at the end of every session.

Good first projects

Start small. A fine-tuned small model that does one job well is usually cheaper and faster than prompting a giant model for the same task — and you own it.

Guardrails that matter

Why the agent needs its own computer

Training runs are long. A laptop that sleeps, a chat window that times out, or a sandbox that resets will kill the job halfway. An always-on server with a terminal and browser lets Claude Code work for hours, keep logs and datasets between sessions, open the Hugging Face and Vast.ai dashboards when it needs to check something, and report back when you look at your phone.

Common questions

Can Claude Code train machine learning models?

Claude Code doesn't train models itself, but it can do almost all the work around training: prepare datasets, write the training code, rent a GPU, run and monitor the job, fix errors, evaluate the result and publish it to Hugging Face.

Why use Vast.ai instead of a GPU server that is always on?

Training only needs a GPU for hours at a time. Renting by the hour on Vast.ai and destroying the instance afterwards is usually far cheaper than paying for a dedicated GPU around the clock. The agent itself lives on a cheaper always-on CPU server.

What does Hugging Face do in this setup?

It is the source of open base models and datasets, and the place the agent publishes finished models, LoRA adapters, datasets and demos, privately or publicly.

How do I stop the agent from overspending on GPUs?

Keep a limited balance on Vast.ai, set a maximum hourly price and run length in the agent's instructions, and require it to destroy instances when a run ends and to check for running instances at the end of each session.

Do I need to know machine learning to use this?

It helps to know what you want the model to do and how you'll judge it. The agent handles the code, infrastructure and debugging, and explains its choices in plain language.

Claude and Claude Code are products of Anthropic. Vast.ai and Hugging Face are independent companies. WebHand is not affiliated with any of them.

Want an AI model agent with Hugging Face and Vast.ai already connected?

Two done-for-you plans at $499/month: we install Browser Use and Claude Code on your own server (Contabo, Hetzner, Amazon EC2), or give you a hosted Claude Code agent connected to Hugging Face and Vast.ai that builds and trains AI models. Setup and ongoing support included; you use your own Claude plan or API key.

See the two plans — $499/month