# AI ## Execute AI model `ai.run(strmodel_name, AIRunParams**kwargs) -> 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](https://developers.cloudflare.com/workers-ai/models/). ### Parameters - `account_id: str` - `model_name: str` - `text: str` The text that you want to classify ### Returns - `AIRunResponse` An array of classification results for the input text - `List[TextClassification]` An array of classification results for the input text - `label: Optional[str]` The classification label assigned to the text (e.g., 'POSITIVE' or 'NEGATIVE') - `score: Optional[float]` Confidence score indicating the likelihood that the text belongs to the specified label - `object` The generated image in PNG format - `class Audio: …` - `audio: Optional[str]` The generated audio in MP3 format, base64-encoded - `object` The generated audio in MP3 format - `class TextEmbeddings: …` - `data: Optional[List[List[float]]]` Embeddings of the requested text values - `shape: Optional[List[float]]` - `class AutomaticSpeechRecognition: …` - `text: str` The transcription - `vtt: Optional[str]` - `word_count: Optional[float]` - `words: Optional[List[AutomaticSpeechRecognitionWord]]` - `end: Optional[float]` The ending second when the word completes - `start: Optional[float]` The second this word begins in the recording - `word: Optional[str]` - `List[ImageClassification]` - `label: Optional[str]` The predicted category or class for the input image based on analysis - `score: Optional[float]` A confidence value, between 0 and 1, indicating how certain the model is about the predicted label - `List[ObjectDetection]` An array of detected objects within the input image - `box: Optional[ObjectDetectionBox]` Coordinates defining the bounding box around the detected object - `xmax: Optional[float]` The x-coordinate of the bottom-right corner of the bounding box - `xmin: Optional[float]` The x-coordinate of the top-left corner of the bounding box - `ymax: Optional[float]` The y-coordinate of the bottom-right corner of the bounding box - `ymin: Optional[float]` The y-coordinate of the top-left corner of the bounding box - `label: Optional[str]` The class label or name of the detected object - `score: Optional[float]` Confidence score indicating the likelihood that the detection is correct - `class UnionMember8: …` - `response: str` The generated text response from the model - `tool_calls: Optional[List[UnionMember8ToolCall]]` An array of tool calls requests made during the response generation - `arguments: Optional[object]` The arguments passed to be passed to the tool call request - `name: Optional[str]` The name of the tool to be called - `usage: Optional[UnionMember8Usage]` Usage statistics for the inference request - `completion_tokens: Optional[float]` Total number of tokens in output - `prompt_tokens: Optional[float]` Total number of tokens in input - `total_tokens: Optional[float]` Total number of input and output tokens - `object` - `class Translation: …` - `translated_text: Optional[str]` The translated text in the target language - `class Summarization: …` - `summary: Optional[str]` The summarized version of the input text - `class ImageToText: …` - `description: Optional[str]` - `class ImageTextToText: …` - `description: Optional[str]` - `class MultimodalEmbeddings: …` - `data: Optional[List[List[float]]]` - `shape: Optional[List[float]]` ### Example ```python 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="model_name", account_id="023e105f4ecef8ad9ca31a8372d0c353", text="x", ) print(response) ``` #### Response ```json { "result": [ { "label": "label", "score": 0 } ] } ``` ## Domain Types ### AI Run Response - `AIRunResponse` An array of classification results for the input text - `List[TextClassification]` An array of classification results for the input text - `label: Optional[str]` The classification label assigned to the text (e.g., 'POSITIVE' or 'NEGATIVE') - `score: Optional[float]` Confidence score indicating the likelihood that the text belongs to the specified label - `object` The generated image in PNG format - `class Audio: …` - `audio: Optional[str]` The generated audio in MP3 format, base64-encoded - `object` The generated audio in MP3 format - `class TextEmbeddings: …` - `data: Optional[List[List[float]]]` Embeddings of the requested text values - `shape: Optional[List[float]]` - `class AutomaticSpeechRecognition: …` - `text: str` The transcription - `vtt: Optional[str]` - `word_count: Optional[float]` - `words: Optional[List[AutomaticSpeechRecognitionWord]]` - `end: Optional[float]` The ending second when the word completes - `start: Optional[float]` The second this word begins in the recording - `word: Optional[str]` - `List[ImageClassification]` - `label: Optional[str]` The predicted category or class for the input image based on analysis - `score: Optional[float]` A confidence value, between 0 and 1, indicating how certain the model is about the predicted label - `List[ObjectDetection]` An array of detected objects within the input image - `box: Optional[ObjectDetectionBox]` Coordinates defining the bounding box around the detected object - `xmax: Optional[float]` The x-coordinate of the bottom-right corner of the bounding box - `xmin: Optional[float]` The x-coordinate of the top-left corner of the bounding box - `ymax: Optional[float]` The y-coordinate of the bottom-right corner of the bounding box - `ymin: Optional[float]` The y-coordinate of the top-left corner of the bounding box - `label: Optional[str]` The class label or name of the detected object - `score: Optional[float]` Confidence score indicating the likelihood that the detection is correct - `class UnionMember8: …` - `response: str` The generated text response from the model - `tool_calls: Optional[List[UnionMember8ToolCall]]` An array of tool calls requests made during the response generation - `arguments: Optional[object]` The arguments passed to be passed to the tool call request - `name: Optional[str]` The name of the tool to be called - `usage: Optional[UnionMember8Usage]` Usage statistics for the inference request - `completion_tokens: Optional[float]` Total number of tokens in output - `prompt_tokens: Optional[float]` Total number of tokens in input - `total_tokens: Optional[float]` Total number of input and output tokens - `object` - `class Translation: …` - `translated_text: Optional[str]` The translated text in the target language - `class Summarization: …` - `summary: Optional[str]` The summarized version of the input text - `class ImageToText: …` - `description: Optional[str]` - `class ImageTextToText: …` - `description: Optional[str]` - `class MultimodalEmbeddings: …` - `data: Optional[List[List[float]]]` - `shape: Optional[List[float]]` # Finetunes ## List Finetunes `ai.finetunes.list(FinetuneListParams**kwargs) -> FinetuneListResponse` **get** `/accounts/{account_id}/ai/finetunes` Lists all fine-tuning jobs created by the account, including status and metrics. ### Parameters - `account_id: str` ### Returns - `class FinetuneListResponse: …` - `id: str` - `created_at: datetime` - `model: str` - `modified_at: datetime` - `name: str` - `description: Optional[str]` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) finetunes = client.ai.finetunes.list( account_id="023e105f4ecef8ad9ca31a8372d0c353", ) print(finetunes.id) ``` #### Response ```json { "result": { "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", "created_at": "2019-12-27T18:11:19.117Z", "model": "model", "modified_at": "2019-12-27T18:11:19.117Z", "name": "name", "description": "description" }, "success": true } ``` ## Create a new Finetune `ai.finetunes.create(FinetuneCreateParams**kwargs) -> FinetuneCreateResponse` **post** `/accounts/{account_id}/ai/finetunes` Creates a new fine-tuning job for a Workers AI model using custom training data. ### Parameters - `account_id: str` - `model: str` - `name: str` - `description: Optional[str]` - `public: Optional[bool]` ### Returns - `class FinetuneCreateResponse: …` - `id: str` - `created_at: datetime` - `model: str` - `modified_at: datetime` - `name: str` - `public: bool` - `description: Optional[str]` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) finetune = client.ai.finetunes.create( account_id="023e105f4ecef8ad9ca31a8372d0c353", model="model", name="name", ) print(finetune.id) ``` #### Response ```json { "result": { "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", "created_at": "2019-12-27T18:11:19.117Z", "model": "model", "modified_at": "2019-12-27T18:11:19.117Z", "name": "name", "public": true, "description": "description" }, "success": true } ``` ## Domain Types ### Finetune List Response - `class FinetuneListResponse: …` - `id: str` - `created_at: datetime` - `model: str` - `modified_at: datetime` - `name: str` - `description: Optional[str]` ### Finetune Create Response - `class FinetuneCreateResponse: …` - `id: str` - `created_at: datetime` - `model: str` - `modified_at: datetime` - `name: str` - `public: bool` - `description: Optional[str]` # Assets ## Upload a Finetune Asset `ai.finetunes.assets.create(strfinetune_id, AssetCreateParams**kwargs) -> AssetCreateResponse` **post** `/accounts/{account_id}/ai/finetunes/{finetune_id}/finetune-assets` Uploads training data assets for a Workers AI fine-tuning job. ### Parameters - `account_id: str` - `finetune_id: str` - `file: Optional[FileTypes]` - `file_name: Optional[str]` ### Returns - `class AssetCreateResponse: …` - `success: bool` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) asset = client.ai.finetunes.assets.create( finetune_id="bc451aef-f723-4b26-a6b2-901afd2e7a8a", account_id="023e105f4ecef8ad9ca31a8372d0c353", ) print(asset.success) ``` #### Response ```json { "success": true } ``` ## Domain Types ### Asset Create Response - `class AssetCreateResponse: …` - `success: bool` # Public ## List Public Finetunes `ai.finetunes.public.list(PublicListParams**kwargs) -> SyncSinglePage[PublicListResponse]` **get** `/accounts/{account_id}/ai/finetunes/public` Lists publicly available fine-tuned models that can be used with Workers AI. ### Parameters - `account_id: str` - `limit: Optional[float]` Pagination Limit - `offset: Optional[float]` Pagination Offset - `order_by: Optional[str]` Order By Column Name ### Returns - `class PublicListResponse: …` - `id: str` - `created_at: datetime` - `model: str` - `modified_at: datetime` - `name: str` - `public: bool` - `description: Optional[str]` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) page = client.ai.finetunes.public.list( account_id="023e105f4ecef8ad9ca31a8372d0c353", ) page = page.result[0] print(page.id) ``` #### Response ```json { "result": [ { "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", "created_at": "2019-12-27T18:11:19.117Z", "model": "model", "modified_at": "2019-12-27T18:11:19.117Z", "name": "name", "public": true, "description": "description" } ], "success": true } ``` ## Domain Types ### Public List Response - `class PublicListResponse: …` - `id: str` - `created_at: datetime` - `model: str` - `modified_at: datetime` - `name: str` - `public: bool` - `description: Optional[str]` # Authors ## Author Search `ai.authors.list(AuthorListParams**kwargs) -> SyncSinglePage[object]` **get** `/accounts/{account_id}/ai/authors/search` Searches Workers AI models by author or organization name. ### Parameters - `account_id: str` ### Returns - `object` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) page = client.ai.authors.list( account_id="023e105f4ecef8ad9ca31a8372d0c353", ) page = page.result[0] print(page) ``` #### Response ```json { "errors": [ {} ], "messages": [ "string" ], "result": [ {} ], "success": true } ``` # Tasks ## Task Search `ai.tasks.list(TaskListParams**kwargs) -> SyncSinglePage[object]` **get** `/accounts/{account_id}/ai/tasks/search` Searches Workers AI models by task type (e.g., text-generation, embeddings). ### Parameters - `account_id: str` ### Returns - `object` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) page = client.ai.tasks.list( account_id="023e105f4ecef8ad9ca31a8372d0c353", ) page = page.result[0] print(page) ``` #### Response ```json { "errors": [ {} ], "messages": [ "string" ], "result": [ {} ], "success": true } ``` # Models ## Model Search `ai.models.list(ModelListParams**kwargs) -> SyncV4PagePaginationArray[object]` **get** `/accounts/{account_id}/ai/models/search` Searches Workers AI models by name or description. ### Parameters - `account_id: str` - `author: Optional[str]` Filter by Author - `hide_experimental: Optional[bool]` Filter to hide experimental models - `page: Optional[int]` - `per_page: Optional[int]` - `search: Optional[str]` Search - `source: Optional[float]` Filter by Source Id - `task: Optional[str]` Filter by Task Name ### Returns - `object` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) page = client.ai.models.list( account_id="023e105f4ecef8ad9ca31a8372d0c353", ) page = page.result[0] print(page) ``` #### Response ```json { "errors": [ {} ], "messages": [ "string" ], "result": [ {} ], "success": true } ``` # Schema ## Get Model Schema `ai.models.schema.get(SchemaGetParams**kwargs) -> SchemaGetResponse` **get** `/accounts/{account_id}/ai/models/schema` Retrieves the input and output JSON schema definition for a Workers AI model. ### Parameters - `account_id: str` - `model: str` Model Name ### Returns - `class SchemaGetResponse: …` - `input: Input` - `additional_properties: bool` - `description: str` - `type: str` - `output: Output` - `additional_properties: bool` - `description: str` - `type: str` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) schema = client.ai.models.schema.get( account_id="023e105f4ecef8ad9ca31a8372d0c353", model="model", ) print(schema.input) ``` #### Response ```json { "result": { "input": { "additionalProperties": true, "description": "JSON Schema definition for the model's input parameters", "type": "object" }, "output": { "additionalProperties": true, "description": "JSON Schema definition for the model's output format", "type": "object" } }, "success": true } ``` ## Domain Types ### Schema Get Response - `class SchemaGetResponse: …` - `input: Input` - `additional_properties: bool` - `description: str` - `type: str` - `output: Output` - `additional_properties: bool` - `description: str` - `type: str` # To Markdown ## Convert Files into Markdown `ai.to_markdown.transform(ToMarkdownTransformParams**kwargs) -> SyncSinglePage[ToMarkdownTransformResponse]` **post** `/accounts/{account_id}/ai/tomarkdown` Converts uploaded files into Markdown format using Workers AI. ### Parameters - `account_id: str` - `file: File` - `files: SequenceNotStr[FileTypes]` ### Returns - `class ToMarkdownTransformResponse: …` - `data: str` - `format: str` - `mime_type: str` - `name: str` - `tokens: str` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) page = client.ai.to_markdown.transform( account_id="023e105f4ecef8ad9ca31a8372d0c353", file={ "files": [b"Example data"] }, ) page = page.result[0] print(page.data) ``` #### Response ```json { "result": [ { "data": "data", "format": "format", "mimeType": "mimeType", "name": "name", "tokens": "tokens" } ], "success": true } ``` ## Get all converted formats supported `ai.to_markdown.supported(ToMarkdownSupportedParams**kwargs) -> SyncSinglePage[ToMarkdownSupportedResponse]` **get** `/accounts/{account_id}/ai/tomarkdown/supported` Lists all file formats supported for conversion to Markdown. ### Parameters - `account_id: str` ### Returns - `class ToMarkdownSupportedResponse: …` - `extension: str` - `mime_type: str` ### Example ```python import os from cloudflare import Cloudflare client = Cloudflare( api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted ) page = client.ai.to_markdown.supported( account_id="023e105f4ecef8ad9ca31a8372d0c353", ) page = page.result[0] print(page.extension) ``` #### Response ```json { "result": [ { "extension": "extension", "mimeType": "mimeType" } ], "success": true } ``` ## Domain Types ### To Markdown Transform Response - `class ToMarkdownTransformResponse: …` - `data: str` - `format: str` - `mime_type: str` - `name: str` - `tokens: str` ### To Markdown Supported Response - `class ToMarkdownSupportedResponse: …` - `extension: str` - `mime_type: str`