Inference Logoinference.sh

Sync & Async

JavaScript patterns for task execution.


Wait for Result (Default)

typescript
1const result = await client.run({2  app: 'infsh/flux',3  input: { prompt: 'A sunset' }4});56console.log(result.output);

Fire and Forget

Return immediately without waiting:

typescript
1const task = await client.run(2  { app: 'infsh/flux', input: { prompt: 'hello' } },3  { wait: false }4);56console.log('Task submitted:', task.id);7// Check status later

Run Options

typescript
1interface RunOptions {2  wait?: boolean;                    // Wait for completion (default: true)3  onUpdate?: (update: Task) => void; // Status callback4  onPartialUpdate?: (update: Task, fields: string[]) => void;5  autoReconnect?: boolean;           // Auto-reconnect (default: true)6  maxReconnects?: number;            // Max attempts (default: 5)7  reconnectDelayMs?: number;         // Delay in ms (default: 1000)8}

Cancel Task

typescript
1const task = await client.run(params, { wait: false });23// Cancel if needed4await client.cancel(task.id);

Error Handling

typescript
1try {2  const result = await client.run(params);3} catch (error) {4  if (error instanceof Error) {5    console.error('Task failed:', error.message);6  }7}

Common errors:

  • Error: task failed — Execution error
  • Error: task cancelled — Cancelled
  • Error: Request failed — API error

Concurrent Tasks

typescript
1const results = await Promise.all([2  client.run({ app: 'app', input: { n: 1 } }),3  client.run({ app: 'app', input: { n: 2 } }),4  client.run({ app: 'app', input: { n: 3 } }),5]);

Batch Processing

typescript
1async function processImages(images: string[]) {2  return Promise.all(3    images.map(image =>4      client.run({5        app: 'image-processor',6        input: { image }7      })8    )9  );10}

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.