import { C as ClientOptions, H as HttpMethod, R as RequestOptions, Q as QueryParams, P as PollingOptions } from './types-ClO2hfPY.js'; export { A as AsyncTaskStatus, T as TaskBillingFacts, a as TaskBillingResponse, b as TaskRefund, c as TaskReservation, d as TaskResponse, e as TaskSettlement, f as TaskStatus } from './types-ClO2hfPY.js'; /** * Default timeout constants for SDK operations. * All values are in milliseconds. */ declare const TIMEOUTS: { /** * Default HTTP request timeout (15 minutes). * AI generation APIs can take significant time to complete. */ readonly HTTP_REQUEST: 900000; /** * Default polling timeout (15 minutes). * Matches HTTP_REQUEST to allow long-running tasks to complete. */ readonly POLLING_MAX_WAIT: 900000; /** * Default polling interval (2 seconds). * How often to check task status during polling. */ readonly POLLING_INTERVAL: 2000; }; /** * Default retry configuration for HTTP requests. */ declare const RETRY_CONFIG: { /** * Maximum number of retry attempts. */ readonly MAX_RETRIES: 2; /** * Base delay between retries (500ms). * Actual delay uses exponential backoff. */ readonly BASE_DELAY: 500; /** * Maximum delay between retries (5 seconds). * Caps the exponential backoff. */ readonly MAX_DELAY: 5000; }; /** * Default base URL for RunAPI services. */ declare const DEFAULT_BASE_URL = "https://runapi.ai"; /** * SDK user agent string. */ declare const SDK_USER_AGENT = "runapi-sdk-js"; /** Options for constructing RunApiError instances. */ interface RunApiErrorOptions extends ErrorOptions { /** Explicit machine-readable reason. */ code?: string; /** HTTP status code. */ status?: number; /** Request ID from `X-Request-ID` header. */ requestId?: string; /** Additional error details from response body. */ details?: unknown; } /** * Base error class for all RunAPI SDK errors. * Includes HTTP status, request ID, and response details. */ declare class RunApiError extends Error { /** Explicit machine-readable reason when one was provided. */ code?: string; /** HTTP status code if available. */ status?: number; /** Request ID from response headers. */ requestId?: string; /** Parsed response body or error details. */ details?: unknown; constructor(message: string, options?: RunApiErrorOptions); } /** Thrown when API key is missing or invalid (HTTP 401). */ declare class AuthenticationError extends RunApiError { constructor(message: string, options?: RunApiErrorOptions); } /** Thrown when rate limit is exceeded (HTTP 429). Includes retry-after delay. */ declare class RateLimitError extends RunApiError { /** Suggested retry delay in milliseconds from `Retry-After` header. */ retryAfterMs?: number; constructor(message: string, options?: RunApiErrorOptions & { retryAfterMs?: number; }); } /** Thrown when account has insufficient credits (HTTP 402). */ declare class InsufficientCreditsError extends RunApiError { constructor(message: string, options?: RunApiErrorOptions); } /** Thrown when requested resource does not exist (HTTP 404). */ declare class NotFoundError extends RunApiError { constructor(message: string, options?: RunApiErrorOptions); } /** Thrown when request validation fails (HTTP 400, 422). */ declare class ValidationError extends RunApiError { constructor(message: string, options?: RunApiErrorOptions); } /** Thrown when service is temporarily unavailable (HTTP 503). */ declare class ServiceUnavailableError extends RunApiError { constructor(message: string, options?: RunApiErrorOptions); } /** Thrown when network connection fails or request cannot be sent. */ declare class NetworkError extends RunApiError { constructor(message: string, options?: RunApiErrorOptions); } /** Thrown when HTTP request exceeds configured timeout. */ declare class TimeoutError extends RunApiError { constructor(message: string, options?: RunApiErrorOptions); } /** Thrown when polling for task completion exceeds maximum wait time. */ declare class TaskTimeoutError extends RunApiError { constructor(message: string, options?: RunApiErrorOptions); } /** Thrown when async task fails during processing. */ declare class TaskFailedError extends RunApiError { constructor(message: string, options?: RunApiErrorOptions); } /** * Constructs appropriate error class from HTTP response. * Maps status codes to specific error types and extracts error messages. * * @param response - HTTP Response object * @param bodyText - Response body as text * @param bodyJson - Parsed JSON body if available * @returns Specific error instance based on status code */ declare function errorFromResponse(response: Response, bodyText: string | null, bodyJson?: unknown): RunApiError; /** * Resolve the API key from explicit options or the `RUNAPI_API_KEY` environment * variable. Throws `AuthenticationError` when neither is provided. */ declare function resolveApiKey(options: ClientOptions): string; /** Resolve an API key when present without requiring one for public resources. */ declare function resolveOptionalApiKey(options: ClientOptions): string | undefined; interface HttpRequestOptions extends RequestOptions { query?: QueryParams; body?: unknown; /** Return a successful response body without text decoding. */ responseType?: 'json' | 'bytes'; /** Treat HTTP 304 as a successful conditional request result. */ allowNotModified?: boolean; /** Internal response-header capture for resources that support HTTP revalidation. */ captureResponseHeaders?: Record; /** Internal HTTP status capture for resources with response lifecycle branches. */ captureResponseStatus?: { status?: number; }; } interface HttpClient { request(method: HttpMethod, path: string, options?: HttpRequestOptions): Promise; /** * PUT bytes straight to an absolute upload URL with the exact headers issued * for it. Skips the base URL, auth, and retries — the URL is single-use and * pre-authorized, and the body is not safe to replay. */ upload(url: string, options: { headers: Record; body: BodyInit; timeoutMs?: number; signal?: AbortSignal; }): Promise; } declare function createHttpClient(options: ClientOptions): HttpClient; interface HybridTaskUpdate { id?: string; status: 'processing' | 'completed' | 'failed'; } type HybridTaskListener = (task: HybridTaskUpdate) => void; type HybridTaskOptions = RequestOptions & PollingOptions; declare class HybridTask { private readonly http; private readonly location; private readonly terminal; private readonly options; private completion?; private readonly listeners; constructor(http: HttpClient, location: string | undefined, terminal: T | undefined, options: HybridTaskOptions); run(): Promise; subscribe(listener: HybridTaskListener): Promise; private wait; private completeTerminal; private poll; private notify; } declare function createHybridTask(http: HttpClient, path: string, options: HttpRequestOptions & HybridTaskOptions): Promise>; interface RetryOptions { maxRetries: number; baseDelayMs: number; maxDelayMs: number; } declare function getRetryDelayMs(attempt: number, baseDelayMs: number, maxDelayMs: number): number; declare function isRetryableStatus(status: number): boolean; declare function isIdempotentMethod(method: string): boolean; declare function parseRetryAfterMs(response: Response): number | undefined; declare function compactParams(params: T): Partial; /** One action entry from a package's generated contract. */ interface ActionSchema { models?: readonly string[]; rules?: readonly Record[]; fields_by_model?: Record>; } type Params = Record; /** * Validates request params against a generated action schema: model * membership, then declared cross-field rules, then per-field * required/enum/integer/min/max/length. A missing schema is a no-op. */ declare function validateParams(schema: ActionSchema | undefined, params: Params): void; interface FileUploadResponse { file_name: string; url: string; size_bytes: number; mime_type: string; created_at: string; expires_at: string; } interface FileObject { id: string; object: 'file'; bytes: number; created_at: number; expires_at?: number; filename: string; purpose: 'user_data'; } interface FileList { object: 'list'; data: FileObject[]; first_id?: string; last_id?: string; has_more: boolean; } interface DeletedFile { id: string; object: 'file'; deleted: true; } interface FileListParams { after?: string; limit?: number; order?: 'asc' | 'desc'; purpose?: 'user_data'; } interface ProtocolFileCreateParams { file: Blob; filename?: string; purpose?: 'user_data'; } type FileSource = { type: 'url'; url: string; } | { type: 'base64'; data: string; }; type FileCreateParams = { file: Blob; file_name?: string; source?: never; } | { source: FileSource; file_name?: string; file?: never; }; declare class Files { private readonly http; constructor(http: HttpClient); create(params: FileCreateParams, options?: RequestOptions): Promise; /** Uploads a persistent File through the OpenAI-compatible Files API. */ createFile(params: ProtocolFileCreateParams, options?: RequestOptions): Promise; list(params?: FileListParams, options?: RequestOptions): Promise; retrieve(fileId: string, options?: RequestOptions): Promise; content(fileId: string, options?: RequestOptions): Promise; deleteFile(fileId: string, options?: RequestOptions): Promise; private uploadDirect; private filePath; } interface UploadObject { id: string; object: 'upload'; bytes: number; created_at: number; filename: string; purpose: 'user_data'; status: 'pending' | 'completed' | 'cancelled' | 'expired'; expires_at: number; file?: FileObject; } interface UploadPart { id: string; object: 'upload.part'; created_at: number; upload_id: string; } interface UploadCreateParams { bytes: number; filename: string; mime_type: string; purpose?: 'user_data'; } declare class Uploads { private readonly http; constructor(http: HttpClient); create(params: UploadCreateParams, options?: RequestOptions): Promise; addPart(uploadId: string, data: Blob, filename?: string, options?: RequestOptions): Promise; complete(uploadId: string, partIds: string[], options?: RequestOptions): Promise; cancel(uploadId: string, options?: RequestOptions): Promise; private uploadPath; } interface AccountInfoResponse { id: number; name: string; email: string; account: { id: number; name: string; }; } interface AccountBalanceResponse { balance_cents: number; paid_balance_cents: number; bonus_balance_cents: number; spent_cents_today: number; spent_cents_total: number; } declare class Account { private readonly http; constructor(http: HttpClient); info(options?: RequestOptions): Promise; balance(options?: RequestOptions): Promise; } interface PriceScheduleFilters extends QueryParams { service?: string; action?: string; model?: string; } interface PriceSchedule { service: string; action: string; model: string | null; pricing_status: 'available' | 'pending' | string; catalog_status: 'active' | 'maintenance' | 'disabled' | string; currency: string; billing_unit: string; billing_strategy: string; unit_price_cents?: number | null; input_price_per_1m_cents: number | null; output_price_per_1m_cents: number | null; cache_read_price_per_1m_cents: number | null; cache_write_price_per_1m_cents: number | null; cache_write_5m_price_per_1m_cents: number | null; cache_write_1h_price_per_1m_cents: number | null; billing_config: Record; } interface PriceScheduleListResponse { as_of: string; price_schedules: PriceSchedule[]; /** HTTP ETag for revalidating this schedule on a later request. */ etag?: string; } interface PriceScheduleNotModifiedResponse { not_modified: true; etag?: string; } type PriceScheduleListResult = PriceScheduleListResponse | PriceScheduleNotModifiedResponse; interface PriceQuoteParams { service: string; action: string; model?: string | null; params?: Record; } interface PriceQuoteResponse { service: string; action: string; model: string | null; pricing_status: 'available' | string; currency: string; reservation_amount_cents: number; estimate_basis: string; as_of: string; } /** Live Price Schedule lookup and request-specific Price Quote operations. */ declare class Pricing { private readonly http; constructor(http: HttpClient); list(filters?: PriceScheduleFilters, options?: RequestOptions): Promise; quote(params: PriceQuoteParams, options?: RequestOptions): Promise; } /** Standalone live Pricing client with optional API authentication. */ declare class PricingClient extends Pricing { constructor(options?: ClientOptions); } /** * Base class for RunAPI Provider Clients. Resolves the API key, builds the * shared HTTP client, and exposes the Universal Resources (Files, Uploads, * account, pricing) that are available on any client regardless of which model * package was imported. * * Provider clients extend this and build their model resources from `this.http`. */ declare class BaseClient { /** Persistent File lifecycle and temporary URL upload operations. */ readonly files: Files; /** Account info and balance operations. */ readonly account: Account; /** Live Price Schedule lookup and Price Quote operations. */ readonly pricing: Pricing; /** Multipart Upload lifecycle operations. */ readonly uploads: Uploads; protected readonly http: HttpClient; private readonly apiKey; constructor(options?: ClientOptions); getApiKey(): string; } declare const version = "0.1.0"; export { Account, type AccountBalanceResponse, type AccountInfoResponse, type ActionSchema, AuthenticationError, BaseClient, ClientOptions, DEFAULT_BASE_URL, type DeletedFile, type FileCreateParams, type FileList, type FileListParams, type FileObject, type FileSource, type FileUploadResponse, Files, type HttpClient, HttpMethod, type HttpRequestOptions, HybridTask, type HybridTaskListener, type HybridTaskOptions, type HybridTaskUpdate, InsufficientCreditsError, NetworkError, NotFoundError, PollingOptions, type PriceQuoteParams, type PriceQuoteResponse, type PriceSchedule, type PriceScheduleFilters, type PriceScheduleListResponse, type PriceScheduleListResult, type PriceScheduleNotModifiedResponse, Pricing, PricingClient, type ProtocolFileCreateParams, QueryParams, RETRY_CONFIG, RateLimitError, RequestOptions, type RetryOptions, RunApiError, type RunApiErrorOptions, SDK_USER_AGENT, ServiceUnavailableError, TIMEOUTS, TaskFailedError, TaskTimeoutError, TimeoutError, type UploadCreateParams, type UploadObject, type UploadPart, Uploads, ValidationError, compactParams, createHttpClient, createHybridTask, errorFromResponse, getRetryDelayMs, isIdempotentMethod, isRetryableStatus, parseRetryAfterMs, resolveApiKey, resolveOptionalApiKey, validateParams, version };