iterate(options?: SortedListOptions): AsyncGenerator<KeyResource, void, undefined>Returns an async generator that yields keys individually and fetches the next page only once the current one is drained. Breaking out of the loop stops the requests, which makes this the cheapest way to resolve a single prefix to a full row.
The generator defaults to the maximum page size of 100 and clamps anything larger, so options.limit only ever makes pages smaller. Since a workspace holds at most 100 live keys, one page normally covers everything.
Creating or revoking keys while you iterate changes the set that offsets are counted against, so a key can be skipped or repeated. Collect the ids you care about first, then act on them after the loop has finished.
Example
for await (const key of envless.keys.iterate()) {
if (key.prefix === 'ev_sk_9fQ2xa') {
console.log(key.id, key.scopes, key.projectIds)
break
}
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options.limit | number | No | Page size per request, capped at 100 and defaulting to 100. |
options.offset | number | No | Row the walk starts at, advancing by the number of items each page returns. |
options.search | string | No | Case insensitive substring match against name and prefix. |
options.order | string | No | Defaults to name, which sorts A to Z. Pass asc for oldest first or desc for newest first on createdAt. |
options.signal | AbortSignal | No | Cancels the request that is in flight and ends the iteration. |
Returns
AsyncGenerator<KeyResource, void, undefined> yielding one key per step.
Reads the keys collection. list returns one page as { items, pagination }, listAll collects every page into an array, and iterate streams one item at a time without buffering the whole set.
Worth knowing
- The generator is lazy, so no request is sent until you start consuming it.
- Yielded rows carry
prefixand neversecret, so scanning cannot recover a lost credential.
Required scopes
keys:read
Underlying endpoint
GET /keys
Request and response schema, every error code, and a live playground.
In Python
envless.keys.iterate()
The same method in envless-sdk, the Python SDK, with the same request, retries and errors.
In Ruby
Envless.keys.iterate
The same method in envless-sdk, the Ruby gem, with the same request, retries and errors.
In PHP
$envless->keys->iterate()
The same method in envless/sdk, the PHP SDK, with the same request, retries and errors.