Skip to content

OpenAIBatchApi

Namespace: Vercel.AI.OpenAI

public sealed class OpenAIBatchApi : BatchResultsApiBase, IBatchApi

OpenAI Batch API. Starts, reads, cancels, and lists Responses batches, and downloads their results.

Inheritance: object → BatchResultsApiBase

Implements: IBatchApi

View source

public override bool CanCancel { get; }

True when cancellation is implemented.

Value: bool

View source

public override bool CanList { get; }

True when listing is implemented.

Value: bool

View source

public override string Provider { get; }

Provider id.

Value: string

View source

DoCancelAsync(BatchOperationCall, CancellationToken)

Section titled “DoCancelAsync(BatchOperationCall, CancellationToken)”
public override Task<BatchCancelResult> DoCancelAsync(BatchOperationCall call, CancellationToken cancellationToken)

Cancels a batch.

Parameters

Name Type Description
call BatchOperationCall
cancellationToken CancellationToken

Returns: Task<BatchCancelResult>

View source

DoGetResultsAsync(BatchOperationCall, CancellationToken)

Section titled “DoGetResultsAsync(BatchOperationCall, CancellationToken)”
public override Task<IAsyncEnumerable<BatchItem>> DoGetResultsAsync(BatchOperationCall call, CancellationToken cancellationToken)

Opens the result stream. Errors found while opening, such as a batch that is not complete, throw from the task. Errors found while reading, such as a malformed row, throw from the stream.

Parameters

Name Type Description
call BatchOperationCall
cancellationToken CancellationToken

Returns: Task<IAsyncEnumerable<BatchItem>>

View source

DoGetStatusAsync(BatchOperationCall, CancellationToken)

Section titled “DoGetStatusAsync(BatchOperationCall, CancellationToken)”
public override Task<BatchStatus> DoGetStatusAsync(BatchOperationCall call, CancellationToken cancellationToken)

Reads status.

Parameters

Name Type Description
call BatchOperationCall
cancellationToken CancellationToken

Returns: Task<BatchStatus>

View source

DoListAsync(BatchOperationCall, CancellationToken)

Section titled “DoListAsync(BatchOperationCall, CancellationToken)”
public override Task<BatchListResult> DoListAsync(BatchOperationCall call, CancellationToken cancellationToken)

Lists batches. The implementation is invoked on this instance.

Parameters

Name Type Description
call BatchOperationCall
cancellationToken CancellationToken

Returns: Task<BatchListResult>

View source

DoStartAsync(BatchOperationCall, CancellationToken)

Section titled “DoStartAsync(BatchOperationCall, CancellationToken)”
public override Task<BatchStartResult> DoStartAsync(BatchOperationCall call, CancellationToken cancellationToken)

Uploads the requests as a JSONL input file, then creates a /v1/responses batch with a 24-hour completion window. Every request must be a text request for the same model. providerOptions.openai.inputFileExpiresAfter sets the input file TTL in seconds (3600 to 2592000, default 48 hours).

Parameters

Name Type Description
call BatchOperationCall
cancellationToken CancellationToken

Returns: Task<BatchStartResult>

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product