Skip to content

StreamObjectResult<T>

Namespace: Vercel.AI.GenerateObject

public sealed class StreamObjectResult<T>

The result of a streamObject call. Maps to StreamObjectResult.

Type parameters

Name Description
T The result: the object, the array, or the enum value (a string).

Inheritance: object

View source

public Task<FinishReason> FinishReason { get; }

The reason why the generation finished. Resolved when the response is finished.

Value: Task<FinishReason>

View source

public Task<T> Object { get; }

The generated object. Resolved when the response is finished.

Value: Task<T>

View source

public Task<JsonElement?> ProviderMetadata { get; }

Additional provider-specific metadata.

Value: Task<JsonElement?>

View source

public Task<LanguageModelRequestMetadata> Request { get; }

Additional request information.

Value: Task<LanguageModelRequestMetadata>

View source

public Task<LanguageModelResponseMetadata> Response { get; }

Additional response information.

Value: Task<LanguageModelResponseMetadata>

View source

public Task<LanguageModelUsage> Usage { get; }

The token usage of the generated response. Resolved when the response is finished.

Value: Task<LanguageModelUsage>

View source

public Task<IReadOnlyList<CallWarning>?> Warnings { get; }

Warnings from the model provider (e.g. unsupported settings).

Value: Task<IReadOnlyList<CallWarning>>

View source

public IAsyncEnumerable<JsonElement> ElementStream(CancellationToken cancellationToken = default)

Stream over complete array elements. Only available if the output is Array. Errors are suppressed (use OnError instead).

Parameters

Name Type Description
cancellationToken CancellationToken

Returns: IAsyncEnumerable<JsonElement>

Exceptions

Type Condition
UnsupportedFunctionalityException The output is not an array.

View source

public IAsyncEnumerable<ObjectStreamPart> FullStream(CancellationToken cancellationToken = default)

Stream of different types of events, including partial objects, errors, and finish events. Only errors that stop the stream, such as network errors, are thrown.

Parameters

Name Type Description
cancellationToken CancellationToken

Returns: IAsyncEnumerable<ObjectStreamPart>

View source

public IAsyncEnumerable<JsonElement> PartialObjectStream(CancellationToken cancellationToken = default)

Stream of partial objects. It gets more complete as the stream progresses. The partial object is not validated. Errors are suppressed (use OnError instead).

Parameters

Name Type Description
cancellationToken CancellationToken

Returns: IAsyncEnumerable<JsonElement>

View source

PipeTextStreamToResponse(ServerResponse, int?, string?, HeaderCollection?)

Section titled “PipeTextStreamToResponse(ServerResponse, int?, string?, HeaderCollection?)”
public Task PipeTextStreamToResponse(ServerResponse response, int? status = null, string? statusText = null, HeaderCollection? headers = null)

Writes text delta output to a response. It sets a content-type header to text/plain; charset=utf-8 and writes each text delta as a separate chunk. Maps to pipeTextStreamToResponse.

Parameters

Name Type Description
response ServerResponse
status int?
statusText string
headers HeaderCollection

Returns: Task

View source

public IAsyncEnumerable<string> TextStream(CancellationToken cancellationToken = default)

Text stream of the JSON representation of the generated object. It contains text chunks. When the stream is finished, the object is valid JSON that can be parsed. Errors are suppressed.

Parameters

Name Type Description
cancellationToken CancellationToken

Returns: IAsyncEnumerable<string>

View source

ToTextStreamResponse(int?, string?, HeaderCollection?)

Section titled “ToTextStreamResponse(int?, string?, HeaderCollection?)”
public TextStreamResponse ToTextStreamResponse(int? status = null, string? statusText = null, HeaderCollection? headers = null)

Creates a simple text stream response. The response has a content-type header set to text/plain; charset=utf-8. Each text delta is encoded as UTF-8 and sent as a separate chunk. Maps to toTextStreamResponse.

Parameters

Name Type Description
status int?
statusText string
headers HeaderCollection

Returns: TextStreamResponse

View source

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