Skip to content

workers-ai-provider: Workers AI rate-limit error 3021 is classified as non-retryable #657

Description

@scott-edwards

Workers AI binding error 3021 is treated as non-retryable despite HTTP 429

workers-ai-provider@4.0.0 does not recognize Workers AI inference RPM-limit code 3021. The native binding throws Error("3021: rate limiting: inference request per min rate reached"). normalizeBindingError constructs an APICallError without statusCode, with isRetryable: false, so native AI SDK retries stop immediately.

The corresponding stored Workers AI Gateway response was HTTP 429 with httpCode: 429, internalCode: 3021, name: "AiError", and the same description. No customer identifiers or private prompts are included here.

Reproduction

import { createWorkersAI } from "workers-ai-provider";

const model = createWorkersAI({
  binding: {
    run: async () => {
      throw new Error("3021: rate limiting: inference request per min rate reached");
    },
  },
})("@cf/zai-org/glm-5.3-flash");

try {
  await model.doStream({
    prompt: [{ role: "user", content: [{ type: "text", text: "Welcome" }] }],
  });
} catch (error) {
  console.log(error.statusCode, error.isRetryable);
  // Actual: undefined, false. Expected: 429, true.
}

Proposed correction

Add 3021: 429 to WORKERS_AI_ERROR_CODE_TO_STATUS in packages/gateway-core/src/workers-ai-errors.ts. This also lets the existing parser recognize the error code. No custom retry loop is required.

Validation

An isolated copy of the released package fails four rate-limit tests before the correction and passes all seven tests after it:

  • Streaming and non-streaming binding errors retain their cause and map to retryable HTTP 429.
  • Native AI SDK streamText and generateText each recover after two simulated 3021 errors, using the SDK's existing increasing delays (approximately 2 and 4 seconds).
  • Invalid input, unknown errors, and cancellation do not retry.

This is controlled local validation, not a production load test. The numeric model/account RPM limit is not established by this report.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions