Tela SDK for JavaScript
    Preparing search index...

    Class BatchExecutionResult<TOutput>

    Wraps the completed batch execution response with convenient result access methods.

    Provides multiple ways to access batch results:

    • Download entire output file: downloadOutputFile()
    • Stream results incrementally: iterateResults()
    • Get all results as array: getResults()
    • Fetch individual result by reference ID: getResult(referenceId)
    const execution = await batch.execute()
    const result = await execution.result

    // Access batch metadata
    console.log(`Status: ${result.status}`)
    console.log(`Progress: ${result.state.completed}/${result.state.total}`)

    // Iterate through results
    for await (const item of result.iterateResults()) {
    console.log(item)
    }

    Type Parameters

    • TOutput

      The output type for individual results.

    Index

    Constructors

    Accessors

    • get canceledAt(): Date | null

      Gets the timestamp when this batch was canceled.

      Returns Date | null

      Cancellation date, or null if not canceled.

    • get completedAt(): Date | null

      Gets the timestamp when this batch completed successfully.

      Returns Date | null

      Completion date, or null if not completed.

    • get createdAt(): Date

      Gets the timestamp when this batch was created.

      Returns Date

      Creation date.

    • get failedAt(): Date | null

      Gets the timestamp when this batch failed.

      Returns Date | null

      Failure date, or null if not failed.

    • get id(): string

      Gets the unique identifier for this batch execution.

      Returns string

      The batch execution ID.

    • get outputFile(): string | null

      Gets the vault URL of the output JSONL file containing all results.

      Returns string | null

      The output file URL, or null if batch is not completed.

    • get rawResponse(): WithRequestId<BatchResponse>

      Gets the raw API response without any processing.

      Returns WithRequestId<BatchResponse>

      The complete batch response object.

    • get requestId(): string | undefined

      Returns string | undefined

    • get state(): { completed: number; failed: number; total: number } | null

      Gets the progress statistics for this batch.

      Returns { completed: number; failed: number; total: number } | null

      Object containing completed, failed, and total execution counts, or null if not available.

      • { completed: number; failed: number; total: number }
        • completed: number

          Number of completed executions.

        • failed: number

          Number of failed executions.

        • total: number

          Total number of executions in the batch.

      • null
    • get status(): BatchExecutionStatus

      Gets the current status of the batch execution.

      Returns BatchExecutionStatus

      The batch status.

    • get updatedAt(): Date

      Gets the timestamp when this batch was last updated.

      Returns Date

      Last update date.

    Methods

    • Downloads the complete output file as a Blob.

      The output file is a JSONL (JSON Lines) file where each line contains one execution result with its reference ID, status, and output.

      Returns Promise<Blob>

      A promise resolving to the output file as a Blob.

      If batch is not completed or output file is unavailable.

      const file = await result.downloadOutputFile()
      const text = await file.text()
      console.log(text) // JSONL content
    • Fetches the raw result metadata for a specific execution by its reference ID.

      Queries the API for the execution result using the reference ID tag. Returns the complete execution metadata including input, output, and usage statistics.

      Parameters

      • referenceId: string

        The reference ID of the execution to retrieve.

      Returns Promise<CompletionRunResult<TOutput>>

      A promise resolving to the raw execution result object.

      If no result found with the given reference ID.

      const rawResult = await result.getRawResult('my-ref-id')
      console.log('Credits used:', rawResult.creditsUsed)
      console.log('Execution status:', rawResult.status)
    • Fetches the output content for a specific execution by its reference ID.

      Convenience method that retrieves the raw result and extracts just the output content.

      Parameters

      • referenceId: string

        The reference ID of the execution to retrieve.

      Returns Promise<TOutput>

      A promise resolving to the execution output content.

      If no result found with the given reference ID.

      const output = await result.getResult('my-ref-id')
      console.log('Output:', output)
    • Downloads and parses all results into an array.

      Loads the entire output file into memory, parses each line, and extracts the output content. For large batches, consider using iterateResults() instead.

      Returns Promise<TOutput[]>

      A promise resolving to an array of all execution outputs.

      If batch is not completed, output file is unavailable, or parsing fails.

      const results = await result.getResults()
      console.log(`Got ${results.length} results`)
      results.forEach((output, i) => console.log(`Result ${i}:`, output))
    • Asynchronously iterates over raw result items from the output file.

      Streams and parses the output file line-by-line, yielding raw JSON objects. Each yielded object contains the full result structure including metadata.

      Parameters

      • params: { abortController?: AbortController } = {}

        Iteration options.

        • OptionalabortController?: AbortController

          Optional AbortController to cancel iteration.

      Returns AsyncGenerator<unknown, void, unknown>

      If batch is not completed or output file is unavailable.

      Raw result objects from the JSONL file.

      for await (const rawResult of result.iterateRawResults()) {
      console.log('Reference ID:', rawResult.reference_id)
      console.log('Status:', rawResult.status)
      console.log('Output:', rawResult.result.outputContent.content)
      }
    • Asynchronously iterates over parsed output content from the batch results.

      Streams and parses the output file line-by-line, yielding only the output content (not the full result metadata). Memory-efficient for large batches.

      Parameters

      • params: { abortController?: AbortController } = {}

        Iteration options.

        • OptionalabortController?: AbortController

          Optional AbortController to cancel iteration.

      Returns AsyncGenerator<Awaited<TOutput>, void, unknown>

      If batch is not completed, output file is unavailable, or parsing fails.

      Parsed output content from each execution.

      const controller = new AbortController()

      for await (const output of result.iterateResults({ abortController: controller })) {
      console.log(output)
      if (someCondition) {
      controller.abort() // Stop iteration early
      }
      }
    • Streams the output file as a ReadableStream for memory-efficient processing.

      Useful for large batches where loading the entire file into memory is not practical.

      Returns Promise<ReadableStream<any>>

      A promise resolving to a ReadableStream of the output file.

      If batch is not completed or output file is unavailable.

      const stream = await result.streamOutputFile()
      // Process stream with custom logic