TypeScript SDKReference

Prediction Types

TypeScript types for creating, running, polling, and managing predictions.

See Predictions for usage.

PredictionRequest

SDK request payload for creating predictions. Maps directly to POST /v1/predictions request body.

interface PredictionRequest {
  model: string;
  input: Record<string, any>;
  await?: boolean;
  stream?: boolean;
  webhook?: Webhook | {
    url: string;
    events: ReadonlyArray<string>;
  };
}
ParameterTypeDefaultDescription
modelstringModel slug — see Models.
inputRecord<string, any>Model input parameters (required).
awaitbooleanfalseWhen true, the API holds the connection until the prediction completes. See Server-Side Wait. Do not use for video models.
streambooleanfalseEnable streaming output.
webhookWebhook | { url, events }Webhook config — see Webhooks.

RunOptions

SDK-specific type for client.run(). Extends PredictionRequest with client-side polling controls (interval, maxWait, signal).

interface RunOptions {
  input: Record<string, any>;
  webhook?: Webhook | { url: string; events: ReadonlyArray<string> };
  stream?: boolean;
  interval?: number;
  maxWait?: number;
  signal?: AbortSignal;
}
ParameterTypeDefaultDescription
inputRecord<string, any>Model input (required).
webhookWebhook | { url, events }Webhook config.
streambooleanfalseEnable streaming.
intervalnumber5000Polling interval (ms) when used with onProgress.
maxWaitnumberMax wait time (ms). Throws WAIT_TIMEOUT.
signalAbortSignalAbort polling. Throws ABORTED.

WaitOptions

SDK-specific type for client-side polling via client.wait(). Not sent to the API.

interface WaitOptions {
  interval?: number;
  maxWait?: number;
  signal?: AbortSignal;
}
ParameterTypeDefaultDescription
intervalnumber5000Poll interval in ms.
maxWaitnumberMax wait time (ms).
signalAbortSignalAbort signal.

PredictionSdkOptions

SDK-specific options for predictions. Not sent to the API — used for client-side validation and behavior control.

interface PredictionSdkOptions {
  compatibilityCheck?: boolean;
  autoAwait?: boolean;
}
ParameterTypeDescription
compatibilityCheckbooleanValidate model slug against the models cache before submitting.
autoAwaitboolean(New in v1.0.5) When true and compatibilityCheck: true, automatically sets await: true for image models (causing server-side blocking). Video/audio models ignore this. Explicit payload.await always takes priority. See autoAwait.

PredictionResponse

SDK representation of the v1 Prediction object returned from the Predictions API. This TypeScript interface matches the API JSON response exactly — returned by POST /v1/predictions, GET /v1/predictions/:id, and GET /v1/predictions. The SDK performs no transformations; it's a direct mapping of the REST API response.

interface PredictionResponse {
  id: string;
  status: PredictionStatus;
  type: PredictionType;
  stream: boolean;
  input: Record<string, any>;
  output?: string | string[];
  response?: string;
  created_at: string;
  started_at: string;
  completed_at: string;
  updated_at: string;
  privacy: string;
  source?: PredictionSource;
  model?: {
    name: string;
    type: string;
  };
  webhook?: {
    url: string | null;
    events: string[];
  };
  metrics?: {
    image_count?: number;
    predict_time?: number;
    total_time?: number;
    asset_count?: number;
    progress?: number;
  };
  metadata?: {
    billing?: { credits_used: number };
    storage?: {
      files: {
        name: string;
        type: string;
        size: number;
        url: string;
      }[];
    };
    data_available?: boolean;
  };
  urls?: {
    get?: string;
    cancel?: string;
    stream?: string;
    delete?: string;
  };
}

Returned by client.predict() and predictions.create().

FieldTypeDescription
idstringUnique prediction ID.
statusPredictionStatusCurrent status.
typePredictionType'inference' or 'training'.
streambooleanWhether streaming was requested.
inputRecord<string, any>Input that was submitted.
responsestringRaw response text (if applicable).
outputstring | string[]Output URL(s) or text.
created_atstringISO 8601 creation timestamp.
started_atstringISO 8601 start timestamp.
completed_atstringISO 8601 completion timestamp.
updated_atstringISO 8601 last update.
privacystringPrediction privacy level.
sourcePredictionSource'api' · 'cli' · 'web'.
model{ name, type }Model info.
webhook{ url, events }Webhook that was attached.
metricsobjectimage_count, predict_time, total_time, asset_count, progress.
metadataobjectbilling.credits_used, storage.files[], data_available.
urlsobjectget, cancel, stream, delete endpoint URLs.

PredictionsListOptions

Query parameters for GET /v1/predictions.

interface PredictionsListOptions {
  page?: number;
  since?: string;
  until?: string;
  model?: string;
}

Passed to predictions.list().

ParameterTypeDescription
pagenumberPage number.
sincestringStart date filter (ISO 8601 / YYYY-MM-DD).
untilstringEnd date filter (ISO 8601 / YYYY-MM-DD).
modelstringFilter by model slug.

PaginatedResponse<T>

interface PaginatedResponse<T> {
  data: T[];
  pagination: Pagination;
}
FieldTypeDescription
dataT[]Page of results.
paginationPaginationPagination metadata.

Pagination

interface Pagination {
  current_page: number;
  per_page: number;
  total: number;
  last_page: number;
}
FieldTypeDescription
current_pagenumberCurrent page number.
per_pagenumberItems per page.
totalnumberTotal item count.
last_pagenumberLast page number.

Prediction Class

SDK-specific wrapper class around PredictionResponse. Provides convenience methods for common operations. Returned exclusively by client.run().

class Prediction {
  readonly id: string;
  readonly status: PredictionStatus;
  readonly output: string | string[] | undefined;
  readonly response: PredictionResponse;
  
  outputs(): string | string[] | undefined;
  raw(): PredictionResponse;
  cancel(): Promise<PredictionResponse>;
  delete(): Promise<PredictionResponse>;
  stream(): Promise<PredictionResponse>;
}
MemberTypeDescription
.idstringPrediction ID.
.statusPredictionStatusCurrent status.
.outputstring | string[]Raw output.
.responsePredictionResponseFull API response.
.outputs()string | string[]Normalized output — unwraps single-element arrays.
.raw()PredictionResponseFull response as plain object.
.cancel()Promise<PredictionResponse>Cancel the prediction.
.delete()Promise<PredictionResponse>Delete the prediction and its assets.
.stream()Promise<PredictionResponse>Get the streaming endpoint.

Prediction Enums

TypeScript enums mirroring the v1 Prediction object string literal types.

enum PredictionStatus {
  PENDING    = 'pending',
  PROCESSING = 'processing',
  SUCCEEDED  = 'succeeded',
  FAILED     = 'failed',
  CANCELLED  = 'cancelled',
  STARTING   = 'starting',
  STARTED    = 'started',
}

enum PredictionType {
  INFERENCE = 'inference',
  TRAINING  = 'training',
}

enum PredictionSource {
  API = 'api',
  CLI = 'cli',
  WEB = 'web',
}

OnProgressCallback

SDK-specific type for polling progress callbacks in client.run().

type OnProgressCallback = (prediction: PredictionResponse) => void

QueueItem

interface QueueItem {
  request: PredictionRequest;
  sdk?: PredictionSdkOptions;
}
FieldTypeDescription
requestPredictionRequestThe queued request.
sdkPredictionSdkOptionsSDK options for the request.

How is this guide?

On this page