API for executing Sogni platform tool calls (image, video, music generation).

Accessed via sogni.chat.tools. Provides methods to execute tool calls returned by the LLM, mapping them to sogni.projects.create() calls automatically.

// Execute a single tool call
const result = await sogni.chat.tools.execute(toolCall, {
tokenType: 'sogni',
onProgress: (p) => console.log(`${p.status}: ${p.percent}%`),
});

// Execute all tool calls from a completion
const results = await sogni.chat.tools.executeAll(result.tool_calls, {
onToolCall: async (tc) => myCustomHandler(tc), // for non-Sogni tools
});

Constructors

Methods

Constructors

Methods

  • Execute multiple tool calls from a single LLM response.

    Sogni tool calls (prefixed with sogni_) are executed automatically via projects.create(). Non-Sogni tool calls are delegated to the onToolCall callback if provided, or returned as errors.

    Parameters

    • toolCalls: ToolCall[]

      Array of tool calls from result.tool_calls

    • Optionaloptions: ToolExecutionOptions & {
          onToolCall?: (toolCall: ToolCall) => Promise<string>;
          onToolProgress?: (
              toolCall: ToolCall,
              progress: ToolExecutionProgress,
          ) => void;
      }

      Execution options plus optional handler for non-Sogni tools

      • OptionalonToolCall?: (toolCall: ToolCall) => Promise<string>

        Handler for non-Sogni tool calls. Must return the tool result content string.

      • OptionalonToolProgress?: (toolCall: ToolCall, progress: ToolExecutionProgress) => void

        Per-tool progress callback (wraps the per-tool onProgress with tool identity).

    Returns Promise<ToolExecutionResult[]>