AiSearchToken
Source:
src/Cloudflare/AiSearch/AiSearchToken.ts
A Cloudflare AI Search service token — the credential AI Search uses to access your data source (R2 bucket, Vectorize index, Workers AI) when indexing.
The token wraps an existing Cloudflare API token (cfApiId +
cfApiKey). That API token must carry the “AI Search Index Engine”
permission group — Cloudflare validates the credential on create and
update and rejects tokens without it. Pair it with
Cloudflare.AccountApiToken to mint the underlying API token in the
same stack, then reference the service token’s id from an AI Search
instance’s tokenId prop.
Creating a Token
Section titled “Creating a Token”const apiToken = yield* Cloudflare.AccountApiToken("SearchTokenSource", { policies: [ { effect: "allow", permissionGroups: ["AI Search Index Engine"], resources: { [`com.cloudflare.api.account.${accountId}`]: "*" }, }, ],});const token = yield* Cloudflare.AiSearchToken("SearchToken", { cfApiId: apiToken.tokenId, cfApiKey: apiToken.value,});Using the Token from an Instance
Section titled “Using the Token from an Instance”const search = yield* Cloudflare.AiSearchInstance("Search", { source: bucket.bucketName, tokenId: token.id,});