---
title: Create a token
---

[Skip to content](#_top)

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

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

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

Copy Markdown

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

---

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

# Create a token

aisearch.tokens.create(TokenCreateParams\*\*kwargs) -> [TokenCreateResponse](<https://developers.cloudflare.com/api/python/resources/ai_search#(resource)%20ai_search.tokens%20%3E%20(model)%20token_create_response%20%3E%20(schema)>)

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

account\_id: str

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

cf\_api\_id: str

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

cf\_api\_key: str

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

name: str

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

legacy: Optional\[[bool](<https://developers.cloudflare.com/api/python/resources/ai_search/subresources/tokens/methods/create#(resource)%20ai_search.tokens%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20legacy%20%3E%20(schema)>)]

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

##### ReturnsExpand Collapse

<details>

<summary>

class TokenCreateResponse: …

</summary>

id: str

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: str

<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: datetime

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: datetime

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: str

<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: Optional\[str]

<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: Optional\[bool]

<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: Optional\[bool]

<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: Optional\[str]

<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

Python

HTTPTypeScriptPythonGoTerraform

```
import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
token = client.aisearch.tokens.create(
    account_id="c3dc5f0b34a14ff8e1b3ec04895e1b22",
    cf_api_id="a1b2c3d4e5f6",
    cf_api_key="abc123",
    name="my-token",
)
print(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
}
```