Skip to content

Production reliability guide

Retry Comic API requests without creating duplicate work.

A production integration classifies each response, assigns an Idempotency-Key to a create intent, honors Retry-After when present, and retries only bounded transient failures.

Retries are not a blanket response to every error. Authentication, payment, permission, and validation failures require correction; rate-limit and transient service failures may be retried under an explicit policy.

Verify current error responses

Account, API key, usage, and billing open on LlamaGen.AI.

Direct answer

The decision this page is for.

Last verified:

Assign one Idempotency-Key to each create intent, store the request and any generation ID, and retry only bounded transient responses. Correct 400, 401, 402, and 403 failures; honor Retry-After for 429; reconcile uncertain 500 or 503 outcomes before creating a new intent.

Verifiable request

Bounded create retry with one idempotency key

JavaScript
const endpoint = "https://api.llamagen.ai/v1/comics/generations";
const idempotencyKey = crypto.randomUUID();

for (let attempt = 0; attempt < 4; attempt += 1) {
  const response = await fetch(endpoint, {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.LLAMAGEN_API_KEY,
      "Content-Type": "application/json",
      "Idempotency-Key": idempotencyKey,
    },
    body: JSON.stringify({ prompt: "An original four-panel rescue story.", fixPanelNum: 4 }),
  });

  if (response.ok) break;
  if (![429, 500, 503].includes(response.status) || attempt === 3) {
    throw new Error("Comic API failed with HTTP " + response.status);
  }

  const retryAfterHeader = response.headers.get("retry-after");
  const retryAfterSeconds = Number(retryAfterHeader);
  const serverDelayMs = retryAfterHeader && Number.isFinite(retryAfterSeconds)
    ? retryAfterSeconds * 1000
    : 0;
  const delayMs = response.status === 503
    ? Math.max(serverDelayMs, 5 * 60 * 1000)
    : serverDelayMs || Math.min(1000 * 2 ** attempt, 8000);
  await new Promise((resolve) => setTimeout(resolve, delayMs));
}

Structured response

State your application can route

response.jsonILLUSTRATIVE
{
  "retryPolicy": {
    "doNotRetry": [
      400,
      401,
      402,
      403
    ],
    "conditionalRetry": [
      429,
      500,
      503
    ],
    "serviceUnavailableMinimumSeconds": 300,
    "maxAttempts": 4
  },
  "note": "Application policy example; confirm current API behavior."
}

Reliability walkthrough

Treat retries as an observable production decision.

The operations scene links one guarded request path, recovery state, human review, and a finished artifact without implying guaranteed uptime.

Two production teammates trace a failed generation path while reviewing a completed multi-panel comic proof
Editorial illustration generated with AI; it is not a real operations team and not a generated API result.Art direction · American operations editorial

Failure decision tree

Correct permanent failures; delay and reconcile transient ones.

The retry owner needs the original intent, one stable idempotency key, attempt count, last response, and any returned generation ID before deciding what happens next.

  1. 01Application

    Persist the intent

    Create a local request record and stable idempotency key before the first billable POST.

  2. 02Worker

    Classify the response

    Separate validation, authentication, billing, permission, rate-limit, and server-availability failures.

  3. 03Retry scheduler

    Honor server guidance

    Use Retry-After when present, enforce the documented five-minute minimum for 503, and cap every retry sequence.

  4. 04Operations

    Reconcile uncertainty

    Keep the same key, store any generation ID, and check existing state before creating a replacement intent.

  5. 05Product

    Expose a terminal state

    Show the user whether the request needs correction, more balance, support, or a later retry.

Capability and boundary facts

Facts an integration can verify.

Last verified:

Duplicate control
Optional Idempotency-Key on POST /v1/comics/generations
Rate limit
429 may include Retry-After
Correct before retry
400, 401, 402, and 403 classes
Service recovery
Bound 500 retries; wait at least five minutes before a same-key 503 retry
Verification
Contract checked against the LlamaGen OpenAPI file on 2026-10-28

Good fit

Use it when

  • Paid-order generation with duplicate protection
  • Workers that can persist request intent and generation ID
  • Operational dashboards that distinguish corrective from transient failures

Wrong fit

Do not use it for

  • Retrying validation or permission errors unchanged
  • Infinite exponential backoff
  • Claiming exactly-once delivery without reconciliation

Production limits

Plan for the boundaries.

  • 01Idempotency reduces duplicate creation risk but is not a substitute for storing the generation ID and reconciling uncertain responses.
  • 02The OpenAPI description says an idempotency marker lasts five minutes and an existing generation may be returned later; do not change the key while the original outcome is uncertain.
  • 03A 503 can indicate the idempotency store is unavailable or a previous request is pending confirmation; follow the current API description and support guidance before retrying.
  • 04The JavaScript is a policy example and was not executed against a paid account from this page.
  • 05Generation is asynchronous; production interfaces must handle processing and failure states.
  • 06Outputs should be reviewed against product, brand, safety, and print requirements before delivery.
  • 07You must have the rights to prompts, photos, scripts, and reference assets submitted to the API.

Questions

Direct answers before you integrate.

01Which Comic API errors should I retry?
Retry 429, 500, or 503 only under a bounded policy and with the same idempotency key for the same create intent. Validation, authentication, billing, and permission failures need correction rather than an unchanged retry.
02Does an Idempotency-Key guarantee exactly-once generation?
No. It reduces duplicate creation risk. Persist the local intent and returned generation ID, keep the key stable while the outcome is uncertain, and reconcile state before creating a replacement request.
03What should the user see during a retry?
Expose a real queued, delayed, corrective, or failed state. A create timeout is not proof that no generation exists, so do not invite an immediate second purchase or duplicate submission.

Next step

Move from evidence to a real API request.

LlamaGen provides the playground, API key, usage, billing, and authoritative service documentation.

Verify current error responses