Pagination
List methods return results one page at a time. The SDK can fetch the next pages for you as you loop, or you can fetch pages yourself.
The loop requests the next page only when it reaches the end of the current one. If you break out early, no more pages are fetched.
List methods
| Method | Query parameters | Items |
|---|---|---|
glexir.files.list(query?) | after, limit, order, purpose | FileObject |
glexir.batches.list(query?) | after, limit | Batch |
glexir.chat.completions.list(query?) | after, limit, metadata, model, order | ChatCompletion |
glexir.chat.completions.messages.list(completionId, query?) | after, limit, order | ChatCompletionStoreMessage |
glexir.responses.inputItems.list(responseId, query?) | after, limit, order, include | ResponseItem |
glexir.conversations.items.list(conversationId, query?) | after, limit, order, include | ConversationItem |
glexir.models.list() | none | Model |
Each method also takes request options as its last argument. They apply to every page the SDK fetches, including signal, headers, timeout and maxRetries.
glexir.models.list() always returns a single page with every model. It has no cursor, so for await stops after that page.
Page size and order
- Files and batches are listed by the gateway from Glexir's own records.
limitdefaults to 20 and is clamped to 1 to 100. Results are newest first. Files also acceptorder: "asc". - Stored chat completions default to
order: "asc".metadatafilters by key/value pairs, for example{ metadata: { tenant: "acme" } }. - Conversation items default to
order: "desc"(newest first). - Other lists pass
limitandorderthrough to the upstream API, which sets their defaults.
Page by page
Await a list call to get the first page as a CursorPage:
To loop over pages instead of items, use iterPages():
Cursors
Pages are linked by an after cursor, which is an object ID. To resume a listing later, for example in a paginated UI or a job that runs in batches, save the cursor and pass it as after:
The SDK picks the next cursor like this:
| List | Next after |
|---|---|
conversations.items.list | The page's last_id |
| All other lists | The id of the last item on the page |
Keep the other query parameters the same when you pass a cursor. getNextPage() does this for you: it repeats the original query with the new after.
Reference
CursorPage
One page of results. It is also an async iterable over the items of this page and all later pages.
dataItem[]optional- The items on this page.
has_morebooleanoptional- Whether the API reported more results.
falseif the response did not include it. first_idstring | null | undefinedoptional- The first item's ID, when the API returns it.
last_idstring | null | undefinedoptional- The last item's ID, when the API returns it.
hasNextPage()booleanoptionaltruewhenhas_moreis true, the page is not empty, and a next cursor exists. Alwaysfalseformodels.list().getNextPage()Promise<CursorPage<Item>>optional- Fetches the next page. Throws an
Errorif there is none, so checkhasNextPage()first. iterPages()AsyncGenerator<CursorPage<Item>>optional- Yields this page, then each following page.
[Symbol.asyncIterator]()AsyncGenerator<Item>optional- Yields every item on this page and the pages after it. This is what
for await (const item of page)uses.
PagePromise
What a list method returns. It is an APIPromise for the first CursorPage<Item>, so you can await it or call withRawResponse() and asResponse(). It is also an async iterable over all items, which is why for await (const x of glexir.files.list()) works without an await first.
CursorPageParams
The type is exported from @glexir/sdk. Each list method has its own params type with these two fields plus the extra filters in the table above: FileListParams, BatchListParams, ChatCompletionListParams, MessageListParams, InputItemListParams and ItemListParams.