# AI ## 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](https://developers.cloudflare.com/workers-ai/models/). ### Parameters - `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` ### Returns - `AIRunResponse = Array | Uploadable | Audio | 12 more` An array of classification results for the input text - `Array` - `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?: string` The generated audio in MP3 format, base64-encoded - `Uploadable` - `TextEmbeddings` - `data?: Array>` Embeddings of the requested text values - `shape?: Array` - `AutomaticSpeechRecognition` - `text: string` The transcription - `vtt?: string` - `word_count?: number` - `words?: Array` - `end?: number` The ending second when the word completes - `start?: number` The second this word begins in the recording - `word?: string` - `Array` - `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` - `box?: Box` 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: string` The generated text response from the model - `tool_calls?: Array` 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` 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?: string` The translated text in the target language - `Summarization` - `summary?: string` The summarized version of the input text - `ImageToText` - `description?: string` - `ImageTextToText` - `description?: string` - `MultimodalEmbeddings` - `data?: Array>` - `shape?: Array` ### Example ```node 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); ``` #### Response ```json { "result": [ { "label": "label", "score": 0 } ] } ``` ## Domain Types ### AI Run Response - `AIRunResponse = Array | Uploadable | Audio | 12 more` An array of classification results for the input text - `Array` - `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?: string` The generated audio in MP3 format, base64-encoded - `Uploadable` - `TextEmbeddings` - `data?: Array>` Embeddings of the requested text values - `shape?: Array` - `AutomaticSpeechRecognition` - `text: string` The transcription - `vtt?: string` - `word_count?: number` - `words?: Array` - `end?: number` The ending second when the word completes - `start?: number` The second this word begins in the recording - `word?: string` - `Array` - `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` - `box?: Box` 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: string` The generated text response from the model - `tool_calls?: Array` 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` 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?: string` The translated text in the target language - `Summarization` - `summary?: string` The summarized version of the input text - `ImageToText` - `description?: string` - `ImageTextToText` - `description?: string` - `MultimodalEmbeddings` - `data?: Array>` - `shape?: Array` # Finetunes ## List Finetunes `client.ai.finetunes.list(FinetuneListParamsparams, RequestOptionsoptions?): FinetuneListResponse` **get** `/accounts/{account_id}/ai/finetunes` Lists all fine-tuning jobs created by the account, including status and metrics. ### Parameters - `params: FinetuneListParams` - `account_id: string` ### Returns - `FinetuneListResponse` - `id: string` - `created_at: string` - `model: string` - `modified_at: string` - `name: string` - `description?: string` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const finetunes = await client.ai.finetunes.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(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 `client.ai.finetunes.create(FinetuneCreateParamsparams, RequestOptionsoptions?): FinetuneCreateResponse` **post** `/accounts/{account_id}/ai/finetunes` Creates a new fine-tuning job for a Workers AI model using custom training data. ### Parameters - `params: FinetuneCreateParams` - `account_id: string` Path param - `model: string` Body param - `name: string` Body param - `description?: string` Body param - `_public?: boolean` Body param ### Returns - `FinetuneCreateResponse` - `id: string` - `created_at: string` - `model: string` - `modified_at: string` - `name: string` - `public: boolean` - `description?: string` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const finetune = await client.ai.finetunes.create({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', model: 'model', name: 'name', }); console.log(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 - `FinetuneListResponse` - `id: string` - `created_at: string` - `model: string` - `modified_at: string` - `name: string` - `description?: string` ### Finetune Create Response - `FinetuneCreateResponse` - `id: string` - `created_at: string` - `model: string` - `modified_at: string` - `name: string` - `public: boolean` - `description?: string` # Assets ## Upload a Finetune Asset `client.ai.finetunes.assets.create(stringfinetuneId, AssetCreateParamsparams, RequestOptionsoptions?): AssetCreateResponse` **post** `/accounts/{account_id}/ai/finetunes/{finetune_id}/finetune-assets` Uploads training data assets for a Workers AI fine-tuning job. ### Parameters - `finetuneId: string` - `params: AssetCreateParams` - `account_id: string` Path param - `file?: Uploadable` Body param - `file_name?: string` Body param ### Returns - `AssetCreateResponse` - `success: boolean` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const asset = await client.ai.finetunes.assets.create('bc451aef-f723-4b26-a6b2-901afd2e7a8a', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(asset.success); ``` #### Response ```json { "success": true } ``` ## Domain Types ### Asset Create Response - `AssetCreateResponse` - `success: boolean` # Public ## List Public Finetunes `client.ai.finetunes.public.list(PublicListParamsparams, RequestOptionsoptions?): SinglePage` **get** `/accounts/{account_id}/ai/finetunes/public` Lists publicly available fine-tuned models that can be used with Workers AI. ### Parameters - `params: PublicListParams` - `account_id: string` Path param - `limit?: number` Query param: Pagination Limit - `offset?: number` Query param: Pagination Offset - `orderBy?: string` Query param: Order By Column Name ### Returns - `PublicListResponse` - `id: string` - `created_at: string` - `model: string` - `modified_at: string` - `name: string` - `public: boolean` - `description?: string` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const publicListResponse of client.ai.finetunes.public.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', })) { console.log(publicListResponse.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 - `PublicListResponse` - `id: string` - `created_at: string` - `model: string` - `modified_at: string` - `name: string` - `public: boolean` - `description?: string` # Authors ## Author Search `client.ai.authors.list(AuthorListParamsparams, RequestOptionsoptions?): SinglePage` **get** `/accounts/{account_id}/ai/authors/search` Searches Workers AI models by author or organization name. ### Parameters - `params: AuthorListParams` - `account_id: string` ### Returns - `AuthorListResponse = unknown` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const authorListResponse of client.ai.authors.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', })) { console.log(authorListResponse); } ``` #### Response ```json { "errors": [ {} ], "messages": [ "string" ], "result": [ {} ], "success": true } ``` ## Domain Types ### Author List Response - `AuthorListResponse = unknown` # Tasks ## Task Search `client.ai.tasks.list(TaskListParamsparams, RequestOptionsoptions?): SinglePage` **get** `/accounts/{account_id}/ai/tasks/search` Searches Workers AI models by task type (e.g., text-generation, embeddings). ### Parameters - `params: TaskListParams` - `account_id: string` ### Returns - `TaskListResponse = unknown` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const taskListResponse of client.ai.tasks.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', })) { console.log(taskListResponse); } ``` #### Response ```json { "errors": [ {} ], "messages": [ "string" ], "result": [ {} ], "success": true } ``` ## Domain Types ### Task List Response - `TaskListResponse = unknown` # Models ## Model Search `client.ai.models.list(ModelListParamsparams, RequestOptionsoptions?): V4PagePaginationArray` **get** `/accounts/{account_id}/ai/models/search` Searches Workers AI models by name or description. ### Parameters - `params: ModelListParams` - `account_id: string` Path param - `author?: string` Query param: Filter by Author - `hide_experimental?: boolean` Query param: Filter to hide experimental models - `page?: number` Query param - `per_page?: number` Query param - `search?: string` Query param: Search - `source?: number` Query param: Filter by Source Id - `task?: string` Query param: Filter by Task Name ### Returns - `ModelListResponse = unknown` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const modelListResponse of client.ai.models.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', })) { console.log(modelListResponse); } ``` #### Response ```json { "errors": [ {} ], "messages": [ "string" ], "result": [ {} ], "success": true } ``` ## Domain Types ### Model List Response - `ModelListResponse = unknown` # Schema ## Get Model Schema `client.ai.models.schema.get(SchemaGetParamsparams, RequestOptionsoptions?): SchemaGetResponse` **get** `/accounts/{account_id}/ai/models/schema` Retrieves the input and output JSON schema definition for a Workers AI model. ### Parameters - `params: SchemaGetParams` - `account_id: string` Path param - `model: string` Query param: Model Name ### Returns - `SchemaGetResponse` - `input: Input` - `additionalProperties: boolean` - `description: string` - `type: string` - `output: Output` - `additionalProperties: boolean` - `description: string` - `type: string` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const schema = await client.ai.models.schema.get({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', model: 'model', }); console.log(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 - `SchemaGetResponse` - `input: Input` - `additionalProperties: boolean` - `description: string` - `type: string` - `output: Output` - `additionalProperties: boolean` - `description: string` - `type: string` # To Markdown ## Convert Files into Markdown `client.ai.toMarkdown.transform(ToMarkdownTransformParamsparams, RequestOptionsoptions?): SinglePage` **post** `/accounts/{account_id}/ai/tomarkdown` Converts uploaded files into Markdown format using Workers AI. ### Parameters - `params: ToMarkdownTransformParams` - `account_id: string` Path param - `file: File` Body param - `files: Array` ### Returns - `ToMarkdownTransformResponse` - `data: string` - `format: string` - `mimeType: string` - `name: string` - `tokens: string` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const toMarkdownTransformResponse of client.ai.toMarkdown.transform({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', file: { files: [fs.createReadStream('path/to/file')] }, })) { console.log(toMarkdownTransformResponse.data); } ``` #### Response ```json { "result": [ { "data": "data", "format": "format", "mimeType": "mimeType", "name": "name", "tokens": "tokens" } ], "success": true } ``` ## Get all converted formats supported `client.ai.toMarkdown.supported(ToMarkdownSupportedParamsparams, RequestOptionsoptions?): SinglePage` **get** `/accounts/{account_id}/ai/tomarkdown/supported` Lists all file formats supported for conversion to Markdown. ### Parameters - `params: ToMarkdownSupportedParams` - `account_id: string` ### Returns - `ToMarkdownSupportedResponse` - `extension: string` - `mimeType: string` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const toMarkdownSupportedResponse of client.ai.toMarkdown.supported({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', })) { console.log(toMarkdownSupportedResponse.extension); } ``` #### Response ```json { "result": [ { "extension": "extension", "mimeType": "mimeType" } ], "success": true } ``` ## Domain Types ### To Markdown Transform Response - `ToMarkdownTransformResponse` - `data: string` - `format: string` - `mimeType: string` - `name: string` - `tokens: string` ### To Markdown Supported Response - `ToMarkdownSupportedResponse` - `extension: string` - `mimeType: string`