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

[Skip to content](#_top)

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

[AI](https://developers.cloudflare.com/api/go/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(ctx, modelName, params) (\*[AIRunResponseUnion](<https://developers.cloudflare.com/api/go/resources/ai#(resource)%20ai%20%3E%20(model)%20AIRunResponse%20%3E%20(schema)>), error)

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)%20default%20%3E%20(param)%20model_name%20%3E%20(schema)>)

<details>

<summary>

params AIRunParams

</summary>

AccountID param.Field\[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 param.Field\[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>

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

##### ReturnsExpand Collapse

<details>

<summary>

type AIRunResponseUnion interface{…}

An array of classification results for the input text

</summary>

One of the following:

<details>

<summary>

type AIRunResponseTextClassification \[]AIRunResponseTextClassificationItem

An array of classification results for the input text

</summary>

Label stringOptional

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

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

Score float64Optional

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

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%200">Link to this property</a>

UnionString

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

<details>

<summary>

type AIRunResponseAudio struct{…}

</summary>

Audio stringOptional

The generated audio in MP3 format, base64-encoded

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%202">Link to this property</a>

UnionString

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

<details>

<summary>

type AIRunResponseTextEmbeddings struct{…}

</summary>

Data \[]\[]float64Optional

Embeddings of the requested text values

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

Shape \[]float64Optional

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%204">Link to this property</a>

<details>

<summary>

type AIRunResponseAutomaticSpeechRecognition struct{…}

</summary>

Text string

The transcription

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

Vtt stringOptional

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

WordCount float64Optional

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

<details>

<summary>

Words \[]AIRunResponseAutomaticSpeechRecognitionWordOptional

</summary>

End float64Optional

The ending second when the word completes

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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 float64Optional

The second this word begins in the recording

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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 stringOptional

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%205">Link to this property</a>

<details>

<summary>

type AIRunResponseImageClassification \[]AIRunResponseImageClassificationItem

</summary>

Label stringOptional

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

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

Score float64Optional

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)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%206">Link to this property</a>

<details>

<summary>

type AIRunResponseObjectDetection \[]AIRunResponseObjectDetectionItem

An array of detected objects within the input image

</summary>

<details>

<summary>

Box AIRunResponseObjectDetectionBoxOptional

Coordinates defining the bounding box around the detected object

</summary>

Xmax float64Optional

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

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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 float64Optional

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

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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 float64Optional

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

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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 float64Optional

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

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%207%20%3E%20(items)%20%3E%20(property)%20box">Link to this property</a>

Label stringOptional

The class label or name of the detected object

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

Score float64Optional

Confidence score indicating the likelihood that the detection is correct

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%207">Link to this property</a>

<details>

<summary>

type AIRunResponseObject struct{…}

</summary>

Response string

The generated text response from the model

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

<details>

<summary>

ToolCalls \[]AIRunResponseObjectToolCallOptional

An array of tool calls requests made during the response generation

</summary>

Arguments unknownOptional

The arguments passed to be passed to the tool call request

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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 stringOptional

The name of the tool to be called

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%208%20%3E%20(property)%20tool_calls">Link to this property</a>

<details>

<summary>

Usage AIRunResponseObjectUsageOptional

Usage statistics for the inference request

</summary>

CompletionTokens float64Optional

Total number of tokens in output

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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>

PromptTokens float64Optional

Total number of tokens in input

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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>

TotalTokens float64Optional

Total number of input and output tokens

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%208">Link to this property</a>

UnionString

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

<details>

<summary>

type AIRunResponseTranslation struct{…}

</summary>

TranslatedText stringOptional

The translated text in the target language

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%2010">Link to this property</a>

<details>

<summary>

type AIRunResponseSummarization struct{…}

</summary>

Summary stringOptional

The summarized version of the input text

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%2011">Link to this property</a>

<details>

<summary>

type AIRunResponseImageToText struct{…}

</summary>

Description stringOptional

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%2012">Link to this property</a>

<details>

<summary>

type AIRunResponseImageTextToText struct{…}

</summary>

Description stringOptional

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)%20%3E%20(variant)%2013">Link to this property</a>

<details>

<summary>

type AIRunResponseMultimodalEmbeddings struct{…}

</summary>

Data \[]\[]float64Optional

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

Shape \[]float64Optional

<a href="#(resource)%20ai%20%3E%20(model)%20AIRunResponse%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)%20AIRunResponse%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)%20AIRunResponse%20%3E%20(schema)>)

### Run a Workers AI model

Go

HTTPTypeScriptPythonGoTerraform

```
package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/ai"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  response, err := client.AI.Run(
    context.TODO(),
    "@cf/meta/llama-3.1-8b-instruct",
    ai.AIRunParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response)
}
```

200 example

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

##### Returns Examples

200 example

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