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

[Skip to content](#_top)

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

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

Copy Markdown

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

---

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

# Run a Workers AI model

ai.run(strmodel\_name, AIRunParams\*\*kwargs) -> [AIRunResponse](<https://developers.cloudflare.com/api/python/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

account\_id: str

Cloudflare account ID used for this AI model request.

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

model\_name: str

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

text: str

The text that you want to classify

minLength1

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

##### ReturnsExpand Collapse

<details>

<summary>

<a href="https://developers.cloudflare.com/api/python/resources/ai#(resource)%20ai%20%3E%20(model)%20ai_run_response%20%3E%20(schema)">AIRunResponse</a>

An array of classification results for the input text

</summary>

One of the following:

<details>

<summary>

List\[TextClassification]

An array of classification results for the input text

</summary>

label: Optional\[str]

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

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>

object

The generated image in PNG format

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

class Audio: …

</summary>

audio: Optional\[str]

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>

object

The generated audio in MP3 format

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

class TextEmbeddings: …

</summary>

data: Optional\[List\[List\[float]]]

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

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

class AutomaticSpeechRecognition: …

</summary>

text: str

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

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

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

</summary>

end: Optional\[float]

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

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

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

List\[ImageClassification]

</summary>

label: Optional\[str]

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

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>

List\[ObjectDetection]

An array of detected objects within the input image

</summary>

<details>

<summary>

box: Optional\[ObjectDetectionBox]

Coordinates defining the bounding box around the detected object

</summary>

xmax: Optional\[float]

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

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

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

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

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

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>

class UnionMember8: …

</summary>

response: str

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

An array of tool calls requests made during the response generation

</summary>

arguments: Optional\[object]

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

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

Usage statistics for the inference request

</summary>

completion\_tokens: Optional\[float]

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

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

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>

object

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

class Translation: …

</summary>

translated\_text: Optional\[str]

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>

class Summarization: …

</summary>

summary: Optional\[str]

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>

class ImageToText: …

</summary>

description: Optional\[str]

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

class ImageTextToText: …

</summary>

description: Optional\[str]

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

class MultimodalEmbeddings: …

</summary>

data: Optional\[List\[List\[float]]]

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

<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

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
)
response = client.ai.run(
    model_name="@cf/meta/llama-3.1-8b-instruct",
    account_id="023e105f4ecef8ad9ca31a8372d0c353",
    text="x",
)
print(response)
```

200 example

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

##### Returns Examples

200 example

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