Skip to main content

experimental_getBatchResults

还没翻译译自英文(ai-sdk.dev)本页 10 段都还没译

Warning

Batch support is experimental and the API may change in patch releases.

Returns an async iterable of terminal results for the requests in an asynchronous batch. For a complete guide to the batch lifecycle, see Batch.

import { anthropic } from '@ai-sdk/anthropic';
import { experimental_getBatchResults as getBatchResults } from 'ai';

for await (const item of getBatchResults({ provider: anthropic, batch })) {
  if (item.status === 'succeeded') {
    console.log(item.id, item.text);
  } else {
    console.error(item.id, item.error);
  }
}

Import

import { experimental_getBatchResults } from "ai"

API Signature

Parameters

  • provider? (Experimental_BatchProvider): The provider used to access the batch. Defaults to the global provider, or the AI Gateway when no global provider is configured.
  • batch (Experimental_BatchReference): The serializable reference returned by experimental_startBatch.
  • tools? (ToolSet): The client-defined tools provided on requests in the batch. Used to validate and normalize returned tool calls; execute functions are never invoked.
  • providerOptions? (ProviderOptions): Additional provider-specific options for result retrieval.
  • maxRetries? (number): Maximum number of retries for result retrieval. Set to 0 to disable retries. Default: 2.
  • abortSignal? (AbortSignal): An optional abort signal to cancel result retrieval.
  • timeout? (number | { totalMs?: number }): Maximum time allowed for result retrieval.
  • headers? (Record<string, string | undefined>): Additional HTTP headers for the request.

Returns

An AsyncIterableStream<Experimental_BatchItemResult> of succeeded, failed, cancelled, or expired request results. You can consume the stream as either an async iterable or a ReadableStream.

Successful items contain id, status: 'succeeded', text, normalized content (including text, reasoning, sources, files, tool calls, and tool results), finishReason, usage, and optional response and provider metadata. text is the concatenation of text parts and can be an empty string when a result contains no text parts. Failed, cancelled, and expired items contain the request id, their terminal status, and optional error details.