Skip to main content
This page contains practical examples for the Asteroid Odyssey TypeScript and Python SDKs.
Execute an agent and wait for the result in the simplest way possible.
import { client, agentExecutePost, executionGet } from 'asteroid-odyssey';
import type { AgentsExecutionListItem } from 'asteroid-odyssey';

const TERMINAL_STATUSES = ['completed', 'failed', 'cancelled'];

async function basicExample() {
  // Configure client
  client.setConfig({
    headers: {
      'X-Asteroid-Agents-Api-Key': process.env.ASTEROID_API_KEY!,
    },
  });

  // Execute agent with variables
  const { data, error } = await agentExecutePost({
    path: { agentId: 'your-agent-id' },
    body: {
      inputs: {
        DATA: 'First name: John, Last name: Smith',
      },
      agentProfileId: 'your-agent-profile-id', // Optional
    },
  });

  if (error || !data) {
    console.error('Failed to start execution:', error);
    return;
  }

  const executionId = data.executionId;
  console.log(`Execution started: ${executionId}`);

  // Poll for result
  let execution: AgentsExecutionListItem | undefined;
  while (true) {
    const { data: result } = await executionGet({
      path: { executionId },
    });
    execution = result;
    console.log(`Status: ${execution?.status}`);

    if (TERMINAL_STATUSES.includes(execution?.status ?? '')) {
      break;
    }
    await new Promise(resolve => setTimeout(resolve, 2000));
  }

  console.log('Result:', execution);
}

basicExample().catch(console.error);
These examples cover the most common patterns you’ll need when working with the Asteroid Odyssey TypeScript and Python SDKs.