# AI ## Execute AI model `client.AI.Run(ctx, modelName, params) (*AIRunResponseUnion, error)` **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` - `params AIRunParams` - `AccountID param.Field[string]` Path param - `Text param.Field[string]` Body param: The text that you want to classify ### Returns - `type AIRunResponseUnion interface{…}` An array of classification results for the input text - `type AIRunResponseTextClassification []AIRunResponseTextClassificationItem` An array of classification results for the input text - `Label string` The classification label assigned to the text (e.g., 'POSITIVE' or 'NEGATIVE') - `Score float64` Confidence score indicating the likelihood that the text belongs to the specified label - `UnionString` - `type AIRunResponseAudio struct{…}` - `Audio string` The generated audio in MP3 format, base64-encoded - `UnionString` - `type AIRunResponseTextEmbeddings struct{…}` - `Data [][]float64` Embeddings of the requested text values - `Shape []float64` - `type AIRunResponseAutomaticSpeechRecognition struct{…}` - `Text string` The transcription - `Vtt string` - `WordCount float64` - `Words []AIRunResponseAutomaticSpeechRecognitionWord` - `End float64` The ending second when the word completes - `Start float64` The second this word begins in the recording - `Word string` - `type AIRunResponseImageClassification []AIRunResponseImageClassificationItem` - `Label string` The predicted category or class for the input image based on analysis - `Score float64` A confidence value, between 0 and 1, indicating how certain the model is about the predicted label - `type AIRunResponseObjectDetection []AIRunResponseObjectDetectionItem` An array of detected objects within the input image - `Box AIRunResponseObjectDetectionBox` Coordinates defining the bounding box around the detected object - `Xmax float64` The x-coordinate of the bottom-right corner of the bounding box - `Xmin float64` The x-coordinate of the top-left corner of the bounding box - `Ymax float64` The y-coordinate of the bottom-right corner of the bounding box - `Ymin float64` The y-coordinate of the top-left corner of the bounding box - `Label string` The class label or name of the detected object - `Score float64` Confidence score indicating the likelihood that the detection is correct - `type AIRunResponseObject struct{…}` - `Response string` The generated text response from the model - `ToolCalls []AIRunResponseObjectToolCall` 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 AIRunResponseObjectUsage` Usage statistics for the inference request - `CompletionTokens float64` Total number of tokens in output - `PromptTokens float64` Total number of tokens in input - `TotalTokens float64` Total number of input and output tokens - `UnionString` - `type AIRunResponseTranslation struct{…}` - `TranslatedText string` The translated text in the target language - `type AIRunResponseSummarization struct{…}` - `Summary string` The summarized version of the input text - `type AIRunResponseImageToText struct{…}` - `Description string` - `type AIRunResponseImageTextToText struct{…}` - `Description string` - `type AIRunResponseMultimodalEmbeddings struct{…}` - `Data [][]float64` - `Shape []float64` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.AI.Run( context.TODO(), "model_name", ai.AIRunParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response) } ``` #### Response ```json { "result": [ { "label": "label", "score": 0 } ] } ``` # Finetunes ## List Finetunes `client.AI.Finetunes.List(ctx, query) (*FinetuneListResponse, error)` **get** `/accounts/{account_id}/ai/finetunes` Lists all fine-tuning jobs created by the account, including status and metrics. ### Parameters - `query FinetuneListParams` - `AccountID param.Field[string]` ### Returns - `type FinetuneListResponse struct{…}` - `ID string` - `CreatedAt Time` - `Model string` - `ModifiedAt Time` - `Name string` - `Description string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) finetunes, err := client.AI.Finetunes.List(context.TODO(), ai.FinetuneListParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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.New(ctx, params) (*FinetuneNewResponse, error)` **post** `/accounts/{account_id}/ai/finetunes` Creates a new fine-tuning job for a Workers AI model using custom training data. ### Parameters - `params FinetuneNewParams` - `AccountID param.Field[string]` Path param - `Model param.Field[string]` Body param - `Name param.Field[string]` Body param - `Description param.Field[string]` Body param - `Public param.Field[bool]` Body param ### Returns - `type FinetuneNewResponse struct{…}` - `ID string` - `CreatedAt Time` - `Model string` - `ModifiedAt Time` - `Name string` - `Public bool` - `Description string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) finetune, err := client.AI.Finetunes.New(context.TODO(), ai.FinetuneNewParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Model: cloudflare.F("model"), Name: cloudflare.F("name"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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 } ``` # Assets ## Upload a Finetune Asset `client.AI.Finetunes.Assets.New(ctx, finetuneID, params) (*FinetuneAssetNewResponse, error)` **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 FinetuneAssetNewParams` - `AccountID param.Field[string]` Path param - `File param.Field[Reader]` Body param - `FileName param.Field[string]` Body param ### Returns - `type FinetuneAssetNewResponse struct{…}` - `Success bool` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) asset, err := client.AI.Finetunes.Assets.New( context.TODO(), "bc451aef-f723-4b26-a6b2-901afd2e7a8a", ai.FinetuneAssetNewParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", asset.Success) } ``` #### Response ```json { "success": true } ``` # Public ## List Public Finetunes `client.AI.Finetunes.Public.List(ctx, params) (*SinglePage[FinetunePublicListResponse], error)` **get** `/accounts/{account_id}/ai/finetunes/public` Lists publicly available fine-tuned models that can be used with Workers AI. ### Parameters - `params FinetunePublicListParams` - `AccountID param.Field[string]` Path param - `Limit param.Field[float64]` Query param: Pagination Limit - `Offset param.Field[float64]` Query param: Pagination Offset - `OrderBy param.Field[string]` Query param: Order By Column Name ### Returns - `type FinetunePublicListResponse struct{…}` - `ID string` - `CreatedAt Time` - `Model string` - `ModifiedAt Time` - `Name string` - `Public bool` - `Description string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.AI.Finetunes.Public.List(context.TODO(), ai.FinetunePublicListParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### 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 } ``` # Authors ## Author Search `client.AI.Authors.List(ctx, query) (*SinglePage[AuthorListResponse], error)` **get** `/accounts/{account_id}/ai/authors/search` Searches Workers AI models by author or organization name. ### Parameters - `query AuthorListParams` - `AccountID param.Field[string]` ### Returns - `type AuthorListResponse interface{…}` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.AI.Authors.List(context.TODO(), ai.AuthorListParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ {} ], "messages": [ "string" ], "result": [ {} ], "success": true } ``` # Tasks ## Task Search `client.AI.Tasks.List(ctx, query) (*SinglePage[TaskListResponse], error)` **get** `/accounts/{account_id}/ai/tasks/search` Searches Workers AI models by task type (e.g., text-generation, embeddings). ### Parameters - `query TaskListParams` - `AccountID param.Field[string]` ### Returns - `type TaskListResponse interface{…}` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.AI.Tasks.List(context.TODO(), ai.TaskListParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ {} ], "messages": [ "string" ], "result": [ {} ], "success": true } ``` # Models ## Model Search `client.AI.Models.List(ctx, params) (*V4PagePaginationArray[ModelListResponse], error)` **get** `/accounts/{account_id}/ai/models/search` Searches Workers AI models by name or description. ### Parameters - `params ModelListParams` - `AccountID param.Field[string]` Path param - `Author param.Field[string]` Query param: Filter by Author - `HideExperimental param.Field[bool]` Query param: Filter to hide experimental models - `Page param.Field[int64]` Query param - `PerPage param.Field[int64]` Query param - `Search param.Field[string]` Query param: Search - `Source param.Field[float64]` Query param: Filter by Source Id - `Task param.Field[string]` Query param: Filter by Task Name ### Returns - `type ModelListResponse interface{…}` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.AI.Models.List(context.TODO(), ai.ModelListParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ {} ], "messages": [ "string" ], "result": [ {} ], "success": true } ``` # Schema ## Get Model Schema `client.AI.Models.Schema.Get(ctx, params) (*ModelSchemaGetResponse, error)` **get** `/accounts/{account_id}/ai/models/schema` Retrieves the input and output JSON schema definition for a Workers AI model. ### Parameters - `params ModelSchemaGetParams` - `AccountID param.Field[string]` Path param - `Model param.Field[string]` Query param: Model Name ### Returns - `type ModelSchemaGetResponse struct{…}` - `Input ModelSchemaGetResponseInput` - `AdditionalProperties bool` - `Description string` - `Type string` - `Output ModelSchemaGetResponseOutput` - `AdditionalProperties bool` - `Description string` - `Type string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) schema, err := client.AI.Models.Schema.Get(context.TODO(), ai.ModelSchemaGetParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Model: cloudflare.F("model"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", 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 } ``` # To Markdown ## Convert Files into Markdown `client.AI.ToMarkdown.Transform(ctx, params) (*SinglePage[ToMarkdownTransformResponse], error)` **post** `/accounts/{account_id}/ai/tomarkdown` Converts uploaded files into Markdown format using Workers AI. ### Parameters - `params ToMarkdownTransformParams` - `AccountID param.Field[string]` Path param - `File param.Field[ToMarkdownTransformParamsFile]` Body param - `Files []Reader` ### Returns - `type ToMarkdownTransformResponse struct{…}` - `Data string` - `Format string` - `MimeType string` - `Name string` - `Tokens string` ### Example ```go package main import ( "bytes" "context" "fmt" "io" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.AI.ToMarkdown.Transform(context.TODO(), ai.ToMarkdownTransformParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), File: ai.ToMarkdownTransformParamsFile{ Files: cloudflare.F([]io.Reader{io.Reader(bytes.NewBuffer([]byte("Example data")))}), }, }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "result": [ { "data": "data", "format": "format", "mimeType": "mimeType", "name": "name", "tokens": "tokens" } ], "success": true } ``` ## Get all converted formats supported `client.AI.ToMarkdown.Supported(ctx, query) (*SinglePage[ToMarkdownSupportedResponse], error)` **get** `/accounts/{account_id}/ai/tomarkdown/supported` Lists all file formats supported for conversion to Markdown. ### Parameters - `query ToMarkdownSupportedParams` - `AccountID param.Field[string]` ### Returns - `type ToMarkdownSupportedResponse struct{…}` - `Extension string` - `MimeType string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/ai" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.AI.ToMarkdown.Supported(context.TODO(), ai.ToMarkdownSupportedParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "result": [ { "extension": "extension", "mimeType": "mimeType" } ], "success": true } ```