---
title: Execute AI model
---

[Skip to content](#%5Ftop) 

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

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

Copy Markdown

Open in **Claude**

Open in **ChatGPT**

Open in **Cursor**

---

**Copy Markdown**

**View as Markdown**

# Execute AI model

client.ai.run(stringmodelName, AIRunParamsparams, RequestOptionsoptions?): [AIRunResponse](https://developers.cloudflare.com/api/typescript/resources/ai#%28resource%29%20ai%20%3E%20%28model%29%20ai%5Frun%5Fresponse%20%3E%20%28schema%29)

POST/accounts/{account\_id}/ai/run/{model\_name}

This endpoint provides users with the capability to run specific AI models on-demand.

By submitting the required input data, users can receive real-time predictions or results generated by the chosen AI model. The endpoint supports various AI model types, ensuring flexibility and adaptability for diverse use cases.

Model specific inputs available in [Cloudflare Docs](https://developers.cloudflare.com/workers-ai/models/).

##### Security

API Token

The preferred authorization scheme for interacting with the Cloudflare API. [Create a token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/).

**Example:**`Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY`

API Email + API Key

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

**Example:**`X-Auth-Email: user@example.com`

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

**Example:**`X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194`

##### Accepted Permissions (at least one required)

`Workers AI Write` `Workers AI Read`

##### ParametersExpand Collapse 

modelName: string

AIRunParams \= TextClassification | TextToImage | TextToSpeech | 12 more

AIRunParamsBase { account\_id, text } 

account\_id: string

Path param

text: string

Body param: The text that you want to classify

minLength1

TextClassification extends AIRunParamsBase { account\_id, text } 

TextToImage extends AIRunParamsBase { account\_id, text } 

TextToSpeech extends AIRunParamsBase { account\_id, text } 

TextEmbeddings extends AIRunParamsBase { account\_id, text } 

AutomaticSpeechRecognition extends AIRunParamsBase { account\_id, text } 

ImageClassification extends AIRunParamsBase { account\_id, text } 

ObjectDetection extends AIRunParamsBase { account\_id, text } 

Prompt extends AIRunParamsBase { account\_id, text } 

Messages extends AIRunParamsBase { account\_id, text } 

Translation extends AIRunParamsBase { account\_id, text } 

Summarization extends AIRunParamsBase { account\_id, text } 

ImageToText extends AIRunParamsBase { account\_id, text } 

Variant12 extends AIRunParamsBase { account\_id, text } 

Variant13 extends AIRunParamsBase { account\_id, text } 

MultimodalEmbeddings extends AIRunParamsBase { account\_id, text } 

##### ReturnsExpand Collapse 

AIRunResponse \= Array<TextClassification\> | Uploadable | Audio { audio } | 12 more

An array of classification results for the input text

One of the following:

Array<TextClassification\>

label?: string

The classification label assigned to the text (e.g., ‘POSITIVE’ or ‘NEGATIVE’)

score?: number

Confidence score indicating the likelihood that the text belongs to the specified label

Uploadable

Audio { audio } 

audio?: string

The generated audio in MP3 format, base64-encoded

Uploadable

TextEmbeddings { data, shape } 

data?: Array<Array<number\>\>

Embeddings of the requested text values

shape?: Array<number\>

AutomaticSpeechRecognition { text, vtt, word\_count, words } 

text: string

The transcription

vtt?: string

word\_count?: number

words?: Array<Word\>

end?: number

The ending second when the word completes

start?: number

The second this word begins in the recording

word?: string

Array<ImageClassification\>

label?: string

The predicted category or class for the input image based on analysis

score?: number

A confidence value, between 0 and 1, indicating how certain the model is about the predicted label

Array<ObjectDetection\>

box?: Box { xmax, xmin, ymax, ymin } 

Coordinates defining the bounding box around the detected object

xmax?: number

The x-coordinate of the bottom-right corner of the bounding box

xmin?: number

The x-coordinate of the top-left corner of the bounding box

ymax?: number

The y-coordinate of the bottom-right corner of the bounding box

ymin?: number

The y-coordinate of the top-left corner of the bounding box

label?: string

The class label or name of the detected object

score?: number

Confidence score indicating the likelihood that the detection is correct

UnionMember8 { response, tool\_calls, usage } 

response: string

The generated text response from the model

tool\_calls?: Array<ToolCall\>

An array of tool calls requests made during the response generation

arguments?: unknown

The arguments passed to be passed to the tool call request

name?: string

The name of the tool to be called

usage?: Usage { completion\_tokens, prompt\_tokens, total\_tokens } 

Usage statistics for the inference request

completion\_tokens?: number

Total number of tokens in output

prompt\_tokens?: number

Total number of tokens in input

total\_tokens?: number

Total number of input and output tokens

Uploadable

Translation { translated\_text } 

translated\_text?: string

The translated text in the target language

Summarization { summary } 

summary?: string

The summarized version of the input text

ImageToText { description } 

description?: string

ImageTextToText { description } 

description?: string

MultimodalEmbeddings { data, shape } 

data?: Array<Array<number\>\>

shape?: Array<number\>

### Execute AI model

TypeScript

HTTPHTTP

TypeScriptTypeScript

PythonPython

GoGo

TerraformTerraform

```
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.ai.run('model_name', {
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  text: 'x',
});

console.log(response);
```

200 example

```
{
  "result": [
    {
      "label": "label",
      "score": 0
    }
  ]
}
```

##### Returns Examples

200 example

```
{
  "result": [
    {
      "label": "label",
      "score": 0
    }
  ]
}
```