İçeriğe geç
Dokümanlar:Errors and rate limits

API’ler

Errors and rate limits

The shape of an error, every error code with its HTTP status, the default rate limit, and what to retry.

Bu sayfa henüz çevrilmedi. İngilizce sürümü gösteriliyor.

The shape of an error

A request that fails answers with a 4xx or 5xx status and a JSON body in one shape:

JSON
{
  "error": {
    "code": "invalid_request",
    "message": "input/prompt must NOT have fewer than 1 characters",
    "param": "prompt"
  }
}
FieldDescription
codeA stable identifier. Branch on this.
messageA sentence for people. It can change; do not parse it.
paramThe field at fault, when the error is about one field. Not always present.

Every response, successful or not, carries an x-request-id header. An internal_error also repeats it in the body as request_id. Quote it when you contact support.

Error codes

StatusCodeMeaningWhat to do
400invalid_requestThe request is malformed, a required field is missing, or input does not match the model's parameters.Fix the request. param names the field.
400content_blockedThe request was refused by the content policy.Change the prompt or the input.
400unsupported_mediaAn uploaded file is not an image, a video or an audio file.Upload a supported file.
400url_not_allowedA URL you supplied is not https, is not publicly reachable, or redirects too often.Use a public https URL.
401invalid_api_keyThe key is missing, malformed or unknown.Check the Authorization header.
401key_revokedThe key was revoked or has expired.Create a new key.
401unauthorizedThe request is not authenticated.Send a valid key.
402insufficient_balanceThe available balance does not cover the request.Top up in the console.
402spend_cap_reachedThe key has reached its daily spend cap.Raise the cap, or wait for the next UTC day.
403ip_not_allowedThe request came from outside the key's IP allowlist.Call from an allowed address, or change the allowlist.
403model_not_allowedThe key is not allowed to use this model.Use another key, or change the key's allowed models.
403organization_suspendedThe organization is suspended.Contact support.
403forbiddenThe request is not permitted.—
404model_not_foundNo such model, or it is no longer offered.Check the ID against the model reference.
404not_foundNo such task or resource in your organization.Check the ID.
409idempotency_conflictThe Idempotency-Key was already used with a different request.Use a new key for a new request.
409not_cancelableThe task has started or has ended and cannot be canceled.Nothing; let it finish.
413file_too_largeThe uploaded file is over the size limit.Upload a file of 30 MB or less.
429rate_limitedToo many requests in the current window.Wait for Retry-After, then retry.
429queue_fullToo many of your tasks are already waiting.Wait for Retry-After, then retry.
500internal_errorSomething went wrong on our side.Retry with backoff. Report it with the request ID if it persists.
503upstream_unavailableThe model cannot take the request right now.Retry with backoff.

Errors on a task

The codes above answer an HTTP request. A task that was accepted and then did not succeed reports its reason in the task's own error field, with one of these codes. None of them is charged.

Task statuserror.codeMeaning
failedcontent_blockedThe prompt or the result was refused by the content filter.
failedinput_rejectedAn input file could not be used.
failedinvalid_requestThe request was rejected, for example for a combination of parameters that is not supported.
failedupstream_unavailableThe model was temporarily unavailable. Creating the task again later may succeed.
failedcapacity_timeoutThe task waited in the queue and no capacity became free in time.
expiredtimeoutThe task did not finish within the model's time limit.
canceledcanceledYou canceled the task while it was queued.
JSON
{
  "id": "task_1k8r2m4p0a7c9e3g5j6n8q2s",
  "object": "task",
  "status": "failed",
  "outputs": [],
  "error": {
    "code": "content_blocked",
    "message": "The request was refused by the content filter. You were not charged."
  },
  "estimated_cost_usd": "0.033000",
  "cost_usd": "0.000000"
}

Rate limits

20 requests per 10 seconds, per organization, by default.

  • The limit is shared by every API key of the organization and counts every authenticated request, including the ones you make to poll tasks.
  • Requests are counted in fixed 10-second windows. A request over the limit answers 429 rate_limited with a Retry-After header that says how many seconds remain in the window.
HTTP
HTTP/1.1 429 Too Many Requests
retry-after: 4
content-type: application/json

{"error":{"code":"rate_limited","message":"Rate limit reached: 20 requests per 10 seconds."}}

To stay under the limit, use webhooks instead of polling, and poll no faster than you need when you do. If the default does not fit your traffic, talk to us.

Concurrency and the queue

The rate limit is about requests. A second limit is about work: each organization runs a limited number of tasks at the same time.

  • A task beyond the concurrency limit is accepted and stays queued until a slot is free. Nothing fails; it waits.
  • The queue is bounded. When too many of your tasks are waiting, POST /v1/tasks answers 429 queue_full with a Retry-After header, and no task is created.

What to retry

SituationRetry?
429Yes, after the number of seconds in Retry-After.
500, 503Yes, with exponential backoff: for example 0.5 s, 1 s, 2 s, 4 s, with some random jitter. Give up after a few attempts.
Network error or timeoutYes. For POST /v1/tasks, send the same Idempotency-Key so a task that was created is returned and not created twice.
402Only after topping up or raising the key's cap.
Any other 4xxNo. The same request will fail the same way; fix it first.
import { randomUUID } from 'node:crypto';

async function minu(path, init = {}, attempt = 0) {
  const response = await fetch(`https://api.minu.ai${path}`, {
    ...init,
    headers: {
      Authorization: `Bearer ${process.env.MINU_API_KEY}`,
      'Content-Type': 'application/json',
      ...init.headers,
    },
  });
  if (response.ok) return response.json();

  const body = await response.json().catch(() => null);
  const error = body?.error ?? { code: 'unknown', message: response.statusText };
  const retryable = response.status === 429 || response.status >= 500;
  if (!retryable || attempt >= 4) {
    throw Object.assign(new Error(error.message), { status: response.status, code: error.code, param: error.param });
  }

  // Wait as long as the API asks; otherwise back off exponentially, with a little jitter.
  const retryAfter = Number(response.headers.get('retry-after'));
  const delayMs = retryAfter > 0 ? retryAfter * 1000 : 500 * 2 ** attempt + Math.random() * 250;
  await new Promise((resolve) => setTimeout(resolve, delayMs));
  return minu(path, init, attempt + 1);
}

// The Idempotency-Key makes the retry of a POST safe.
const task = await minu('/v1/tasks', {
  method: 'POST',
  headers: { 'Idempotency-Key': randomUUID() },
  body: JSON.stringify({ model: 'google/nano-banana-2', input: { prompt: 'A lighthouse at dusk' } }),
});

Errors from the OpenAI-compatible endpoints

POST /v1/chat/completions and POST /v1/audio/transcriptions use the same status codes and the same error.code values, so the official OpenAI SDKs raise their usual exceptions (an authentication error for 401, a rate-limit error for 429, and so on). See OpenAI-compatible API.