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
Properties
Section titled “Properties”FinishReason
Section titled “FinishReason”public Task<FinishReason> FinishReason { get; }The reason why the generation finished. Resolved when the response is finished.
Value: Task<FinishReason>
Object
Section titled “Object”public Task<T> Object { get; }The generated object. Resolved when the response is finished.
Value: Task<T>
ProviderMetadata
Section titled “ProviderMetadata”public Task<JsonElement?> ProviderMetadata { get; }Additional provider-specific metadata.
Value: Task<JsonElement?>
Request
Section titled “Request”public Task<LanguageModelRequestMetadata> Request { get; }Additional request information.
Value: Task<LanguageModelRequestMetadata>
Response
Section titled “Response”public Task<LanguageModelResponseMetadata> Response { get; }Additional response information.
Value: Task<LanguageModelResponseMetadata>
public Task<LanguageModelUsage> Usage { get; }The token usage of the generated response. Resolved when the response is finished.
Value: Task<LanguageModelUsage>
Warnings
Section titled “Warnings”public Task<IReadOnlyList<CallWarning>?> Warnings { get; }Warnings from the model provider (e.g. unsupported settings).
Value: Task<IReadOnlyList<CallWarning>>
Methods
Section titled “Methods”ElementStream(CancellationToken)
Section titled “ElementStream(CancellationToken)”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. |
FullStream(CancellationToken)
Section titled “FullStream(CancellationToken)”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>
PartialObjectStream(CancellationToken)
Section titled “PartialObjectStream(CancellationToken)”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>
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
TextStream(CancellationToken)
Section titled “TextStream(CancellationToken)”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>
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
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product