This site is not affiliated with or endorsed by Cloudflare, Inc. It simply showcases experiments built using Cloudflare services.
Cloudflare Experiments

AI Batch Infer

Workers AI async batch embeddings with queueRequest and poll

Submit a batch of Workers AI embedding inferences with queueRequest: true, then poll by request_id via the Asynchronous Batch API. Without an AI binding, routes return demo queued/poll responses.

Features

  • Queue embedding batches (POST /batch)
  • Poll results by request_id (GET /batch/:requestId)
  • Configurable model via MODEL var (default @cf/baai/bge-m3)

API Reference

POST /batch

Body

{
  "texts": ["first phrase", "second phrase"]
}
FieldRequiredDescription
textsYes1–20 non-empty strings, max 2000 chars each

Example Request

curl -X POST "https://your-worker.workers.dev/batch" \
  -H "Content-Type: application/json" \
  -d '{"texts":["Cloudflare Workers","edge compute"]}'

Success Response

{
  "status": "queued",
  "model": "@cf/baai/bge-m3",
  "request_id": "000-000-000",
  "mode": "live"
}

Error Codes

  • 400 - Invalid body (INVALID_BODY)
  • 502 - Batch submit failure (BATCH_ERROR)

GET /batch/:requestId

Poll status/results for a queued batch.

Example Request

curl "https://your-worker.workers.dev/batch/000-000-000"

While processing, the API may return queued or running. When complete, the response includes per-item results.

Error Codes

  • 400 - Invalid id (INVALID_REQUEST_ID)
  • 502 - Poll failure (BATCH_ERROR)

Use Cases

  • Offline embedding of large document sets
  • Batch summarization / classification without interactive latency
  • Avoid capacity errors by queueing inference for eventual completion

Limitations

  • Total batch payload must stay under ~10 MB (Workers AI limit)
  • Needs a batch-capable model and account AI access for live mode
  • Demo mode returns placeholder embeddings

Deployment

Click the deploy button

Deploy to Cloudflare Workers

Confirm AI binding

wrangler.json declares ai.binding: "AI" and vars.MODEL (default @cf/baai/bge-m3).

Test your deployment

curl -X POST "https://your-worker.workers.dev/batch" \
  -H "Content-Type: application/json" \
  -d '{"texts":["hello","world"]}'

Local Development

cd apps/experiments/ai-batch-infer
npm install
npm run dev

Workers AI batch typically needs remote AI / account access.

Configuration

  • Workers AI binding AI
  • Var MODEL — batch embedding model id

Cloudflare Features Used

On this page