@@ -30,28 +30,6 @@ const client = new LlamaStackClient();
3030const models = await client .models .list ();
3131```
3232
33- ## Streaming responses
34-
35- We provide support for streaming responses using Server Sent Events (SSE).
36-
37- ``` ts
38- import LlamaStackClient from ' llama-stack-client' ;
39-
40- const client = new LlamaStackClient ();
41-
42- const stream = await client .chat .completions .create ({
43- messages: [{ content: ' string' , role: ' user' }],
44- model: ' model' ,
45- stream: true ,
46- });
47- for await (const chatCompletionChunk of stream ) {
48- console .log (chatCompletionChunk .id );
49- }
50- ```
51-
52- If you need to cancel a stream, you can ` break ` from the loop
53- or call ` stream.controller.abort() ` .
54-
5533### Request & Response types
5634
5735This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
@@ -179,6 +157,37 @@ On timeout, an `APIConnectionTimeoutError` is thrown.
179157
180158Note that requests which time out will be [ retried twice by default] ( #retries ) .
181159
160+ ## Auto-pagination
161+
162+ List methods in the LlamaStackClient API are paginated.
163+ You can use the ` for await … of ` syntax to iterate through items across all pages:
164+
165+ ``` ts
166+ async function fetchAllResponseListResponses(params ) {
167+ const allResponseListResponses = [];
168+ // Automatically fetches more pages as needed.
169+ for await (const responseListResponse of client .responses .list ()) {
170+ allResponseListResponses .push (responseListResponse );
171+ }
172+ return allResponseListResponses ;
173+ }
174+ ```
175+
176+ Alternatively, you can request a single page at a time:
177+
178+ ``` ts
179+ let page = await client .responses .list ();
180+ for (const responseListResponse of page .data ) {
181+ console .log (responseListResponse );
182+ }
183+
184+ // Convenience methods are provided for manually paginating:
185+ while (page .hasNextPage ()) {
186+ page = await page .getNextPage ();
187+ // ...
188+ }
189+ ```
190+
182191## Advanced Usage
183192
184193### Accessing raw Response data (e.g., headers)
0 commit comments