Expand description
Fetch - live Workers AI model catalog retrieval over HTTPS.
Typed blocking GET of
/accounts/<id>/ai/models/search?format=openrouter&per_page=1000&hide_experimental=false&include_deprecated=false
(feedback 01 contract) with the token carried exclusively in the
`Authorization: Bearer *** header.
Pagination (feedback 01: “handle pagination even if Cloudflare later caps
per_page”): fetch_catalog_from_api follows cursor/next-page markers -
result_info.cursor, result_info.page/total_pages, a top-level
cursor, or a top-level next field - merging each page’s data array
until the marker disappears or [MAX_CATALOG_PAGES] pages were pulled. A
payload with no pagination field behaves exactly as before (single page).
Error taxonomy (feedback 01/03): missing token → CloudflareError::MissingEnv
(defensive - the core’s Config already guarantees a non-empty token);
403 → CloudflareError::AuthRejected with a scope classification from
the envelope code (invalid token / wrong account scope / Workers AI
permission / generic - see [auth_scope_for]); 401 → CloudflareError::Api
with the envelope code (defensive - the catalog endpoint rejects auth
failures as 403); rate limit → CloudflareError::Api code 429 plus a
Retry-After hint; transient 5xx → CloudflareError::Http; malformed JSON
or a payload without a data array → CloudflareError::NoDataArray;
transport/network failure → CloudflareError::Http.
Security: the token never reaches a URL, an error string, or a log line. Every text source that could feed an error (response body, transport message, body-read failure) is scrubbed of the token before it is mapped.
Constants§
- FETCH_
TIMEOUT - Overall per-request timeout for the catalog GET (15s, task contract).
Functions§
- auth_
header - The
Authorizationheader value - factored out for unit testing. This is the ONLY place the token leavesSecretString. - catalog_
url - The exact catalog endpoint URL for one account (feedback 01 contract).
- fetch_
catalog_ from_ api - Fetch the live catalog from the Cloudflare API, following pagination.