همه صفحه‌ها

Predictions، تصویر، ویدیو و صدا

مدل‌های تولید تصویر، ویدیو و صدا ناهمگام اجرا می‌شوند: با POST /v1/predictions کار را بسازید، با GET /v1/predictions/{id} تقریباً هر ۲ ثانیه یک‌بار وضعیت را بپرسید، و وقتی status برابر succeeded و آرایهٔ assets پر شد، فایل را از لینک assets دانلود کنید. خروجی‌ها روی سرورهای هرمز آینه می‌شوند تا از داخل ایران سریع و پایدار دانلود شوند.

POST/v1/predictionsاحراز هویت Bearer

Create a prediction

Start an async prediction job on an image/video model (image generation, video, audio, etc.). Returns immediately with a prediction ID that you poll until completion.

The async flow:

  1. POST /v1/predictions → Get prediction id (status: starting)
  2. GET /v1/predictions/{id} → Poll until succeeded AND assets populated
  3. GET /v1/assets/{asset_id} → Download the output file

پارامترها

فیلدinنوعتوضیح
Idempotency-Keyheaderstring

Optional deduplication token (any string up to 200 characters).

How it works:

  • Same key + same request body → cached response replayed (safe retry)
  • Same key + different body → 409 CONFLICT error
  • Keys expire after 24 hours

When to use: Add this header when you want to safely retry a request after a network timeout without risking a duplicate operation.

بدنه درخواستالزامی

فیلدنوعتوضیح
versionالزامیstring

Model identifier. Two formats:

  • Bare name (owner/name) uses the latest approved version (e.g., black-forest-labs/flux-pro)
  • Pinned (owner/name:hash) uses a specific model version

Must be an admin-approved model. Unapproved models return 400 MODEL_NOT_APPROVED.

نمونه: black-forest-labs/flux-pro

inputالزامیobject

Model-specific input parameters. Each model accepts different inputs: check GET /v1/models for the input_fields of each model.

Common fields for image models:

  • prompt (string): Text description of the desired image
  • width / height (integer): Output dimensions
  • num_outputs (integer): Number of images to generate
  • guidance_scale (number): How closely to follow the prompt
webhookstring (uri)

Optional webhook URL to receive prediction status updates. Hormouz normally handles webhooks internally for billing; only set this if you need a copy of the events.

webhook_events_filterarray of string

Filter which events trigger your webhook. Values: start, output, logs, completed.

نمونه

پاسخ‌ها

201

Prediction created. Poll GET /v1/predictions/{id} for status.

400

The request body or query parameters are invalid. Check the error.code and error.message fields for details. Codes the gateway emits at 400:

  • BAD_REQUEST: generic malformed JSON / missing required field.
  • INVALID_TOOLS: the tools array, plugins field, or model's :online suffix uses an unsupported shape. The response names the offender and links to the supported form. See the dedicated InvalidTools response below for the three triggers and migration hints.
  • UNSUPPORTED_TOOL: a built-in tool (file_search, code_interpreter, computer_use, mcp) whose pricing dimension is not yet wired into the gateway hold estimator.
  • INVALID_AUDIO_FORMAT: input_audio.format value is not in the supported set. The envelope lists every supported codec name. The gateway accepts both short names (wav, webm) and full MIME aliases (audio/wav, audio/webm); anything else fails fast at admission. See API guide §8b.
  • AUDIO_NOT_SUPPORTED_ON_RESPONSES: input_audio content part sent to POST /v1/responses. The Responses API has no audio content type today; resend to POST /v1/chat/completions instead.
401

Authentication failed. Either the Authorization header is missing, the key format is invalid, or the key doesn't match any active account.

{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Authentication required",
    "status": 401
  }
}
402

Insufficient credit balance.

409

Idempotency key conflict: you sent the same Idempotency-Key with a different request body.

429

Too many requests. Back off and retry after a short delay. Check the Retry-After header for guidance.

451

The submitted image was flagged by our content policy. Explicit or NSFW content is not permitted on image-only models. The prediction does not run. See the Content Policy section above for details on what is screened.

{
  "error": {
    "code": "CONTENT_POLICY_VIOLATION",
    "message": "The submitted image was flagged by our content policy. Explicit or NSFW content is not permitted.",
    "status": 451
  }
}
499

Your HTTP client cancelled the request before the gateway finished. No charge: the hold has been released. The most common cause is a 30 s default client timeout against a model whose p95 latency is 45-60 s; bump your client timeout to 120 s.

Retries with the same Idempotency-Key will replay this 499 forever (the prior outcome is "you cancelled"). For an actual re-attempt, mint a fresh Idempotency-Key. See docs/CUSTOMER_ERROR_HANDLING.md §3 for the full contract.

{
  "error": {
    "code": "CLIENT_CLOSED",
    "message": "Client disconnected before response",
    "status": 499
  }
}
500

Unexpected server error. Please retry with exponential backoff. If the issue persists, contact your admin.

502

The upstream AI provider is temporarily unavailable. Retry with exponential backoff (1s, 2s, 4s) using the same Idempotency-Key: if the upstream actually completed the work and only the response failed, the gateway replays the cached success without a second charge. Holds are released automatically on upstream failures.

503

The upstream AI provider is temporarily unavailable. Retry with exponential backoff (1s, 2s, 4s) using the same Idempotency-Key: if the upstream actually completed the work and only the response failed, the gateway replays the cached success without a second charge. Holds are released automatically on upstream failures.

504

The gateway's 120 s upstream deadline elapsed before the upstream provider produced a response. Retry with the same Idempotency-Key so a delayed-but-eventually-successful upstream call can be replayed instead of re-charged. Consider switching to a faster model or capping max_tokens if this recurs.

{
  "error": {
    "code": "UPSTREAM_TIMEOUT",
    "message": "Upstream did not respond before timeout",
    "status": 504
  }
}
POST/v1/models/{owner}/{name}/predictionsاحراز هویت Bearer

Create a prediction (path-based model)

Alternative to POST /v1/predictions where the model is specified in the URL path instead of the request body. Useful for integrations that prefer path-based routing.

Equivalent to calling POST /v1/predictions with "version": "{owner}/{name}".

پارامترها

فیلدinنوعتوضیح
ownerالزامیpathstring

Model owner (e.g., black-forest-labs).

nameالزامیpathstring

Model name (e.g., flux-pro).

Idempotency-Keyheaderstring

Optional deduplication token (any string up to 200 characters).

How it works:

  • Same key + same request body → cached response replayed (safe retry)
  • Same key + different body → 409 CONFLICT error
  • Keys expire after 24 hours

When to use: Add this header when you want to safely retry a request after a network timeout without risking a duplicate operation.

بدنه درخواستالزامی

فیلدنوعتوضیح
inputالزامیobject

Model-specific input parameters.

webhookstring (uri)

Optional webhook URL.

webhook_events_filterarray of string

Webhook event filter.

نمونه

پاسخ‌ها

201

Prediction created.

400

The request body or query parameters are invalid. Check the error.code and error.message fields for details. Codes the gateway emits at 400:

  • BAD_REQUEST: generic malformed JSON / missing required field.
  • INVALID_TOOLS: the tools array, plugins field, or model's :online suffix uses an unsupported shape. The response names the offender and links to the supported form. See the dedicated InvalidTools response below for the three triggers and migration hints.
  • UNSUPPORTED_TOOL: a built-in tool (file_search, code_interpreter, computer_use, mcp) whose pricing dimension is not yet wired into the gateway hold estimator.
  • INVALID_AUDIO_FORMAT: input_audio.format value is not in the supported set. The envelope lists every supported codec name. The gateway accepts both short names (wav, webm) and full MIME aliases (audio/wav, audio/webm); anything else fails fast at admission. See API guide §8b.
  • AUDIO_NOT_SUPPORTED_ON_RESPONSES: input_audio content part sent to POST /v1/responses. The Responses API has no audio content type today; resend to POST /v1/chat/completions instead.
401

Authentication failed. Either the Authorization header is missing, the key format is invalid, or the key doesn't match any active account.

{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Authentication required",
    "status": 401
  }
}
402

Insufficient credit balance.

409

Idempotency key conflict: you sent the same Idempotency-Key with a different request body.

429

Too many requests. Back off and retry after a short delay. Check the Retry-After header for guidance.

451

Image flagged by content policy. See Content Policy section.

499

Your HTTP client cancelled the request before the gateway finished. No charge: the hold has been released. The most common cause is a 30 s default client timeout against a model whose p95 latency is 45-60 s; bump your client timeout to 120 s.

Retries with the same Idempotency-Key will replay this 499 forever (the prior outcome is "you cancelled"). For an actual re-attempt, mint a fresh Idempotency-Key. See docs/CUSTOMER_ERROR_HANDLING.md §3 for the full contract.

{
  "error": {
    "code": "CLIENT_CLOSED",
    "message": "Client disconnected before response",
    "status": 499
  }
}
500

Unexpected server error. Please retry with exponential backoff. If the issue persists, contact your admin.

502

The upstream AI provider is temporarily unavailable. Retry with exponential backoff (1s, 2s, 4s) using the same Idempotency-Key: if the upstream actually completed the work and only the response failed, the gateway replays the cached success without a second charge. Holds are released automatically on upstream failures.

503

The upstream AI provider is temporarily unavailable. Retry with exponential backoff (1s, 2s, 4s) using the same Idempotency-Key: if the upstream actually completed the work and only the response failed, the gateway replays the cached success without a second charge. Holds are released automatically on upstream failures.

504

The gateway's 120 s upstream deadline elapsed before the upstream provider produced a response. Retry with the same Idempotency-Key so a delayed-but-eventually-successful upstream call can be replayed instead of re-charged. Consider switching to a faster model or capping max_tokens if this recurs.

{
  "error": {
    "code": "UPSTREAM_TIMEOUT",
    "message": "Upstream did not respond before timeout",
    "status": 504
  }
}
GET/v1/predictions/{id}احراز هویت Bearer

Get prediction status

Returns the current state of a prediction. Poll this endpoint until status is succeeded (or failed / canceled).

Important: After succeeded, wait for the assets array to be populated before downloading. The background mirror worker typically takes 5–30 seconds to copy outputs to local storage.

Recommended poll interval: Every 2 seconds. Don't poll faster than once per second.

پارامترها

فیلدinنوعتوضیح
idالزامیpathstring

Prediction ID from the create response.

نمونه

پاسخ‌ها

200

Current prediction state.

401

Authentication failed. Either the Authorization header is missing, the key format is invalid, or the key doesn't match any active account.

{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Authentication required",
    "status": 401
  }
}
404

Prediction not found. Either the ID is wrong or it belongs to a different account.

429

Too many requests. Back off and retry after a short delay. Check the Retry-After header for guidance.

503

The upstream AI provider is temporarily unavailable. Retry with exponential backoff (1s, 2s, 4s) using the same Idempotency-Key: if the upstream actually completed the work and only the response failed, the gateway replays the cached success without a second charge. Holds are released automatically on upstream failures.

POST/v1/predictions/{id}/cancelاحراز هویت Bearer

Cancel a prediction

Cancels a running or queued prediction. The prediction status changes to canceled and any held credits are released.

پارامترها

فیلدinنوعتوضیح
idالزامیpathstring

Prediction ID to cancel.

Idempotency-Keyheaderstring

Optional deduplication token (any string up to 200 characters).

How it works:

  • Same key + same request body → cached response replayed (safe retry)
  • Same key + different body → 409 CONFLICT error
  • Keys expire after 24 hours

When to use: Add this header when you want to safely retry a request after a network timeout without risking a duplicate operation.

نمونه

پاسخ‌ها

200

Cancellation accepted.

401

Authentication failed. Either the Authorization header is missing, the key format is invalid, or the key doesn't match any active account.

{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Authentication required",
    "status": 401
  }
}
404

The requested resource was not found. Either the ID is wrong or it belongs to a different account.

429

Too many requests. Back off and retry after a short delay. Check the Retry-After header for guidance.

503

The upstream AI provider is temporarily unavailable. Retry with exponential backoff (1s, 2s, 4s) using the same Idempotency-Key: if the upstream actually completed the work and only the response failed, the gateway replays the cached success without a second charge. Holds are released automatically on upstream failures.

GET/v1/predictions/{id}/streamاحراز هویت Bearer

Stream prediction events (SSE)

Opens a Server-Sent Events stream for real-time prediction updates. Events include output progress, logs, and completion status.

Event types:

  • output: Partial or final model output
  • logs: Model execution logs
  • done: Prediction complete

پارامترها

فیلدinنوعتوضیح
idالزامیpathstring

Prediction ID.

نمونه

پاسخ‌ها

200

Event stream.

401

Authentication failed. Either the Authorization header is missing, the key format is invalid, or the key doesn't match any active account.

{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Authentication required",
    "status": 401
  }
}
404

The requested resource was not found. Either the ID is wrong or it belongs to a different account.

429

Too many requests. Back off and retry after a short delay. Check the Retry-After header for guidance.

503

The upstream AI provider is temporarily unavailable. Retry with exponential backoff (1s, 2s, 4s) using the same Idempotency-Key: if the upstream actually completed the work and only the response failed, the gateway replays the cached success without a second charge. Holds are released automatically on upstream failures.

سوالات متداول

چرا باید منتظر پر شدن assets بمانم و نه فقط succeeded؟

آینه‌سازی خروجی چند ثانیه بعد از اتمام کار انجام می‌شود (معمولاً ۵ تا ۳۰ ثانیه). لینک‌های assets روی دامنهٔ هرمز هستند و ۷ روز معتبر می‌مانند؛ لینک منبع خیلی زود منقضی می‌شود.

هزینهٔ prediction چطور محاسبه می‌شود؟

هر مدل قیمت ثابتِ هر اجرا دارد که در کاتالوگ مدل‌ها نمایش داده می‌شود. مبلغ قبل از اجرا از اعتبار بلوکه و پس از پایان تسویه می‌شود؛ اگر کار لغو یا خطا شود، مبلغ آزاد می‌گردد.

به‌روزرسانی: 2026-10-13