Function: doStreamFetch()
@providerprotocol/ai / http / doStreamFetch
Function: doStreamFetch()
Section titled “Function: doStreamFetch()”doStreamFetch(
url,init,config,provider,modality):Promise<Response>
Defined in: src/http/fetch.ts:314
Executes an HTTP fetch request for streaming responses.
Unlike doFetch, this function returns the response immediately without checking the HTTP status. This is necessary for Server-Sent Events (SSE) and other streaming protocols where error information may be embedded in the stream.
The caller is responsible for:
- Checking response.ok and handling HTTP errors
- Parsing the response stream (e.g., using parseSSEStream)
- Handling stream-specific error conditions
Retries are not performed for streaming requests since partial data may have already been consumed by the caller.
Parameters
Section titled “Parameters”string
The URL to fetch
RequestInit
Standard fetch RequestInit options
config
Section titled “config”Provider configuration containing fetch customization and timeout
provider
Section titled “provider”string
Provider identifier for error context
modality
Section titled “modality”Request modality for error context
Returns
Section titled “Returns”Promise<Response>
The Response object (may have non-2xx status)
Throws
Section titled “Throws”NETWORK_ERROR - When a network failure occurs
Throws
Section titled “Throws”TIMEOUT - When the request times out
Throws
Section titled “Throws”CANCELLED - When the request is aborted via signal
Example
Section titled “Example”const response = await doStreamFetch( 'https://api.openai.com/v1/chat/completions', { method: 'POST', headers: { 'Authorization': 'Bearer sk-...' }, body: JSON.stringify({ model: 'gpt-4', messages: [], stream: true }) }, { timeout: 120000 }, 'openai', 'llm');
if (!response.ok) { throw await normalizeHttpError(response, 'openai', 'llm');}
for await (const event of parseSSEStream(response.body!)) { console.log(event);}