Skip to content
Start here

Execute AI model

client.ai.run(stringmodelName, AIRunParamsparams, RequestOptionsoptions?): AIRunResponse
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.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a 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 WriteWorkers AI Read
ParametersExpand Collapse
modelName: string
AIRunParams = TextClassification | TextToImage | TextToSpeech | 12 more
AIRunParamsBase
TextClassification extends AIRunParamsBase
TextToImage extends AIRunParamsBase
TextToSpeech extends AIRunParamsBase
TextEmbeddings extends AIRunParamsBase
AutomaticSpeechRecognition extends AIRunParamsBase
ImageClassification extends AIRunParamsBase
ObjectDetection extends AIRunParamsBase
Prompt extends AIRunParamsBase
Messages extends AIRunParamsBase
Translation extends AIRunParamsBase
Summarization extends AIRunParamsBase
ImageToText extends AIRunParamsBase
Variant12 extends AIRunParamsBase
Variant13 extends AIRunParamsBase
MultimodalEmbeddings extends AIRunParamsBase
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

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);
{
  "result": [
    {
      "label": "label",
      "score": 0
    }
  ]
}
Returns Examples
{
  "result": [
    {
      "label": "label",
      "score": 0
    }
  ]
}