Use this file to discover all available pages before exploring further.
The stream() method is used to make streaming chat completion requests to the Edgee AI Gateway. It returns an AsyncGenerator<StreamChunk> that yields response chunks as they arrive from the API.
When input is a string, it’s automatically converted to a user message:
for await (const chunk of edgee.stream('gpt-5.2', 'Tell me a story')) { if (chunk.text) { process.stdout.write(chunk.text); } if (chunk.finishReason) { console.log(`\nFinished: ${chunk.finishReason}`); }}// Equivalent to: input: { messages: [{ role: 'user', content: 'Tell me a story' }] }
When input is an InputObject, you have full control over the conversation:
Property
Type
Description
messages
Message[]
Array of conversation messages
tools
Tool[]
Array of function tools available to the model
tool_choice
ToolChoice
Controls which tool (if any) the model should call. See Tools documentation for details
tags
string[]
Optional tags to categorize and label the request for analytics and filtering. Can also be sent via the x-edgee-tags header (comma-separated)
compression_model
string
Compression model for this request: "agentic", "claude", "opencode", "cursor", or "customer". Each model is a bundle of compression strategies. Overrides API key settings when present.
compression_configuration
object
Configuration for the compression model. Currently only available for agentic. Contains optional rate (0.0-1.0, default 0.8) and semantic_preservation_threshold (0-100).
The StreamChunk class provides convenience getters for easier access:
Property
Type
Description
text
string | null
Shortcut to choices[0].delta.content - the incremental text content
role
string | null
Shortcut to choices[0].delta.role - the message role (first chunk only)
finishReason
string | null
Shortcut to choices[0].finish_reason - the finish reason (final chunk only)
Example - Using Convenience Properties:
for await (const chunk of edgee.stream('gpt-5.2', 'Explain quantum computing')) { // Content chunks if (chunk.text) { process.stdout.write(chunk.text); } // First chunk contains the role if (chunk.role) { console.log(`Role: ${chunk.role}`); } // Last chunk contains finish reason if (chunk.finishReason) { console.log(`\nFinish reason: ${chunk.finishReason}`); }}
Final chunk: Contains finish_reason indicating why generation stopped
Example - Collecting Full Response:
let fullText = '';for await (const chunk of edgee.stream('gpt-5.2', 'Tell me a story')) { if (chunk.text) { fullText += chunk.text; process.stdout.write(chunk.text); // Also display as it streams }}console.log(`\n\nFull response (${fullText.length} characters):`);console.log(fullText);
Some chunks may not contain content. This is normal and can happen when:
The chunk only contains metadata (role, finish_reason)
The chunk is part of tool call processing
Network buffering creates empty chunks
Always check for chunk.text before using it:
for await (const chunk of edgee.stream('gpt-5.2', 'Hello')) { if (chunk.text) { // ✅ Good: Check before using console.log(chunk.text); } // ❌ Bad: console.log(chunk.text) - may log null}