sangtao.ai
API key

Tổng quan

Mã lỗi

Định dạng lỗi

Mọi lượt gọi lỗi — sai key, thiếu trường, sai đường dẫn — đều trả JSON theo đúng khuôn này:

json
{
  "success": false,
  "errorCode": "INVALID_DPI",
  "error": "dpi must be between 1 and 1200.",
  "details": [
    {
      "field": "dpi",
      "code": "INVALID_DPI",
      "message": "dpi must be between 1 and 1200.",
      "params": { "min": 1, "max": 1200 }
    }
  ],
  "requestId": "4bf92f3577b34da6a3ce929d0e0e4736"
}

Code theo errorCode — đừng theo câu lỗi, cũng đừng theo mã HTTP (vài mã có endpoint trả HTTP khác). Ý nghĩa từng trường: Quy ước API.

Mã trạng thái HTTP

MãÝ nghĩaCách xử lý
200 / 201Thành côngĐọc trường data
400Request không hợp lệSửa trường mà error nêu rồi gửi lại
401Thiếu key hoặc sai keyGửi key đúng trong header X-Api-Key
402Không đủ creditNạp thêm rồi thử lại — thử lại trước đó vẫn lỗi như cũ
403Không có quyềnKey này không dùng được endpoint này
404Không tìm thấyKiểm tra đường dẫn và id
409Đã làm rồiViệc này đã được làm (xác nhận một file hai lần) — đừng gửi lại
422Dữ liệu sai giá trị (tạo ảnh)Xem errorCode, sửa giá trị rồi gửi lại
429Gọi quá nhanhĐợi rồi thử lại, giãn dần khoảng chờ
500 / 502 / 503Lỗi máy chủThử lại sau vài giây; vẫn lỗi thì liên hệ hỗ trợ

Đa số endpoint báo request sai bằng 400. Riêng tạo ảnh (POST /images/generations) trả 422 — thiếu model hoặc prompt, aspectRatio, format, resolution hay dpi không hợp lệ, hoặc link ảnh tham chiếu không tồn tại.

Danh sách mã lỗi

Danh sách đầy đủ, đọc từ GET /v2/errors (không cần key). Câu lỗi để tiếng Anh, đúng như khi gọi bằng API key; {tên} được điền từ details[].params. Cột HTTP là mã thường gặp — endpoint nào trả mã khác thì ghi ở trang của endpoint đó.

Mã endpoint nào cũng có thể trả:

errorCodeHTTPCâu lỗiThử lại?
BAD_REQUEST400The request is invalid.Không
VALIDATION_ERROR400 (có endpoint trả 422)The request contains invalid fields. See details.Không
BODY_REQUIRED400Request body is required.Không
UNAUTHORIZED401Missing or invalid API key.Không
FORBIDDEN403You do not have permission to do this.Không
NOT_FOUND404The requested resource was not found.Không
CONFLICT409The request conflicts with the current state of the resource.Không
PAYLOAD_TOO_LARGE413The request body is too large.Không
INSUFFICIENT_CREDITS402Not enough credits. Required: {required}, available: {available}.Không
RATE_LIMITED429Too many requests. Retry after {retryAfter} seconds.Có
TOO_MANY_ACTIVE_JOBS429Too many active jobs ({active}/{limit}). Wait for current jobs to finish.Có
INTERNAL_ERROR500Something went wrong on our side. Please try again.Có
UPSTREAM_ERROR502A downstream service failed. Please try again.Có
SERVICE_UNAVAILABLE503Service temporarily unavailable. Please try again later.Có

Mã của từng nhóm endpoint:

errorCodeHTTPCâu lỗiThử lại?
ENDPOINT_NOT_FOUND404Endpoint not found. Check the path and HTTP method.Không
MODEL_REQUIRED422model is required.Không
PROMPT_REQUIRED422prompt is required.Không
MODEL_NOT_FOUND404Model not found. See GET /v2/models for available models.Không
MODEL_WRONG_CATEGORY422This model belongs to another category. Use the endpoint for its category.Không
SERVER_NOT_FOUND422This server is not available for the model. See details for available servers.Không
IDEMPOTENCY_KEY_REUSED422This idempotency key was already used for a different request. Use a new key.Không
INVALID_DPI422dpi must be between {min} and {max}.Không
INVALID_FORMAT422format must be one of: {allowed}.Không
INVALID_ASPECT_RATIO422aspectRatio must be W:H (positive integers, e.g. 16:9) or "auto", at most {max}:1. Received "{value}".Không
INVALID_RESOLUTION422resolution '{value}' is not valid. Use one of: {supported}.Không
RESOLUTION_NOT_SUPPORTED422Resolution '{value}' is not supported yet. Available: {supported}.Không
REFERENCE_IMAGE_UNREACHABLE422 (có endpoint trả 400)Could not download reference image: {url}. Check that the link is alive and allows server downloads.Không
AGENT_QUEUE_FULL429The queue is full ({queued} waiting, {running} running). Try again shortly.Có
NO_AGENT_AVAILABLE503No worker is available right now. Please try again shortly.Có
INVALID_COUNT422count must be between {min} and {max}.Không
COUNT_NOT_SUPPORTED_FOR_API_KEY400count is web-only. With an API key, send one request per image.Không
ROUND_NOT_AFFORDABLE402Not enough credits for this many images.Không
INVALID_VISIBILITY422visibility must be 'public' or 'private'.Không
RESOLUTION_REQUIRES_PLAN403This resolution requires an active plan.Không
JOB_NOT_FOUND404Job not found.Không
JOB_NOT_READY400The job has not finished yet.Không
JOB_PUBLISHED409The job is published. Unpublish it first.Không
CHARACTER_NOT_FOUND404Character not found.Không
REF_IMAGE_NOT_FOUND404Reference image not found.Không
ASSET_NOT_FOUND404Asset not found.Không
ASSET_ALREADY_CONFIRMED409This upload was already confirmed.Không
UNSUPPORTED_FILE_TYPE400Unsupported file type.Không
UPLOAD_FAILED400 (có endpoint trả 500)Upload failed. Please try again.Có
QUOTA_EXCEEDED429 (có endpoint trả 400)Quota exceeded. Delete some items or upgrade your plan.Không
UPLOAD_QUOTA_EXCEEDED429Daily upload limit reached. Try again after 00:00 UTC, or use an image URL you already host.Có
TEAM_NOT_FOUND404Publishing team not found.Không
POST_NOT_FOUND404Post not found.Không
PUBLISH_FAILED502Could not publish. Please try again.Có
NO_API_ACCESS403Your plan does not include API access.Không
NO_PUBLISHING_TEAM404No publishing team found. Connect a social account first.Không
INVALID_GENRE422Unknown music genre.Không
NO_CONNECTED_ACCOUNT400This platform is not connected. Connect it first.Không
ACCOUNT_NEEDS_ATTENTION409The page for {platform} changed or lost access. Select the page again before posting.Không
CHANNEL_LIMIT403Connected channel limit reached.Không
NO_SUBSCRIPTION500Publishing is not set up for this account. Contact support.Không
INVALID_DATE_RANGE400Invalid date range. Use 1DAY, 7DAY or 30DAY.Không
BRAND_KIT_NOT_FOUND404Brand kit not found, or it belongs to another account.Không
STYLE_NOT_FOUND404Saved style not found, or it belongs to another account.Không
PROPS_INVALID400A request field is invalid. The error message says which one.Không
PROP_INVALID400Field {field} {reason}.Không
PROP_TOO_LONG400Field {field} {reason}.Không
PROP_REQUIRED400Field {field} {reason}.Không
ASSET_INVALID400The file could not be used. The error message says why.Không
ASSET_MISSING404The referenced asset was not found.Không
ASSET_KIND_NOT_ALLOWED400This kind of asset is not allowed here.Không
AUDIO_SOURCE_CONFLICT400Send only one of audioKey or audioUrl.Không
ROTATE_REQUIRES_LOGIN403An API key cannot rotate itself. Sign in to rotate it.Không

Webhook:

errorCodeHTTPCâu lỗiThử lại?
INVALID_WEBHOOK_URL422url must be a public https URL on port 443 without credentials.Không
INVALID_WEBHOOK_EVENT422Unknown event type. See details for allowed values.Không
WEBHOOK_LIMIT_REACHED422You can have at most {limit} webhook endpoints.Không
WEBHOOK_NOT_FOUND404Webhook endpoint not found.Không
DELIVERY_NOT_FOUND404Delivery not found.Không
WEBHOOK_DISABLED409This webhook endpoint is disabled. Enable it first.Không

Motion — phân tích video nguồn (POST /motion/analyses; bốn mã cuối thường nằm ở error.code của lượt phân tích hỏng):

errorCodeHTTPCâu lỗiThử lại?
TEMPLATE_NOT_FOUND404Template not found, or your account has no access to it.Không
SOURCE_NOT_SUPPORTED400This template does not accept a source video.Không
URL_NOT_ALLOWED400sourceUrl must be a public http(s) URL on port 80 or 443.Không
ANALYSIS_NOT_FOUND404Analysis not found.Không
URL_FETCH_FAILED502Could not download the video from this URL.Có
ASSET_TOO_LARGE413The video is too large (max 300 MB).Không
SOURCE_INVALID422The source video could not be read. Use an mp4 / mov / webm file.Không
ANALYSIS_FAILED502Video analysis failed. Please try again later.Có