zod stream / API reference

API Reference

zod-stream offers various classes and functions to handle structured JSON streaming. Below is the detailed API reference.

ZodStream

import ZodStream from "zod-stream"
 
const zodstream = new ZodStream(config)

Constructor

constructor(config?: ClientConfig)
ClientConfig
PropertyTypeDescriptionDefault
debugbooleanEnables debug mode for detailed logging.false

Methods

chatCompletionStream
chatCompletionStream<T extends z.AnyZodObject>(params: StructredStreamCompletionParams<T>): Promise<AsyncGenerator<Partial<z.infer<T>>, void, unknown>>
StructredStreamCompletionParams
PropertyTypeDescription
completionPromiseFunctionA function that returns a promise resolving to a stream.
dataanyData to be sent in the stream request.
response_modelResponseModel<T>The Zod schema model for the stream response.
ResponseModel
PropertyTypeDescription
namestringName of the response model.
schemaz.AnyZodObjectThe Zod schema for validation.
descriptionstringA description of the response model.

OAIStream

OAIStream({ res }: OaiStreamArgs): ReadableStream<Uint8Array>
OaiStreamArgs
PropertyTypeDescription
resStreamThe stream of data from OpenAI or AnyScale.