# Captions ## List captions or subtitles `client.Stream.Captions.Get(ctx, identifier, query) (*SinglePage[Caption], error)` **get** `/accounts/{account_id}/stream/{identifier}/captions` Lists the available captions or subtitles for a specific video. ### Parameters - `identifier string` A Cloudflare-generated unique identifier for a media item. - `query CaptionGetParams` - `AccountID param.Field[string]` Identifier. ### Returns - `type Caption struct{…}` - `Generated bool` Whether the caption was generated via AI. - `Label string` The language label displayed in the native language to users. - `Language string` The language tag in BCP 47 format. - `Status CaptionStatus` The status of a generated caption. - `const CaptionStatusReady CaptionStatus = "ready"` - `const CaptionStatusInprogress CaptionStatus = "inprogress"` - `const CaptionStatusError CaptionStatus = "error"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/stream" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.Stream.Captions.Get( context.TODO(), "ea95132c15732412d22c1476fa83f27a", stream.CaptionGetParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": [ { "generated": true, "label": "Türkçe", "language": "tr", "status": "ready" } ] } ``` ## Domain Types ### Caption - `type Caption struct{…}` - `Generated bool` Whether the caption was generated via AI. - `Label string` The language label displayed in the native language to users. - `Language string` The language tag in BCP 47 format. - `Status CaptionStatus` The status of a generated caption. - `const CaptionStatusReady CaptionStatus = "ready"` - `const CaptionStatusInprogress CaptionStatus = "inprogress"` - `const CaptionStatusError CaptionStatus = "error"` # Language ## List captions or subtitles for a provided language `client.Stream.Captions.Language.Get(ctx, identifier, language, query) (*Caption, error)` **get** `/accounts/{account_id}/stream/{identifier}/captions/{language}` Lists the captions or subtitles for provided language. ### Parameters - `identifier string` A Cloudflare-generated unique identifier for a media item. - `language string` The language tag in BCP 47 format. - `query CaptionLanguageGetParams` - `AccountID param.Field[string]` Identifier. ### Returns - `type Caption struct{…}` - `Generated bool` Whether the caption was generated via AI. - `Label string` The language label displayed in the native language to users. - `Language string` The language tag in BCP 47 format. - `Status CaptionStatus` The status of a generated caption. - `const CaptionStatusReady CaptionStatus = "ready"` - `const CaptionStatusInprogress CaptionStatus = "inprogress"` - `const CaptionStatusError CaptionStatus = "error"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/stream" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) caption, err := client.Stream.Captions.Language.Get( context.TODO(), "ea95132c15732412d22c1476fa83f27a", "tr", stream.CaptionLanguageGetParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", caption.Generated) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "generated": true, "label": "Türkçe", "language": "tr", "status": "ready" } } ``` ## Generate captions or subtitles for a provided language via AI `client.Stream.Captions.Language.New(ctx, identifier, language, body) (*Caption, error)` **post** `/accounts/{account_id}/stream/{identifier}/captions/{language}/generate` Generate captions or subtitles for provided language via AI. ### Parameters - `identifier string` A Cloudflare-generated unique identifier for a media item. - `language string` The language tag in BCP 47 format. - `body CaptionLanguageNewParams` - `AccountID param.Field[string]` Identifier. ### Returns - `type Caption struct{…}` - `Generated bool` Whether the caption was generated via AI. - `Label string` The language label displayed in the native language to users. - `Language string` The language tag in BCP 47 format. - `Status CaptionStatus` The status of a generated caption. - `const CaptionStatusReady CaptionStatus = "ready"` - `const CaptionStatusInprogress CaptionStatus = "inprogress"` - `const CaptionStatusError CaptionStatus = "error"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/stream" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) caption, err := client.Stream.Captions.Language.New( context.TODO(), "ea95132c15732412d22c1476fa83f27a", "tr", stream.CaptionLanguageNewParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", caption.Generated) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "generated": true, "label": "Türkçe", "language": "tr", "status": "ready" } } ``` ## Upload captions or subtitles `client.Stream.Captions.Language.Update(ctx, identifier, language, params) (*Caption, error)` **put** `/accounts/{account_id}/stream/{identifier}/captions/{language}` Uploads the caption or subtitle file to the endpoint for a specific BCP47 language. One caption or subtitle file per language is allowed. ### Parameters - `identifier string` A Cloudflare-generated unique identifier for a media item. - `language string` The language tag in BCP 47 format. - `params CaptionLanguageUpdateParams` - `AccountID param.Field[string]` Path param: Identifier. - `File param.Field[string]` Body param: The WebVTT file containing the caption or subtitle content. ### Returns - `type Caption struct{…}` - `Generated bool` Whether the caption was generated via AI. - `Label string` The language label displayed in the native language to users. - `Language string` The language tag in BCP 47 format. - `Status CaptionStatus` The status of a generated caption. - `const CaptionStatusReady CaptionStatus = "ready"` - `const CaptionStatusInprogress CaptionStatus = "inprogress"` - `const CaptionStatusError CaptionStatus = "error"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/stream" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) caption, err := client.Stream.Captions.Language.Update( context.TODO(), "ea95132c15732412d22c1476fa83f27a", "tr", stream.CaptionLanguageUpdateParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), File: cloudflare.F("@/Users/kyle/Desktop/tr.vtt"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", caption.Generated) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "generated": true, "label": "Türkçe", "language": "tr", "status": "ready" } } ``` ## Delete captions or subtitles `client.Stream.Captions.Language.Delete(ctx, identifier, language, body) (*string, error)` **delete** `/accounts/{account_id}/stream/{identifier}/captions/{language}` Removes the captions or subtitles from a video. ### Parameters - `identifier string` A Cloudflare-generated unique identifier for a media item. - `language string` The language tag in BCP 47 format. - `body CaptionLanguageDeleteParams` - `AccountID param.Field[string]` Identifier. ### Returns - `type CaptionLanguageDeleteResponseEnvelopeResult string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/stream" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) language, err := client.Stream.Captions.Language.Delete( context.TODO(), "ea95132c15732412d22c1476fa83f27a", "tr", stream.CaptionLanguageDeleteParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", language) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": "" } ``` # Vtt ## Return WebVTT captions for a provided language `client.Stream.Captions.Language.Vtt.Get(ctx, identifier, language, query) (*string, error)` **get** `/accounts/{account_id}/stream/{identifier}/captions/{language}/vtt` Return WebVTT captions for a provided language. ### Parameters - `identifier string` A Cloudflare-generated unique identifier for a media item. - `language string` The language tag in BCP 47 format. - `query CaptionLanguageVttGetParams` - `AccountID param.Field[string]` Identifier. ### Returns - `type CaptionLanguageVttGetResponse string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/stream" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) vtt, err := client.Stream.Captions.Language.Vtt.Get( context.TODO(), "ea95132c15732412d22c1476fa83f27a", "tr", stream.CaptionLanguageVttGetParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", vtt) } ```