Invoking via CLI

Invoke an app action immediately via the CLI:

kernel invoke <app_name> <action_name>

Payload parameter

--payload allows you to invoke the action with specified parameters. This enables your action to receive and handle dynamic inputs at runtime. For example:

kernel invoke <app_name> <action_name> 
    --payload '{"tshirt_size": "small", "color": "black", "shipping_address": "2 Mint Plz, San Francisco CA 94103"}'

See developing to learn how to access the payload in your action method.

Return values

If your action specifies a return value, the invocation returns its value to the command line once it completes.

Return payloads have a max response limit size of 64kb. Use an S3 bucket for larger data processing.

Invoking via API/SDK

You can also run your app by making a POST request to Kernel’s API. For automations and agents that take longer than 100 seconds, use async invocations.

Synchronous invocations time out after 100 seconds.

const response = await fetch(`https://api.onkernel.com/invocations`, {
    method: 'POST',
    headers: {
        'Authorization': `Bearer ${process.env.KERNEL_API_KEY}`,
        'Content-Type': 'application/json'
    },
    body: {
        JSON.stringify({
            app_name: app_name,
            action_name: action_name,
            version: "latest",
            // Optional flags
            payload: {
                tshirt_size: "small",
                color: "black",
                shipping_address: "2 Mint Plz, San Francisco CA 94103"
            }
        })
    }
});
const { id, status, status_reason, output } = await response.json();

Or, invoke the function using Kernel’s SDK:

import { Kernel } from '@onkernel/sdk';

const {
    id,
    status,
    status_reason
    output
} = await Kernel.invocations.create({
    app_name: app_name,
    action_name: action_name,
    version: "latest"
});

Asynchronous invocations

For long running jobs, use asynchronous invocations to trigger Kernel actions without waiting for the result. You can then poll its status for the result.

const response = await fetch(`https://api.onkernel.com/invocations`, {
    method: 'POST',
    headers: {
        'Authorization': `Bearer ${process.env.KERNEL_API_KEY}`,
        'Content-Type': 'application/json'
    },
    body: {
        JSON.stringify({
            app_name: "app_name",
            action_name: "action_name",
            version: "latest",
            async: true, // Set this flag to specify asynchronous
        })
    }
});
const { id, status } = await response.json(); // status will be QUEUED

Or, invoke the function using Kernel’s SDK:

import { Kernel } from '@onkernel/sdk';

const {
    id,
    status, // status will be QUEUED
} = await Kernel.invocations.create({
    app_name: app_name,
    action_name: action_name,
    version: "latest",
    async: true,
});

See the CLI reference for full details.