In Workers AI, how do you run a LoRA adapter trained on your support tone, and what does Cloudflare require of the adapter?
answer
- a base model that accepts adapters
- two files with exact names
- a finetune created per upload
- the lora input
basics
~20 sUpload the adapter with wrangler ai finetune create against a LoRA-capable base model, then call env.AI.run() on that base with lora set to the finetune's name or id. The adapter is two exactly named files, under 300 MB, rank up to 32.
solid answer
~40 sPick a base model that lists LoRA support and is not quantized, such as `@cf/mistral/mistral-7b-instruct-v0.2-lora` or `@cf/google/gemma-7b-it-lora`. The adapter folder must hold exactly `adapter_config.json` and `adapter_model.safetensors`, with `model_type` (`mistral`, `gemma` or `llama`) added to the config; the weights file must be under 300 MB and the rank at most 32. `wrangler ai finetune create <model_name> <finetune_name> <folder_path>` creates the finetune and uploads both files; an account can hold up to 100 adapters, and a finetune's files cannot be edited, so a retrained adapter becomes a new finetune. At inference, `env.AI.run()` names the base model and passes `lora` with the finetune's name or id, usually with `raw: true` and the chat template the adapter was trained on. A base model without LoRA support answers with error `5005`.
go deeper
Know that Workers AI runs a LoRA adapter on top of a supported base model, selected with the lora input.
Explain the upload contract: two exactly named files, model_type in the config, rank up to 32, under 300 MB, via wrangler ai finetune create.
Show the operating habits: new finetune per retrain, a named version to roll back to, raw: true with the training template, and 5005 read as an unsupported base.
Weigh an adapter against prompting alone: it adds a training pipeline, a beta feature and a base model that may be retired, in exchange for tone the prompt cannot hold.
## What a LoRA adapter gives the support team A **LoRA** (Low-Rank Adaptation) adapter is a small set of extra weights trained on top of a base model. For the support-ticket product, an adapter trained on past replies can make drafts follow the team's tone and structure without running a separate full model. Workers AI serves adapters on top of its own base models: you upload the adapter, and each call names the base model plus the adapter. The docs describe this as an **open beta, free during the beta**. How rank and alpha shape training is covered with LoRA fine-tuning in general; this answer is about what Workers AI accepts. ## Choosing a base model Only some catalogue models accept adapters, and they must **not be quantized**. The catalogue marks them with a LoRA capability, for example: - `@cf/mistral/mistral-7b-instruct-v0.2-lora` - `@cf/google/gemma-7b-it-lora` and `@cf/google/gemma-2b-it-lora` - `@cf/meta-llama/llama-2-7b-chat-hf-lora` - some newer instruct models, such as `@cf/meta/llama-3.2-3b-instruct` The adapter must have been trained against that same base model. Calling `lora` on a model without LoRA support fails with error `5005` (LoRa unsupported). ## Preparing the adapter | Requirement | Value | |---|---| | Files | exactly `adapter_config.json` and `adapter_model.safetensors` | | Config field to add | `model_type`: `mistral`, `gemma` or `llama` | | Rank | up to 32 (`r` in the adapter's config) | | Weights file size | under 300 MB | | Adapters per account | up to 100 | If a training run wrote the weights in another format, such as a `.bin` file, convert them first, because only these two files are accepted. ## Uploading it With Wrangler: ```bash npx wrangler ai finetune create @cf/mistral/mistral-7b-instruct-v0.2-lora support-tone ./support-tone-adapter npx wrangler ai finetune list ``` `wrangler ai finetune create` takes three positional arguments, the base model, a name for the finetune and the folder, and uploads both files. The REST API offers the same steps: `POST /accounts/{account_id}/ai/finetunes` creates the finetune, and each file is posted to its `finetune-assets` endpoint, with a token holding `Workers AI: Edit`. A finetune's files **cannot be edited after upload**. A retrained adapter is uploaded as a new finetune with a new name (for example `support-tone-v2`), and the calling code switches to it. That also gives a clean rollback: point back at the old name. ## Calling it ```javascript const result = await env.AI.run("@cf/mistral/mistral-7b-instruct-v0.2-lora", { prompt: "<s>[INST] Draft a reply to: my invoice shows the wrong VAT number [/INST]", raw: true, lora: "support-tone", max_tokens: 400, }); ``` - `lora` takes the finetune's **name or id** and sits in the inputs, not in the third options argument. - `raw: true` skips the model's default chat template, so the prompt must be in the template the adapter was trained on. - Cloudflare also publishes a few public adapters named `cf-public-*` (for example `cf-public-cnn-summarization`), listed through `/ai/finetunes/public`. ## When an adapter is worth it An adapter is extra machinery: a training pipeline, a versioned upload, a beta feature and a base model the catalogue may retire. It earns that cost when prompting cannot hold the behaviour: - the team's tone or reply structure is consistent and well represented in past replies, but a long system prompt still drifts; - a small LoRA-capable base model with an adapter matches a larger model's quality on the task at lower neuron cost; - the output format is strict, and examples in the prompt make every call longer and dearer. When none of these hold, a good system prompt on a stronger catalogue model is simpler to run. ## Operating it 1. Keep the adapter's name in configuration next to the base model id, and change both together. 2. Watch the changelog: the `-lora` base variants stayed active through the May 2026 catalogue deprecations, but the docs warn that LoRA models may be deprecated later, with notice to retrain. 3. Evaluate a new adapter on held-out tickets before switching traffic to its name.
- The team retrains its Workers AI support-tone adapter monthly; how should each new version be rolled out?Upload each version as its own finetune, such as `support-tone-2026-11`, because a finetune's files cannot be edited after upload. Keep the active name in configuration, evaluate the new finetune on held-out tickets, switch the `lora` value to it, and keep the previous name for rollback. The 100-adapter account limit caps how many versions you can keep at once.
- Why do Workers AI LoRA examples set raw: true?`raw: true` tells the model not to apply its default chat template. An adapter learns the exact prompt format it was trained with, so the caller supplies that template itself. Without `raw`, the default template wraps the prompt in a format the adapter may not have seen, and output quality can drop.
- Any catalogue model, including quantized ones, accepts a LoRA adapter.
- The adapter's id goes in the third options argument of env.AI.run().
- A finetune's adapter files can be replaced in place after retraining.
- Workers AI accepts adapter weights under any file name.
- The adapter is called as its own model id instead of with the base model.
As of 2026-10-10, LoRA inference on Workers AI is an open beta; the -lora base variants survived the May 2026 model deprecations, and the docs say LoRA models may be deprecated later.