# Tokens ## List tokens. `client.aiSearch.tokens.list(TokenListParamsparams, RequestOptionsoptions?): V4PagePaginationArray` **get** `/accounts/{account_id}/ai-search/tokens` List tokens. ### Parameters - `params: TokenListParams` - `account_id: string` Path param - `page?: number` Query param: Page number (1-indexed). - `per_page?: number` Query param: Number of results per page. - `search?: string` Query param: Filter tokens whose name contains this string (case-insensitive). ### Returns - `TokenListResponse` - `id: string` - `cf_api_id: string` - `created_at: string` - `modified_at: string` - `name: string` - `created_by?: string | null` - `enabled?: boolean` - `legacy?: boolean` - `modified_by?: string | null` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const tokenListResponse of client.aiSearch.tokens.list({ account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', })) { console.log(tokenListResponse.id); } ``` #### Response ```json { "result": [ { "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", "cf_api_id": "cf_api_id", "created_at": "2019-12-27T18:11:19.117Z", "modified_at": "2019-12-27T18:11:19.117Z", "name": "name", "created_by": "created_by", "enabled": true, "legacy": true, "modified_by": "modified_by" } ], "result_info": { "count": 0, "page": 0, "per_page": 0, "total_count": 0 }, "success": true } ``` ## Create token. `client.aiSearch.tokens.create(TokenCreateParamsparams, RequestOptionsoptions?): TokenCreateResponse` **post** `/accounts/{account_id}/ai-search/tokens` Create a new token. ### Parameters - `params: TokenCreateParams` - `account_id: string` Path param - `cf_api_id: string` Body param - `cf_api_key: string` Body param - `name: string` Body param - `legacy?: boolean` Body param ### Returns - `TokenCreateResponse` - `id: string` - `cf_api_id: string` - `created_at: string` - `modified_at: string` - `name: string` - `created_by?: string | null` - `enabled?: boolean` - `legacy?: boolean` - `modified_by?: string | null` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const token = await client.aiSearch.tokens.create({ account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', cf_api_id: 'a1b2c3d4e5f6', cf_api_key: 'abc123', name: 'my-token', }); console.log(token.id); ``` #### Response ```json { "result": { "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", "cf_api_id": "cf_api_id", "created_at": "2019-12-27T18:11:19.117Z", "modified_at": "2019-12-27T18:11:19.117Z", "name": "name", "created_by": "created_by", "enabled": true, "legacy": true, "modified_by": "modified_by" }, "success": true } ``` ## Read token. `client.aiSearch.tokens.read(stringid, TokenReadParamsparams, RequestOptionsoptions?): TokenReadResponse` **get** `/accounts/{account_id}/ai-search/tokens/{id}` Read token. ### Parameters - `id: string` - `params: TokenReadParams` - `account_id: string` ### Returns - `TokenReadResponse` - `id: string` - `cf_api_id: string` - `created_at: string` - `modified_at: string` - `name: string` - `created_by?: string | null` - `enabled?: boolean` - `legacy?: boolean` - `modified_by?: string | null` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.aiSearch.tokens.read('62af0db3-c410-40b2-9ee3-0e93f6dd1de0', { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', }); console.log(response.id); ``` #### Response ```json { "result": { "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", "cf_api_id": "cf_api_id", "created_at": "2019-12-27T18:11:19.117Z", "modified_at": "2019-12-27T18:11:19.117Z", "name": "name", "created_by": "created_by", "enabled": true, "legacy": true, "modified_by": "modified_by" }, "success": true } ``` ## Update token. `client.aiSearch.tokens.update(stringid, TokenUpdateParamsparams, RequestOptionsoptions?): TokenUpdateResponse` **put** `/accounts/{account_id}/ai-search/tokens/{id}` Update token. ### Parameters - `id: string` - `params: TokenUpdateParams` - `account_id: string` Path param - `cf_api_id: string` Body param - `cf_api_key: string` Body param - `name: string` Body param - `legacy?: boolean` Body param ### Returns - `TokenUpdateResponse` - `id: string` - `cf_api_id: string` - `created_at: string` - `modified_at: string` - `name: string` - `created_by?: string | null` - `enabled?: boolean` - `legacy?: boolean` - `modified_by?: string | null` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const token = await client.aiSearch.tokens.update('62af0db3-c410-40b2-9ee3-0e93f6dd1de0', { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', cf_api_id: 'a1b2c3d4e5f6', cf_api_key: 'abc123', name: 'my-token', }); console.log(token.id); ``` #### Response ```json { "result": { "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", "cf_api_id": "cf_api_id", "created_at": "2019-12-27T18:11:19.117Z", "modified_at": "2019-12-27T18:11:19.117Z", "name": "name", "created_by": "created_by", "enabled": true, "legacy": true, "modified_by": "modified_by" }, "success": true } ``` ## Delete token. `client.aiSearch.tokens.delete(stringid, TokenDeleteParamsparams, RequestOptionsoptions?): TokenDeleteResponse` **delete** `/accounts/{account_id}/ai-search/tokens/{id}` Delete token. ### Parameters - `id: string` - `params: TokenDeleteParams` - `account_id: string` ### Returns - `TokenDeleteResponse = unknown` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const token = await client.aiSearch.tokens.delete('62af0db3-c410-40b2-9ee3-0e93f6dd1de0', { account_id: 'c3dc5f0b34a14ff8e1b3ec04895e1b22', }); console.log(token); ``` #### Response ```json { "result": {}, "success": true } ``` ## Domain Types ### Token List Response - `TokenListResponse` - `id: string` - `cf_api_id: string` - `created_at: string` - `modified_at: string` - `name: string` - `created_by?: string | null` - `enabled?: boolean` - `legacy?: boolean` - `modified_by?: string | null` ### Token Create Response - `TokenCreateResponse` - `id: string` - `cf_api_id: string` - `created_at: string` - `modified_at: string` - `name: string` - `created_by?: string | null` - `enabled?: boolean` - `legacy?: boolean` - `modified_by?: string | null` ### Token Read Response - `TokenReadResponse` - `id: string` - `cf_api_id: string` - `created_at: string` - `modified_at: string` - `name: string` - `created_by?: string | null` - `enabled?: boolean` - `legacy?: boolean` - `modified_by?: string | null` ### Token Update Response - `TokenUpdateResponse` - `id: string` - `cf_api_id: string` - `created_at: string` - `modified_at: string` - `name: string` - `created_by?: string | null` - `enabled?: boolean` - `legacy?: boolean` - `modified_by?: string | null` ### Token Delete Response - `TokenDeleteResponse = unknown`