Skip to main content
Once you’ve deployed an app and invoked it, you can monitor its status using streaming for real-time updates or polling for periodic checks.
An invocation ends once its code execution finishes.

Streaming Status Updates

For real-time status monitoring, use follow to stream invocation events. This provides immediate updates as your invocation progresses and is more efficient than polling.
import Kernel from '@onkernel/sdk';

const client = new Kernel({
  apiKey: 'My API Key',
});

const response = await client.invocations.follow('id');

console.log(response);

Example

Here’s an example showing how to handle streaming status updates:
const result = await client.invocations.retrieve(invocation.id);

const follow = await client.invocations.follow(result.id);
for await (const evt of follow) {
  if (evt.event === 'invocation_state') {
    console.log(`Status: ${evt.invocation.status}`);

    if (evt.invocation.status === 'succeeded') {
      console.log('✅ Invocation completed successfully!');
      if (evt.invocation.output) {
        console.log('Result:', JSON.parse(evt.invocation.output));
      }
    } else if (evt.invocation.status === 'failed') {
      console.log('❌ Invocation failed');
      if (evt.invocation.status_reason) {
        console.log('Error:', evt.invocation.status_reason);
      }
    }
  } else if (evt.event === 'error') {
    console.error('🚨 Error:', evt.error.message);
  }
}

console.log('✅ Invocation successful!');
console.log('Invocation result:', JSON.stringify(result, null, 2));

Polling Status Updates

Alternatively, you can poll the status endpoint using retrieve to check the invocation status periodically.
import Kernel from '@onkernel/sdk';

const client = new Kernel({
  apiKey: 'My API Key',
});

const invocation = await client.invocations.retrieve('rr33xuugxj9h0bkf1rdt2bet');

console.log(invocation.id);
I