API
Errors and rate limits
The shape of an error, every error code with its HTTP status, the default rate limit, and what to retry.
이 페이지는 아직 번역되지 않아 영어 원문을 표시합니다.
The shape of an error
A request that fails answers with a 4xx or 5xx status and a JSON body in one shape:
{
"error": {
"code": "invalid_request",
"message": "input/prompt must NOT have fewer than 1 characters",
"param": "prompt"
}
}| Field | Description |
|---|---|
code | A stable identifier. Branch on this. |
message | A sentence for people. It can change; do not parse it. |
param | The 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
| Status | Code | Meaning | What to do |
|---|---|---|---|
| 400 | invalid_request | The request is malformed, a required field is missing, or input does not match the model's parameters. | Fix the request. param names the field. |
| 400 | content_blocked | The request was refused by the content policy. | Change the prompt or the input. |
| 400 | unsupported_media | An uploaded file is not an image, a video or an audio file. | Upload a supported file. |
| 400 | url_not_allowed | A URL you supplied is not https, is not publicly reachable, or redirects too often. | Use a public https URL. |
| 401 | invalid_api_key | The key is missing, malformed or unknown. | Check the Authorization header. |
| 401 | key_revoked | The key was revoked or has expired. | Create a new key. |
| 401 | unauthorized | The request is not authenticated. | Send a valid key. |
| 402 | insufficient_balance | The available balance does not cover the request. | Top up in the console. |
| 402 | spend_cap_reached | The key has reached its daily spend cap. | Raise the cap, or wait for the next UTC day. |
| 403 | ip_not_allowed | The request came from outside the key's IP allowlist. | Call from an allowed address, or change the allowlist. |
| 403 | model_not_allowed | The key is not allowed to use this model. | Use another key, or change the key's allowed models. |
| 403 | organization_suspended | The organization is suspended. | Contact support. |
| 403 | forbidden | The request is not permitted. | — |
| 404 | model_not_found | No such model, or it is no longer offered. | Check the ID against the model reference. |
| 404 | not_found | No such task or resource in your organization. | Check the ID. |
| 409 | idempotency_conflict | The Idempotency-Key was already used with a different request. | Use a new key for a new request. |
| 409 | not_cancelable | The task has started or has ended and cannot be canceled. | Nothing; let it finish. |
| 413 | file_too_large | The uploaded file is over the size limit. | Upload a file of 30 MB or less. |
| 429 | rate_limited | Too many requests in the current window. | Wait for Retry-After, then retry. |
| 429 | queue_full | Too many of your tasks are already waiting. | Wait for Retry-After, then retry. |
| 500 | internal_error | Something went wrong on our side. | Retry with backoff. Report it with the request ID if it persists. |
| 503 | upstream_unavailable | The 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 status | error.code | Meaning |
|---|---|---|
failed | content_blocked | The prompt or the result was refused by the content filter. |
failed | input_rejected | An input file could not be used. |
failed | invalid_request | The request was rejected, for example for a combination of parameters that is not supported. |
failed | upstream_unavailable | The model was temporarily unavailable. Creating the task again later may succeed. |
failed | capacity_timeout | The task waited in the queue and no capacity became free in time. |
expired | timeout | The task did not finish within the model's time limit. |
canceled | canceled | You canceled the task while it was queued. |
{
"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_limitedwith aRetry-Afterheader that says how many seconds remain in the window.
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
queueduntil a slot is free. Nothing fails; it waits. - The queue is bounded. When too many of your tasks are waiting,
POST /v1/tasksanswers429 queue_fullwith aRetry-Afterheader, and no task is created.
What to retry
| Situation | Retry? |
|---|---|
429 | Yes, after the number of seconds in Retry-After. |
500, 503 | Yes, 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 timeout | Yes. For POST /v1/tasks, send the same Idempotency-Key so a task that was created is returned and not created twice. |
402 | Only after topping up or raising the key's cap. |
Any other 4xx | No. 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' } }),
});import os
import random
import time
import uuid
import requests
class MinuError(Exception):
def __init__(self, status, error):
super().__init__(error.get("message", "request failed"))
self.status = status
self.code = error.get("code", "unknown")
self.param = error.get("param")
def minu(method, path, *, json=None, headers=None, attempts=5):
for attempt in range(attempts):
response = requests.request(
method,
f"https://api.minu.ai{path}",
json=json,
headers={"Authorization": f"Bearer {os.environ['MINU_API_KEY']}", **(headers or {})},
timeout=30,
)
if response.ok:
return response.json()
try:
error = response.json()["error"]
except (ValueError, KeyError):
error = {"code": "unknown", "message": response.reason}
retryable = response.status_code == 429 or response.status_code >= 500
if not retryable or attempt == attempts - 1:
raise MinuError(response.status_code, error)
# Wait as long as the API asks; otherwise back off exponentially, with a little jitter.
retry_after = response.headers.get("retry-after", "")
delay = float(retry_after) if retry_after.isdigit() else 0.5 * 2**attempt + random.random() * 0.25
time.sleep(delay)
# The Idempotency-Key makes the retry of a POST safe.
task = minu(
"POST",
"/v1/tasks",
headers={"Idempotency-Key": str(uuid.uuid4())},
json={"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.