Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

Workers AI Inference: Batch Jobs, Capacity Queue and LoRA Adapters

How Cloudflare Workers AI handles batch and async inference, rejectIfBusy capacity control, and LoRA fine-tune upload limits.

This page summarises Cloudflare Workers AI documentation on running inference at scale when synchronous limits bite, choosing between batch and asynchronous patterns, failing fast instead of waiting in a capacity queue, and using LoRA adapters for fine-tuned generation.

Workers AI capacity: why requests queue or fail

Section titled “Workers AI capacity: why requests queue or fail”

Workers AI applies rate and capacity limits per task type and model. When demand exceeds available inference capacity, synchronous calls may wait in a capacity queue rather than returning immediately. That behaviour suits interactive apps that can tolerate delay, but background jobs, agents, and API gateways often need predictable latency or guaranteed completion.

Note that model inferences in local mode using Wrangler will also count towards these limits.

— Cloudflare, Limits

For higher quotas or private models, Cloudflare points operators to a custom requirements form via the same Limits page.

rejectIfBusy: fail fast instead of waiting in the capacity queue

Section titled “rejectIfBusy: fail fast instead of waiting in the capacity queue”

What rejectIfBusy does on synchronous inference

Section titled “What rejectIfBusy does on synchronous inference”

The rejectIfBusy option tells Workers AI to reject a synchronous inference request when capacity is unavailable, instead of queueing it.

The rejectIfBusy option lets synchronous Workers AI inference requests fail when capacity is unavailable. Use it when your application should not wait in a capacity queue.

— Cloudflare, Reject busy requests

Typical uses include user-facing APIs where you would rather return an error and retry elsewhere than hold a connection open, and workers that implement their own backoff.

Workers binding: pass rejectIfBusy in the third argument

Section titled “Workers binding: pass rejectIfBusy in the third argument”

For env.AI.run(), put model input in the second argument and options in the third argument only. Do not put rejectIfBusy inside the model payload.

const response = await env.AI.run(
"@cf/google/gemma-4-26b-a4b-it",
{
messages: [
{
role: "user",
content: "Explain what a capacity queue is.",
},
],
},
{ rejectIfBusy: true },
);

— pattern from Cloudflare, Reject busy requests and Workers AI changelog

REST API and OpenAI-compatible Chat Completions

Section titled “REST API and OpenAI-compatible Chat Completions”

On the native REST ai/run endpoint, nest the flag under options in the JSON body, as shown in Reject busy requests.

For OpenAI-compatible Chat Completions:

For synchronous Chat Completions, set options.rejectIfBusy in the top-level request body. This makes the request fail instead of waiting in a capacity queue.

— Cloudflare, OpenAI compatible API endpoints

HTTP 429 and error code 3040 when capacity is exceeded

Section titled “HTTP 429 and error code 3040 when capacity is exceeded”

Rejected requests return HTTP status 429 with internal error code 3040 and message Capacity temporarily exceeded, please try again. See Reject busy requests for handling details.

Both patterns help large workloads, but they behave differently. Pick based on whether you need an array response in one call or durable queued jobs you poll later.

Pattern How you invoke it Best for Completion behaviour
Batch inference Array of requests in one call; models listed in changelog posts Summarization, embeddings, bulk jobs without a human in the loop Fulfilled as fast as possible; guaranteed eventual completion instead of failing for lack of capacity at a moment
Asynchronous batch API queueRequest: true, then poll with request_id Volumes above synchronous rate limits; non-real-time agents Pull-based queue; often completes within minutes depending on traffic

Batch inference: send an array and get an array back

Section titled “Batch inference: send an array and get an array back”

Introducing a new batch inference feature that allows you to send us an array of requests, which we will fulfill as fast as possible and send them back as an array. This is really helpful for large workloads such as summarization, embeddings, etc. where you don’t have a human-in-the-loop. Using the batch API will guarantee that your requests are fulfilled eventually, rather than erroring out if we don’t have enough capacity at a given time.

— Cloudflare, Workers AI for Developer Week changelog

Models called out in that announcement and related changelog entries include @cf/meta/llama-3.3-70b-instruct-fp8-fast, BGE embedding models (@cf/baai/bge-small-en-v1.5 through @cf/baai/bge-m3), and @cf/meta/m2m100-1.2b. Use the batch path when you want a single round trip that returns all results when ready, not a job ID.

Asynchronous API: queueRequest and polling

Section titled “Asynchronous API: queueRequest and polling”

For request volumes that exceed synchronous rate limits, Workers AI offers a redesigned asynchronous batch API with a pull-based queue:

For volumes of requests that exceed synchronous rate limits, you can submit batches of inferences to be completed asynchronously. We have revamped the Asynchronous Batch API with a pull-based system that processes queued requests as soon as capacity is available. With internal testing, async requests usually execute within 5 minutes, but this depends on live traffic.

— Cloudflare, Redesigned asynchronous API changelog

The async API is the best way to avoid capacity errors in durable workflows. It is ideal for use cases that are not real-time, such as code scanning agents or research agents.

— Cloudflare, Moonshot AI Kimi K2.5 changelog

Flow:

  1. Call env.AI.run with a requests array and { queueRequest: true }.
  2. Read request_id from the response.
  3. Poll with env.AI.run(model, { request_id }) until status is neither queued nor running.
  4. Optionally use event notifications instead of polling (mentioned in changelog/30).

The documented example uses @cf/moonshotai/kimi-k2.5; the same pattern appears across Workers AI product changelog pages.

LoRA fine-tunes: upload limits and inference on Workers AI

Section titled “LoRA fine-tunes: upload limits and inference on Workers AI”

Fine-tuning is a general term for modifying an AI model by continuing to train it with additional data. The goal of fine-tuning is to increase the probability that a generation is similar to your dataset.

— Cloudflare, Fine-tunes

Workers AI focuses on Low-Rank Adaptation (LoRA): adapter weights stay separate from the frozen base model, which keeps training practical compared with full weight updates. See Fine-tunes for the full explanation.

Using LoRA adapters notes the feature was in open beta and free during that period; check current status on Cloudflare’s site if you rely on billing assumptions.

From Using LoRA adapters and expanded LoRA support changelog:

  • Supported on listed base models (must not be quantized).
  • Rank r ≤ 8 historically; expanded support allows ranks up to 32.
  • Adapter file < 300MB (adapter_model.safetensors); config cap was 100MB before the expansion.
  • Files must be named exactly adapter_config.json and adapter_model.safetensors.
  • Up to 100 LoRA adapters per account for testing.
  • After upload, you cannot replace assets on an existing fine tune; create a new fine tune to change files (Using LoRA adapters).

Add model_type to adapter_config.json as one of mistral, gemma, or llama before upload, as shown in Using LoRA adapters.

Changelog posts list additional LoRA-capable bases such as @cf/meta/llama-3.3-70b-instruct-fp8-fast, @cf/google/gemma-3-12b-it, and @cf/qwen/qwen2.5-coder-32b-instruct, with some entries marked coming soon (changelog/51).

Training a LoRA (AutoTrain) and uploading with Wrangler or REST

Section titled “Training a LoRA (AutoTrain) and uploading with Wrangler or REST”

Cloudflare’s Fine Tune Models With AutoTrain from HuggingFace walks through CSV training data, Hugging Face AutoTrain on an A100 runtime, downloading adapter_model.safetensors and adapter_config.json, setting model_type, and uploading to your account.

Upload via Wrangler:

npx wrangler ai finetune create <model_name> <finetune_name> <folder_path>

Or multipart upload to
https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/finetunes/{FINETUNE_ID}/finetune-assets/
as documented under Using LoRA adapters.

The Workers AI changelog notes you can run LoRA inference with the base model rather than always targeting a -lora model id explicitly.

Cloudflare hosts ready-made adapters such as cf-public-magicoder, cf-public-jigsaw-classification, and cf-public-cnn-summarization, compatible with listed Mistral bases. Names use the cf-public-x pattern. List them with:

curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/ai/finetunes/public" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

See Public LoRA adapters. For best results, use the prompt template the adapter was trained on (Hugging Face repos linked from that page).

  • Putting rejectIfBusy in the model input object on the Workers binding instead of the third argument (Reject busy requests).
  • Expecting OpenAI SDK defaults to pass options.rejectIfBusy (OpenAI compatible API endpoints).
  • Confusing batch inference (one call, array in/out, listed models) with async queueRequest (job id, poll statuses queued / running).
  • Uploading LoRA files without model_type or with wrong filenames, causing rejected assets (Using LoRA adapters).
  • Hitting Wrangler local inference during development and forgetting it counts toward Limits.
  1. Send a synchronous env.AI.run or REST ai/run call with { rejectIfBusy: true } during peak usage and confirm you receive HTTP 429 with error 3040 when capacity is tight, per Reject busy requests.

  2. Run a small batch inference job on a supported model from changelog/51 and confirm all array elements return without capacity failures.

  3. Queue a test job with queueRequest: true, poll until status leaves queued/running, and compare elapsed time to the ~5 minute guidance in changelog/30.

  4. List account fine tunes with npx wrangler ai finetune list or call the public finetunes API, then run inference with a uploaded or public LoRA per Using LoRA adapters.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page does not match your experience or the linked Cloudflare docs, email yimasynthetic@gmail.com with the page URL and the exact wording you think is wrong or unclear.