API keys

envless.keys.iterate()

Stream API keys one at a time

ts
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

ts
for await (const key of envless.keys.iterate()) {
    if (key.prefix === 'ev_sk_9fQ2xa') {
        console.log(key.id, key.scopes, key.projectIds)
        break
    }
}

Parameters

ParameterTypeRequiredDescription
options.limitnumberNoPage size per request, capped at 100 and defaulting to 100.
options.offsetnumberNoRow the walk starts at, advancing by the number of items each page returns.
options.searchstringNoCase insensitive substring match against name and prefix.
options.orderstringNoDefaults to name, which sorts A to Z. Pass asc for oldest first or desc for newest first on createdAt.
options.signalAbortSignalNoCancels 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 prefix and never secret, 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.