RawFrame

Errors

The error shape, what each type means, and which errors to retry.

There are two kinds of failure, and they look different:

  • The request is rejected. The API answers with a non-2xx status and an error body. Nothing was queued or charged.
  • A generation fails. It was accepted (202), ran, and ended with status failed and an error object. Failed generations aren't charged.

Request errors

Every error response has the same shape:

{
  "error": {
    "type": "invalid_request",
    "code": "invalid_parameters",
    "message": "Unsupported duration 7. Allowed: 5, 10",
    "param": "params.duration_seconds",
    "request_id": "req_b742b89c4fc9d7ece5d783ae"
  }
}

type is the broad category and decides the HTTP status. code is the specific reason. Both are stable, so branch on them, not on message, which is for people and may change. param names the offending field when there is one. Include request_id (also in the X-Request-Id header) when you contact support.

typeStatusMeaningRetry?
invalid_request400The request is malformed or asks for something the model doesn't support.No, fix it
authentication401Missing, malformed or revoked API key.No
insufficient_credits402The balance can't cover the generation's maximum price.After topping up
permission403The key lacks a scope, or the organization is suspended.No
not_found404No such model, generation, upload or endpoint in your organization.No
conflict409The request conflicts with current state.Depends on code
content_policy422The prompt or a reference was refused before it ran.No, change it
rate_limit429Too many requests, or too many generations in progress.Yes, after Retry-After
provider502The model is unavailable right now (model_unavailable).Yes, later
internal500Something went wrong on our side.Yes, with backoff

Common codes:

codeTypeWhat to do
invalid_parametersinvalid_requestparam says which field. The model page lists accepted values.
invalid_request_bodyinvalid_requestThe JSON doesn't match the schema, e.g. an unknown field.
feature_not_availableinvalid_requestwebhook_url isn't available yet.
upload_incomplete, upload_rejected, upload_expired, upload_not_foundinvalid_requestSee Uploads.
missing_scopepermissionUse a key with the scope named in the message.
idempotency_key_reusedconflictThe key was used with a different request body. Use a new key.
generation_finishedconflictYou tried to cancel a generation that already finished.
rate_limitedrate_limitWait Retry-After seconds.
concurrency_limitrate_limitWait for a running generation to finish.
daily_spend_limitrate_limitThe organization reached its daily spending limit. It resets at 00:00 UTC (Retry-After says when); contact support to raise it. New organizations have a lower limit until their first payment is a day old.
model_unavailableproviderTry again later, or use another model.

Generation errors

A failed generation's error has a code, a message, and retryable, which says whether sending the same request again might work.

codeMeaningretryable
content_rejectedThe provider or our checks refused the prompt, a reference or the output.No
invalid_parametersThe provider rejected a value we passed on.No
provider_rate_limitedThe provider was overloaded, even after our retries.Yes
provider_unavailableThe provider was down, even after our retries.Yes
quota_exhaustedThe provider's capacity for this model ran out.Yes
provider_timeoutThe provider didn't finish within the model's time limit.No
provider_internal_errorThe provider failed in a way we couldn't classify.No
internal_errorWe failed.No

We retry temporary provider problems before failing a generation, so a retryable failure means the problem lasted a while. Wait a minute or more before retrying it.

In the SDKs

API errors raise RawFrameError with status, type, code, param and requestId / request_id. createAndWait and waitForCompletion raise GenerationFailedError, with the failed generation attached, when a generation fails or is canceled. Network failures raise APIConnectionError.

import { GenerationFailedError, RawFrame, RawFrameError } from "@rawframe/sdk";

const rf = new RawFrame();

try {
  await rf.generations.createAndWait({
    model: "bytedance/seedance-2.5",
    prompt: "A lighthouse in a storm",
    params: { duration_seconds: 7 }, // not a supported duration
  });
} catch (err) {
  if (err instanceof RawFrameError) {
    // The API rejected the request. Nothing was queued or charged.
    console.log(err.status, err.type, err.code, err.param, err.requestId);
    if (err.type === "insufficient_credits") {
      // Top up, or turn on auto-recharge, then retry.
    }
  } else if (err instanceof GenerationFailedError) {
    // The generation ran and failed. Failed generations aren't charged.
    const { code, retryable } = err.generation.error ?? {};
    console.log("failed:", code, retryable ? "(worth retrying)" : "");
  } else {
    throw err;
  }
}

On this page