Run a Workers AI model
ai.run(strmodel_name, AIRunParams**kwargs) -> AIRunResponse
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 for supported models and their input formats.
Security
API Token
The preferred authorization scheme for interacting with the Cloudflare API. Create a token.
Example:
API Email + API Key
The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
Example:
The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
Example:
Accepted Permissions (at least one required)
Parameters
Run a Workers AI model
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){
"result": [
{
"label": "label",
"score": 0
}
]
}Returns Examples
{
"result": [
{
"label": "label",
"score": 0
}
]
}
