Go SDK
github.com/transcodely/transcodely-go is the official Go SDK for the Transcodely API. It requires Go 1.23+, builds on connectrpc.com/connect v1, and ships a custom JSON codec so the SDK speaks the API’s snake_case + lowercase-enum wire format identically to the TypeScript and Python SDKs. The SDK is pre-1.0 — breaking changes are possible on minor bumps until 1.0.0.
Install
Add the module to your project with go get:
go get github.com/transcodely/transcodely-goImport it as the transcodely package — the last segment of the module path:
import "github.com/transcodely/transcodely-go"Authenticate
transcodely.New takes the API key as the first positional argument followed by zero or more functional options. Pass os.Getenv("TRANSCODELY_API_KEY") so the calling code stays in control of secret loading — the SDK does not read environment variables itself.
package main
import (
"log"
"os"
"github.com/transcodely/transcodely-go"
)
func main() {
client, err := transcodely.New(os.Getenv("TRANSCODELY_API_KEY"))
if err != nil {
log.Fatal(err)
}
_ = client
}transcodely.New returns an error only on invalid configuration (e.g. an empty API key).
Create your first job
Resource namespaces hang off the root client (client.Jobs, client.Videos, …). Every RPC takes a context.Context and a typed *Params struct. Optional *string fields use proto.String(...) from google.golang.org/protobuf/proto.
package main
import (
"context"
"log"
"os"
"github.com/transcodely/transcodely-go"
"google.golang.org/protobuf/proto"
)
func main() {
client, err := transcodely.New(os.Getenv("TRANSCODELY_API_KEY"))
if err != nil {
log.Fatal(err)
}
job, err := client.Jobs.Create(context.Background(), &transcodely.JobCreateParams{
InputUrl: "https://www.transcodely.com/samples/transcodely-sample-30s.mp4",
Managed: proto.Bool(true),
Outputs: []*transcodely.OutputSpec{{
Type: transcodely.OutputFormatHLS,
Video: []*transcodely.VideoVariant{
{Codec: transcodely.VideoCodecH264, Resolution: transcodely.Resolution1080P, Quality: transcodely.QualityTierStandard},
{Codec: transcodely.VideoCodecH264, Resolution: transcodely.Resolution720P, Quality: transcodely.QualityTierStandard},
},
}},
})
if err != nil {
log.Fatal(err)
}
log.Printf("created %s in status %s", job.GetId(), job.GetStatus())
}It points at a public sample clip and delivers to Transcodely hosting, so it runs before you own any storage. It asks for standard quality, which the free tier includes; only premium needs a payment method. Generated message accessors (job.GetId(), job.GetStatus()) are the safe way to read fields — they handle nil pointers correctly. Field names follow the proto convention (InputUrl, not InputURL).
Watch a job to completion
client.Jobs.Watch returns a *Stream[T] that auto-reconnects on transient network failures and filters HEARTBEAT events by default.
import (
"context"
"log"
"time"
"github.com/transcodely/transcodely-go"
)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
stream := client.Jobs.Watch(ctx, job.GetId())
defer stream.Close()
for stream.Next() {
event := stream.Current()
j := event.GetJob()
log.Printf("[%s] progress=%d%%", j.GetStatus(), j.GetProgress())
if j.GetStatus() == transcodely.JobStatusCompleted ||
j.GetStatus() == transcodely.JobStatusFailed ||
j.GetStatus() == transcodely.JobStatusCanceled {
break
}
}
if err := stream.Err(); err != nil {
log.Fatal(err)
}Cancel the parent context.Context (or call stream.Close()) to terminate the stream from your side. Every reconnect re-emits a SNAPSHOT event so resuming is idempotent on the consumer.
List with auto-pagination
List methods return a *Iter[T]. Drive it with Next() / Current() / Err(), and always defer iter.Close() to release the underlying HTTP connection.
iter := client.Jobs.List(ctx, &transcodely.JobListParams{
Pagination: &transcodely.PaginationRequest{Limit: 50},
})
defer iter.Close()
for iter.Next() {
job := iter.Current()
log.Printf("%s %s", job.GetId(), job.GetStatus())
}
if err := iter.Err(); err != nil {
log.Fatal(err)
}The iterator stops cleanly when the API returns an empty next_cursor. See Pagination for cursor semantics.
Generate insights from existing captions
A hosted video that already has AI captions can get AI insights without transcribing again. Only the insights fee is billed, €0.05 per video plus €0.005 per minute of source, and only when the insights become ready. The call returns the TranscriptInsights entry in pending; pass the language only when the video has more than one AI caption track. See GenerateInsights.
ins, err := client.Videos.GenerateInsights(ctx, &transcodely.VideoGenerateInsightsParams{
Id: "vid_a1b2c3d4e5f6g7",
Language: proto.String("eng"), // only when the video has several AI caption tracks
})
if err != nil {
log.Fatal(err)
}
log.Println(ins.GetId(), ins.GetStatus()) // ins_..., pendingThe entry also appears on video.GetInsights(). The video.insights.ready and video.insights.failed webhook events (transcodely.EventTypeVideoInsightsReady and transcodely.EventTypeVideoInsightsFailed) carry the entry itself, not a Video: read it with event.Insights(), which returns (*TranscriptInsights, bool).
Your prices
client.Apps.GetPricing lists every chargeable item with the EUR rate your app pays, a custom flag where your account has its own rate, and the public list price beside it. Pass "" to price the API key’s own app. See Custom pricing and GetPricing.
pricing, err := client.Apps.GetPricing(ctx, "")
if err != nil {
log.Fatal(err)
}
for _, e := range pricing.Entries {
if e.Custom && e.BasePrice != nil {
log.Printf("%s: %.6f %s (list %.6f)", e.Label, e.GetBasePrice(), pricing.Currency, e.GetListBasePrice())
}
}Prices are fixed when a job is created, so a rate change applies to jobs created after it.
Handle typed errors
Every concrete error implements the transcodely.Error interface (with ErrorCode() and RequestID() methods). Match types with errors.As:
import (
"errors"
"log"
"time"
"github.com/transcodely/transcodely-go"
)
job, err := client.Jobs.Get(ctx, "job_does_not_exist")
if err != nil {
var notFound *transcodely.NotFoundError
var invalid *transcodely.InvalidRequestError
var rate *transcodely.RateLimitError
var auth *transcodely.AuthenticationError
switch {
case errors.As(err, ¬Found):
log.Printf("not found, request_id=%s", notFound.RequestID())
case errors.As(err, &invalid):
for _, v := range invalid.Errors() {
log.Printf("%s: %s", v.Field, v.Description)
}
case errors.As(err, &rate):
time.Sleep(rate.RetryAfter)
case errors.As(err, &auth):
log.Fatal("bad API key")
default:
log.Fatal(err)
}
}
_ = jobEvery error carries ErrorCode(), HTTPStatus(), and RequestID(). See Errors for the full hierarchy.
Override idempotency
Create mutations auto-generate a UUID v4 Idempotency-Key so retrying within the same process is safe. For cross-process safety (queue workers, cron jobs), set IdempotencyKey on the params struct:
import "google.golang.org/protobuf/proto"
params := &transcodely.JobCreateParams{
InputUrl: "...",
OutputOriginId: proto.String("ori_x9y8z7w6v5"),
Outputs: []*transcodely.OutputSpec{/* ... */},
IdempotencyKey: proto.String("transcode_asset_42_v1"),
}
job, err := client.Jobs.Create(ctx, params)To disable auto-injection across the entire client (e.g. when targeting a server that doesn’t yet support idempotency keys), use WithAutoIdempotency(false) at construction. See Idempotency for replay semantics.
Request IDs
Every response and error carries a req_* request ID that Transcodely support can use to trace a call. The Go SDK surfaces it on typed errors — call RequestID() on any transcodely.Error (see Handle typed errors):
job, err := client.Jobs.Get(ctx, "job_a1b2c3d4e5f6")
if err != nil {
var apiErr transcodely.Error
if errors.As(err, &apiErr) {
log.Printf("request failed, request_id=%s", apiErr.RequestID())
}
}
_ = jobUnlike the TypeScript and Python SDKs, the Go client does not expose a LastRequestID accessor for successful responses — read the ID from the error when a call fails.
Configuration
Pass options to transcodely.New:
| Option | Default | Notes |
|---|---|---|
WithBaseURL(url) | https://api.transcodely.com | Override for staging or self-hosted |
WithHTTPClient(c) | &http.Client{Timeout: 60s} | Inject a custom transport |
WithMaxRetries(n) | 2 | Retries on network errors, 5xx, 429, 503 with jittered backoff |
WithUserAgent(ua) | — | Appended to the default transcodely-go/<version> |
WithAPIVersion(v) | calendar version baked at SDK build time | Sent as Transcodely-Version |
WithAutoIdempotency(b) | true | Auto-generate UUIDv4 Idempotency-Key on Create mutations |
Note that the Go SDK defaults MaxRetries to 2, where the TypeScript and Python SDKs default to 3. All three back off with jitter and honor the server’s Retry-After header.
client, err := transcodely.New(
os.Getenv("TRANSCODELY_API_KEY"),
transcodely.WithMaxRetries(5),
transcodely.WithUserAgent("ingest-worker/2.3"),
transcodely.WithHTTPClient(&http.Client{Timeout: 90 * time.Second}),
)Where to go next
- API Reference — the full RPC surface.
- Webhook Integration — verify signed deliveries and handle events with
transcodely.ConstructEvent. - Errors — the typed error hierarchy in one place.
- Pagination — cursor model and auto-paging idioms.
- Idempotency — when and how to set your own key.
- SDK source on GitHub — full source and six runnable examples in
examples/(01_create_job,02_watch_job,03_pagination,04_error_handling,05_create_r2_origin,07_create_s3_compatible_origin).