Execute AI model
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.
Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYYAPI Email + API Key
The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
X-Auth-Email: user@example.comThe previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194Accepted Permissions (at least one required)
Workers AI WriteWorkers AI ReadBody ParametersJSONExpand Collapse
body: optional { text } or { prompt, guidance, height, 8 more } or { prompt, lang } or 12 more
TextToImage { prompt, guidance, height, 8 more }
Controls how closely the generated image should adhere to the prompt; higher values make the image more aligned with the prompt
For use with img2img tasks. An array of integers that represent the image data constrained to 8-bit unsigned integer values
An array representing An array of integers that represent mask image data for inpainting constrained to 8-bit unsigned integer values
The number of diffusion steps; higher values can improve quality but take longer
Prompt { prompt, frequency_penalty, lora, 10 more }
Decreases the likelihood of the model repeating the same lines verbatim.
Increases the likelihood of the model introducing new topics.
If true, a chat template is not applied and you must adhere to the specific model’s expected formatting.
Penalty for repeated tokens; higher values discourage repetition.
If true, the response will be streamed back incrementally using SSE, Server Sent Events.
Controls the randomness of the output; higher values produce more random results.
TextGeneration { messages, frequency_penalty, functions, 11 more }
messages: array of { content, role } An array of message objects representing the conversation history.
An array of message objects representing the conversation history.
Decreases the likelihood of the model repeating the same lines verbatim.
Increases the likelihood of the model introducing new topics.
If true, a chat template is not applied and you must adhere to the specific model’s expected formatting.
Penalty for repeated tokens; higher values discourage repetition.
If true, the response will be streamed back incrementally using SSE, Server Sent Events.
Controls the randomness of the output; higher values produce more random results.
tools: optional array of { description, name, parameters } or { function, type } A list of tools available for the assistant to use.
A list of tools available for the assistant to use.
{ description, name, parameters }
ImageToText { image, frequency_penalty, max_tokens, 8 more }
An array of integers that represent the image data constrained to 8-bit unsigned integer values
Decreases the likelihood of the model repeating the same lines verbatim.
If true, a chat template is not applied and you must adhere to the specific model’s expected formatting.
Penalty for repeated tokens; higher values discourage repetition.
Controls the randomness of the output; higher values produce more random results.
{ image, prompt, frequency_penalty, 8 more }
Decreases the likelihood of the model repeating the same lines verbatim.
Whether to ignore the EOS token and continue generating tokens after the EOS token is generated.
Penalty for repeated tokens; higher values discourage repetition.
Controls the randomness of the output; higher values produce more random results.
ImageTextToText { image, messages, frequency_penalty, 8 more }
messages: array of { content, role } An array of message objects representing the conversation history.
An array of message objects representing the conversation history.
Decreases the likelihood of the model repeating the same lines verbatim.
Whether to ignore the EOS token and continue generating tokens after the EOS token is generated.
Penalty for repeated tokens; higher values discourage repetition.
Controls the randomness of the output; higher values produce more random results.
ReturnsExpand Collapse
result: optional array of { label, score } or string or { audio } or 12 moreAn array of classification results for the input text
An array of classification results for the input text
TextClassification = array of { label, score } An array of classification results for the input text
An array of classification results for the input text
ObjectDetection = array of { box, label, score } An array of detected objects within the input image
An array of detected objects within the input image
{ response, tool_calls, usage }
Execute AI model
curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/ai/run/$MODEL_NAME \
-X POST \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{
"result": [
{
"label": "label",
"score": 0
}
]
}Returns Examples
{
"result": [
{
"label": "label",
"score": 0
}
]
}