---
title: Create a token
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/typescript)

[AI Search](https://developers.cloudflare.com/api/typescript/resources/ai_search)

[Tokens](https://developers.cloudflare.com/api/typescript/resources/ai_search/subresources/tokens)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Create a token

client.aiSearch.tokens.create(TokenCreateParams {account\_id, cf\_api\_id, cf\_api\_key, 2 more } params, RequestOptionsoptions?): [TokenCreateResponse](<https://developers.cloudflare.com/api/typescript/resources/ai_search#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)>) {id, cf\_api\_id, created\_at, 6 more }

POST/accounts/{account\_id}/ai-search/tokens

Create a stored Cloudflare credential for an AI Search instance to access its data source.

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

**Example:**<code>X-Auth-Email: user@example.com</code>

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### ParametersExpand Collapse

<details>

<summary>

params: TokenCreateParams {account\_id, cf\_api\_id, cf\_api\_key, 2 more }

</summary>

account\_id: string

Path param

<a href="#(resource)%20ai_search.tokens%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20account_id">Link to this property</a>

cf\_api\_id: string

Body param

<a href="#(resource)%20ai_search.tokens%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20cf_api_id">Link to this property</a>

cf\_api\_key: string

Body param

<a href="#(resource)%20ai_search.tokens%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20cf_api_key">Link to this property</a>

name: string

Body param

<a href="#(resource)%20ai_search.tokens%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20name">Link to this property</a>

legacy?: boolean

Body param

<a href="#(resource)%20ai_search.tokens%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20legacy">Link to this property</a>

</details>

[Link to this property](<#(resource)%20ai_search.tokens%20%3E%20(method)%20create%20%3E%20(params)%20default>)

##### ReturnsExpand Collapse

<details>

<summary>

TokenCreateResponse {id, cf\_api\_id, created\_at, 6 more }

</summary>

id: string

formatuuid

<a href="#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)%20%3E%20(property)%20id">Link to this property</a>

cf\_api\_id: string

<a href="#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)%20%3E%20(property)%20cf_api_id">Link to this property</a>

created\_at: string

formatdate-time

<a href="#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)%20%3E%20(property)%20created_at">Link to this property</a>

modified\_at: string

formatdate-time

<a href="#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)%20%3E%20(property)%20modified_at">Link to this property</a>

name: string

<a href="#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)%20%3E%20(property)%20name">Link to this property</a>

created\_by?: string| null

<a href="#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)%20%3E%20(property)%20created_by">Link to this property</a>

enabled?: boolean

<a href="#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)%20%3E%20(property)%20enabled">Link to this property</a>

legacy?: boolean

<a href="#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)%20%3E%20(property)%20legacy">Link to this property</a>

modified\_by?: string| null

<a href="#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)%20%3E%20(property)%20modified_by">Link to this property</a>

</details>

[Link to this property](<#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)>)

### Create a token

TypeScript

HTTPTypeScriptPythonGoTerraform

```
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);
```

200 example

```
{
  "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
}
```

##### Returns Examples

200 example

```
{
  "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
}
```