---
title: Run a Workers AI model
---

[Skip to content](#_top)

[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**

# Run a Workers AI model

client.ai.run(stringmodelName, AIRunParamsparams, RequestOptionsoptions?): [AIRunResponse](<https://developers.cloudflare.com/api/typescript/resources/ai#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)>)

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

Runs the Workers AI model specified in the URL path. Send the model’s inputs directly in the request body, without a model/input/options wrapper.

Accepts model-specific JSON or binary input. The response format depends on the model and the requested output.

See the [model catalog](https://developers.cloudflare.com/workers-ai/models/) for supported models and their input formats.

##### 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>

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

`Workers AI Write``Workers AI Read`

##### ParametersExpand Collapse

modelName: string

Workers AI model identifier, including its namespace and model name.

[Link to this property](<#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%200%20%3E%20(param)%20model_name%20%3E%20(schema)>)

<details>

<summary>

AIRunParams = TextClassification| TextToImage| TextToSpeech| 12 more

</summary>

<details>

<summary>

AIRunParamsBase {account\_id, text }

</summary>

account\_id: string

Path param: Cloudflare account ID used for this AI model request.

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%200%20%3E%20(param)%20account_id">Link to this property</a>

text: string

Body param: The text that you want to classify

minLength1

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%200%20%3E%20(param)%20text">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(method)%20run.typescript.base_params">Link to this property</a>

TextClassification extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%200">Link to this property</a>

TextToImage extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%201">Link to this property</a>

TextToSpeech extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%202">Link to this property</a>

TextEmbeddings extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%203">Link to this property</a>

AutomaticSpeechRecognition extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%204">Link to this property</a>

ImageClassification extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%205">Link to this property</a>

ObjectDetection extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%206">Link to this property</a>

Prompt extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%207">Link to this property</a>

Messages extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%208">Link to this property</a>

Translation extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%209">Link to this property</a>

Summarization extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%2010">Link to this property</a>

ImageToText extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%2011">Link to this property</a>

Variant12 extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%2012">Link to this property</a>

Variant13 extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%2013">Link to this property</a>

MultimodalEmbeddings extends AIRunParamsBase {account\_id, text }

<a href="#(resource)%20ai%20%3E%20(method)%20run%20%3E%20(params)%2014">Link to this property</a>

</details>

[Link to this property](<#(resource)%20ai%20%3E%20(method)%20run.typescript.params>)

##### ReturnsExpand Collapse

<details>

<summary>

AIRunResponse = Array&lt;TextClassification&gt;| Uploadable| Audio {audio } | 12 more

An array of classification results for the input text

</summary>

One of the following:

<details>

<summary>

Array&lt;TextClassification&gt;

</summary>

label?: string

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

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%200%20%3E%20(items)%20%3E%20(property)%20label">Link to this property</a>

score?: number

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

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%200%20%3E%20(items)%20%3E%20(property)%20score">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%200">Link to this property</a>

Uploadable

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%201">Link to this property</a>

<details>

<summary>

Audio {audio }

</summary>

audio?: string

The generated audio in MP3 format, base64-encoded

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%202%20%3E%20(property)%20audio">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%202">Link to this property</a>

Uploadable

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%203">Link to this property</a>

<details>

<summary>

TextEmbeddings {data, shape }

</summary>

data?: Array&lt;Array&lt;number&gt;&gt;

Embeddings of the requested text values

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%204%20%3E%20(property)%20data">Link to this property</a>

shape?: Array&lt;number&gt;

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%204%20%3E%20(property)%20shape">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%204">Link to this property</a>

<details>

<summary>

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

</summary>

text: string

The transcription

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%205%20%3E%20(property)%20text">Link to this property</a>

vtt?: string

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%205%20%3E%20(property)%20vtt">Link to this property</a>

word\_count?: number

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%205%20%3E%20(property)%20word_count">Link to this property</a>

<details>

<summary>

words?: Array&lt;Word&gt;

</summary>

end?: number

The ending second when the word completes

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%205%20%3E%20(property)%20words%20%3E%20(items)%20%3E%20(property)%20end">Link to this property</a>

start?: number

The second this word begins in the recording

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%205%20%3E%20(property)%20words%20%3E%20(items)%20%3E%20(property)%20start">Link to this property</a>

word?: string

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%205%20%3E%20(property)%20words%20%3E%20(items)%20%3E%20(property)%20word">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%205%20%3E%20(property)%20words">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%205">Link to this property</a>

<details>

<summary>

Array&lt;ImageClassification&gt;

</summary>

label?: string

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

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%206%20%3E%20(items)%20%3E%20(property)%20label">Link to this property</a>

score?: number

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

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%206%20%3E%20(items)%20%3E%20(property)%20score">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%206">Link to this property</a>

<details>

<summary>

Array&lt;ObjectDetection&gt;

</summary>

<details>

<summary>

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

Coordinates defining the bounding box around the detected object

</summary>

xmax?: number

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

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%207%20%3E%20(items)%20%3E%20(property)%20box%20%3E%20(property)%20xmax">Link to this property</a>

xmin?: number

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

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%207%20%3E%20(items)%20%3E%20(property)%20box%20%3E%20(property)%20xmin">Link to this property</a>

ymax?: number

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

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%207%20%3E%20(items)%20%3E%20(property)%20box%20%3E%20(property)%20ymax">Link to this property</a>

ymin?: number

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

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%207%20%3E%20(items)%20%3E%20(property)%20box%20%3E%20(property)%20ymin">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%207%20%3E%20(items)%20%3E%20(property)%20box">Link to this property</a>

label?: string

The class label or name of the detected object

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%207%20%3E%20(items)%20%3E%20(property)%20label">Link to this property</a>

score?: number

Confidence score indicating the likelihood that the detection is correct

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%207%20%3E%20(items)%20%3E%20(property)%20score">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%207">Link to this property</a>

<details>

<summary>

UnionMember8 {response, tool\_calls, usage }

</summary>

response: string

The generated text response from the model

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%208%20%3E%20(property)%20response">Link to this property</a>

<details>

<summary>

tool\_calls?: Array&lt;ToolCall&gt;

An array of tool calls requests made during the response generation

</summary>

arguments?: unknown

The arguments passed to be passed to the tool call request

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%208%20%3E%20(property)%20tool_calls%20%3E%20(items)%20%3E%20(property)%20arguments">Link to this property</a>

name?: string

The name of the tool to be called

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%208%20%3E%20(property)%20tool_calls%20%3E%20(items)%20%3E%20(property)%20name">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%208%20%3E%20(property)%20tool_calls">Link to this property</a>

<details>

<summary>

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

Usage statistics for the inference request

</summary>

completion\_tokens?: number

Total number of tokens in output

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%208%20%3E%20(property)%20usage%20%3E%20(property)%20completion_tokens">Link to this property</a>

prompt\_tokens?: number

Total number of tokens in input

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%208%20%3E%20(property)%20usage%20%3E%20(property)%20prompt_tokens">Link to this property</a>

total\_tokens?: number

Total number of input and output tokens

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%208%20%3E%20(property)%20usage%20%3E%20(property)%20total_tokens">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%208%20%3E%20(property)%20usage">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%208">Link to this property</a>

Uploadable

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%209">Link to this property</a>

<details>

<summary>

Translation {translated\_text }

</summary>

translated\_text?: string

The translated text in the target language

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%2010%20%3E%20(property)%20translated_text">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%2010">Link to this property</a>

<details>

<summary>

Summarization {summary }

</summary>

summary?: string

The summarized version of the input text

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%2011%20%3E%20(property)%20summary">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%2011">Link to this property</a>

<details>

<summary>

ImageToText {description }

</summary>

description?: string

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%2012%20%3E%20(property)%20description">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%2012">Link to this property</a>

<details>

<summary>

ImageTextToText {description }

</summary>

description?: string

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%2013%20%3E%20(property)%20description">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%2013">Link to this property</a>

<details>

<summary>

MultimodalEmbeddings {data, shape }

</summary>

data?: Array&lt;Array&lt;number&gt;&gt;

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%2014%20%3E%20(property)%20data">Link to this property</a>

shape?: Array&lt;number&gt;

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%2014%20%3E%20(property)%20shape">Link to this property</a>

</details>

<a href="#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)%20%3E%20(variant)%2014">Link to this property</a>

</details>

[Link to this property](<#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)>)

### Run a Workers AI model

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 response = await client.ai.run('@cf/meta/llama-3.1-8b-instruct', {
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  text: 'x',
});

console.log(response);
```

200 example

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

##### Returns Examples

200 example

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