Go SDK
github.com/formfeed-dev/formfeed-go is the Go client for the REST API, for Go 1.26 and later, and it needs nothing but the standard library. It behaves exactly like the TypeScript SDK: 429, 503 and network errors are retried, every render carries an Idempotency-Key, and API problems come back as a *formfeed.Error. Every call takes a context.Context first, lists are iterators, and webhook deliveries are checked by an http.Handler.
go get github.com/formfeed-dev/formfeed-go
The package is called formfeed, which the module's path does not say, so import it under that name:
import formfeed "github.com/formfeed-dev/formfeed-go"
Set up a client
client := formfeed.NewClient(os.Getenv("FORMFEED_API_KEY"))
A client is safe for concurrent use: make one and share it. Options follow the key:
| Option | Default | Notes |
|---|---|---|
WithRegion(region) | "eu" | "eu" (https://api-eu.formfeed.dev/v1) or "us" (https://api-us.formfeed.dev/v1) |
WithBaseURL(url) | region host | Full URL including /v1, used instead of the region's host. You need it only for an address other than the public API, such as one our support gives you. Wins over WithRegion. |
WithHTTPClient(httpClient) | the SDK's own | An *http.Client with your transport and time limits; WithTimeout then has no effect. |
WithMaxRetries(n) | 3 | Retries on 429, 503 and network errors; 0 turns retrying off. |
WithTimeout(d) | 120 * time.Second | Per request of the SDK's own HTTP client, the download of the body included; 0 sets no limit. A request that times out counts as a network error and is retried. |
WithHeader(name, value) | none | Sent with every request, after the SDK's own headers, which it replaces. |
WithSleep(fn), WithJitter(fn) | timers, random | How the client waits between retries and polls, and the random part of a retry's wait; for tests. |
NewClient returns no error. A client without a key, or with a region that is neither eu nor us, answers every call with a *formfeed.Error of the code invalid_request and sends nothing.
Requests are structs with the fields of the API reference: formfeed.RenderRequest, formfeed.BatchRequest and one per PDF tool. A field left at its zero value is not sent, and the API applies its default; where zero is a value of its own, the field is a pointer, which formfeed.Ptr sets (Dedupe: formfeed.Ptr(false)). Extra, a map[string]any, sends members this release of the SDK does not know yet. Answers are structs too: render.DownloadURL, render.PageCount, render.Units, and render.Raw with the whole answer, fields of later API versions included.
Contexts
Every call takes a context.Context first. When it is cancelled or its deadline passes, the call ends at once, a wait between retries or polls included, and returns the context's own error (context.Canceled, context.DeadlineExceeded) rather than a *formfeed.Error:
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
_, err := client.Renders.Create(ctx, formfeed.RenderRequest{Template: "invoice", Data: data})
if errors.Is(err, context.DeadlineExceeded) {
log.Fatal("no answer within 30 seconds")
}
Retries and idempotency
The rule is the one of the TypeScript SDK: 429, 503 and network errors are sent again up to WithMaxRetries times, after the seconds of Retry-After, else 0.5 s, 1 s, 2 s and so on plus up to 0.25 s of jitter, never more than 30 s. Renders.Create, Renders.Batch, every PDF tool but Info, and Einvoices.Validate send an Idempotency-Key, a random one unless you pass formfeed.WithIdempotencyKey(key) as the last argument; its retries reuse it, so the API renders and charges once. To retry safely across processes, pass a key of your own, such as order-8812-invoice. See Idempotency.
Render
invoice := map[string]any{
"number": "2026-0042",
"lines": []map[string]any{
{"description": "Consulting", "qty": 8, "price": 120},
},
}
render, err := client.Renders.Create(ctx, formfeed.RenderRequest{
Template: "invoice",
Data: map[string]any{"invoice": invoice},
Filename: "invoice-2026-0042.pdf",
}, formfeed.WithIdempotencyKey("order-8812-invoice"))
if err != nil {
log.Fatal(err)
}
// a sync render still running after 60 seconds comes back queued; wait for it
if render.Status != "succeeded" {
render, err = client.Renders.WaitFor(ctx, render.ID)
if err != nil {
log.Fatal(err)
}
}
fmt.Println(render.DownloadURL, render.PageCount, render.Units)
if _, err := client.Renders.DownloadFile(ctx, render, "invoice.pdf"); err != nil {
log.Fatal(err)
}
formfeed.RenderRequest is the body of POST /renders: Template, or HTML with Engine, or URL, or Markdown; Version; Data; Output; Settings; Locale; Filename; ExpiresIn; Access; Mode; WebhookURL and WebhookSecret; Meta; Region; Dedupe; CanaryKey; ValidateData; Post; Storage. Data, Settings, Meta and Post are of the type map[string]any. The call option, the idempotency key, is the SDK's own.
A failed render comes back as a *formfeed.Error, whose Problem.RenderID names the render. A sync render that has no answer after 60 seconds is not an error: it comes back with the status queued or rendering and finishes in the background (the automatic fallback), so check Status before you download. client.Renders.Get(ctx, id) fetches a render again, with a fresh download link. Download(ctx, render) returns the file's bytes, DownloadTo(ctx, render, w) streams them into an io.Writer and DownloadFile(ctx, render, path) writes them to a file, which a failed download does not leave behind; all three follow the signed link without the API key, and answer not_ready while the render has no output.
Async renders and batches
queued, err := client.Renders.Create(ctx, formfeed.RenderRequest{Template: "annual-report", Data: payload, Mode: "async"})
if err != nil {
log.Fatal(err)
}
done, err := client.Renders.WaitFor(ctx, queued.ID, formfeed.WithWaitTimeout(2*time.Minute))
if err != nil {
log.Fatal(err)
}
fmt.Println(done.ID, done.Status)
items := make([]formfeed.RenderRequest, 0, len(orders))
for _, order := range orders {
items = append(items, formfeed.RenderRequest{
Data: map[string]any{"invoice": order},
Filename: fmt.Sprintf("%v.pdf", order["number"]),
Meta: map[string]any{"order_id": order["id"]},
})
}
job, err := client.Renders.Batch(ctx, formfeed.BatchRequest{Template: "invoice", Items: items, Zip: true})
if err != nil {
log.Fatal(err)
}
finished, err := client.Jobs.WaitFor(ctx, job.ID)
if err != nil {
log.Fatal(err)
}
fmt.Println(finished.Status, finished.Succeeded, finished.Failed, finished.ZipURL)
Renders.WaitFor(ctx, id) asks every second until the render succeeded or failed and returns it either way: a failed render is an answer, not an error, so look at its Status and Error. Error is a value, not a pointer, so render.Error.Code reads without a nil check: it is empty unless the render failed. After 120 seconds it answers a *formfeed.Error with the code timeout, while the render goes on; formfeed.WithWaitTimeout and formfeed.WithPollInterval change the two, and the context's deadline ends the wait earlier. Jobs.WaitFor does the same for a batch (every 2 seconds, for at most 600) and returns once no render of the job is queued or running, with the status completed, partially_failed or failed; finished.Items are its renders in the order of the request. For anything that takes more than a few seconds in production, prefer webhooks over polling.
List renders and delete outputs
page, err := client.Renders.List(ctx, formfeed.RenderListOptions{Template: "invoice", Status: "failed", Limit: 20})
if err != nil {
log.Fatal(err)
}
for _, failed := range page.Data {
fmt.Println(failed.ID, failed.Error.Code)
}
// an iterator that follows the cursor; an error ends it as its last value
for render, err := range client.Renders.All(ctx, formfeed.RenderListOptions{
Since: "2026-08-01T00:00:00Z",
Until: "2026-09-01T00:00:00Z",
}) {
if err != nil {
log.Fatal(err)
}
fmt.Println(render.ID, render.Status)
}
// needs the file:delete scope
if err := client.Renders.DeleteOutputs(ctx, id); err != nil {
log.Fatal(err)
}
// the kept request (render:input); 410 render_input_expired when none was kept
input, err := client.Renders.Input(ctx, id)
if err != nil {
log.Fatal(err)
}
fmt.Println(input.RenderID, input.Data)
A page has its renders in Data, newest first, and in NextCursor the cursor of the next page, empty on the last, which RenderListOptions.Cursor takes.
PDF tools
// in the same render: steps run as merge, watermark, password
contract, err := client.Renders.Create(ctx, formfeed.RenderRequest{
Template: "contract",
Data: data,
Post: map[string]any{"watermark": map[string]any{"text": "DRAFT"}},
})
if err != nil {
log.Fatal(err)
}
// on renders and library files you already have, by id or name; each tool answers a new render
bundle, err := client.PDF.Merge(ctx, formfeed.MergeRequest{
Sources: []string{contract.ID, "terms.pdf"},
Filename: "bundle.pdf",
})
if err != nil {
log.Fatal(err)
}
locked, err := client.PDF.Protect(ctx, formfeed.ProtectRequest{
Source: bundle.ID,
UserPassword: "open-sesame",
Permissions: []string{"print"},
})
if err != nil {
log.Fatal(err)
}
info, err := client.PDF.Info(ctx, formfeed.InfoRequest{Source: locked.ID}) // free
if err != nil {
log.Fatal(err)
}
fmt.Println(info.PageCount, info.Encrypted)
The tools that read a PDF, and the conversion, take an upload as well, which is sent as multipart and never kept:
// office documents to PDF: Word, Excel, PowerPoint, OpenDocument, RTF or HTML, up to 20 MB
sheet, err := formfeed.UploadFromFile("report.xlsx")
if err != nil {
log.Fatal(err)
}
report, err := client.PDF.Convert(ctx, formfeed.ConvertRequest{File: sheet, SinglePageSheets: true, Filename: "report.pdf"})
if err != nil {
log.Fatal(err)
}
scan, err := formfeed.UploadFromFile("invoice.pdf")
if err != nil {
log.Fatal(err)
}
redacted, err := client.PDF.Redact(ctx, formfeed.RedactRequest{File: scan, Text: []string{"Max Mustermann"}})
if err != nil {
log.Fatal(err)
}
// a form of the file library: every field's name, type, value and options, then the values
form, err := client.PDF.Info(ctx, formfeed.InfoRequest{Source: "antrag.pdf"})
if err != nil {
log.Fatal(err)
}
filled, err := client.PDF.Fill(ctx, formfeed.FillRequest{
Source: "antrag.pdf",
Fields: map[string]any{"customer.name": "Erika Mustermann"},
Flatten: true,
})
if err != nil {
log.Fatal(err)
}
fmt.Println(report.ID, redacted.ID, len(form.Form.Fields), filled.Form.Filled)
Merge, Protect, Watermark, Info, Split, Compress, ToImage, Redact, Fill and Convert each take their request struct (formfeed.SplitRequest{Source: bundle.ID, Ranges: []string{"1", "2-"}} answers a ZIP, formfeed.ToImageRequest{Source: bundle.ID, Pages: "1", DPI: 72} a PNG). Starter plan and higher, 0.5 units per step on live keys; a conversion is counted like a PDF render, ToImage one unit per picture. Info is free on every plan. A source is the id of a render (rnd_…) or a library file's id (fil_…) or name, as Source (Sources for Merge). Info, Split, Compress, ToImage, Redact, Fill and Convert take a File instead, an *formfeed.Upload from formfeed.UploadFromFile(path), UploadFromBytes(name, contents) or UploadFromReader(name, r); a request with both answers invalid_request. Convert's Source is the render of a Word or PowerPoint template. The fields are those the PDF tools page describes, output options included (Filename, ExpiresIn, Access, Meta, Storage). A result of several files is one ZIP (render.Output == "zip"). Redact draws a black box over what it removed, with NoFill: true none; Fill puts what it did in the render's Form.
Validate e-invoices
// the report a render of this workspace keeps: free
checked, err := client.Einvoices.Validate(ctx, formfeed.ValidateEinvoiceRequest{RenderID: invoiceRender.ID})
if err != nil {
log.Fatal(err)
}
fmt.Println(checked.Result, checked.Validator, checked.Rules)
// an XML Formfeed did not make: one of the organisation's validations of the day
received, err := formfeed.UploadFromFile("received.xml")
if err != nil {
log.Fatal(err)
}
checked, err = client.Einvoices.Validate(ctx, formfeed.ValidateEinvoiceRequest{File: received, Rules: "xrechnung"})
if err != nil {
log.Fatal(err)
}
for _, check := range checked.Checks {
fmt.Println(check.Kind, check.Name, check.Result)
}
Result is passed, failed or not_checked; Rules takes auto, factur-x, xrechnung or en16931. The key needs the einvoice:validate scope, and an upload the Starter plan or higher; see E-invoice validation for what the report says and what it does not.
File library
// the same name replaces the file everywhere; templates use {{ asset('brand/logo.png') }}
logo, err := formfeed.UploadFromFile("logo.png")
if err != nil {
log.Fatal(err)
}
logo.Name = "brand/logo.png" // the library name; UploadFromFile named it logo.png
file, err := client.Files.Upload(ctx, logo)
if err != nil {
log.Fatal(err)
}
fmt.Println(file.URL)
for f, err := range client.Files.All(ctx, formfeed.FileListOptions{Prefix: "brand/"}) {
if err != nil {
log.Fatal(err)
}
fmt.Println(f.Name, f.Bytes)
}
if err := client.Files.Delete(ctx, file.ID); err != nil {
log.Fatal(err)
}
// library files in post-processing: an image watermark and a PDF merged by name
if _, err := client.Renders.Create(ctx, formfeed.RenderRequest{
Template: "contract",
Data: data,
Post: map[string]any{
"watermark": map[string]any{"image": "draft.png"},
"merge_after": []string{"terms.pdf"},
},
}); err != nil {
log.Fatal(err)
}
Files.Get and Files.Delete take the file's id (fil_…) or its name; List and All narrow by Prefix. file:read, file:write and file:delete scopes. Library files are served without a signature; see Files.
Templates
for template, err := range client.Templates.All(ctx, formfeed.TemplateListOptions{Kind: "pdf"}) {
if err != nil {
log.Fatal(err)
}
fmt.Println(template.Slug, template.PublishedVersion)
}
schema, err := client.Templates.Schema(ctx, "invoice", "") // JSON Schema of the expected data
if err != nil {
log.Fatal(err)
}
check, err := client.Templates.Validate(ctx, "invoice", formfeed.ValidateTemplateRequest{Data: data}) // renders nothing
if err != nil {
log.Fatal(err)
}
fmt.Println(schema["type"], check.OK, len(check.Diagnostics))
Templates.Get(ctx, slug) reads one template; Schema(ctx, slug, version) takes "published", "latest", a number or a channel name, and with "" reads the published version, else the latest. It returns the stored data schema, else one inferred from the sample data. The Go SDK reads and checks templates. Writing versions, publishing, release channels, the brand kit and shared partials have no methods yet; client.Request reaches them.
Webhooks
hook := formfeed.Webhook{Secret: os.Getenv("FORMFEED_WEBHOOK_SECRET")}
http.Handle("POST /webhooks/formfeed", hook.Handler(func(w http.ResponseWriter, r *http.Request, event *formfeed.WebhookEvent) {
if event.Type == "render.completed" {
render, err := event.Render()
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
log.Println("ready:", render.ID, render.DownloadURL)
}
w.WriteHeader(http.StatusNoContent)
}))
log.Fatal(http.ListenAndServe(":8080", nil))
Handler reads each delivery as it arrived, because the signature covers the bytes on the wire, and answers 401 to one whose signature does not match or whose timestamp is more than five minutes from the current time, which Formfeed retries. Only a delivery that passed reaches your function, with the request's body there to read again. Without a secret it answers 500, a server error rather than a refusal, so the deliveries are retried until the secret is set. The event has ID, Type, CreatedAt, WorkspaceID and Data, the raw JSON, which event.Render() and event.Job() read as a render or a job.
Handler is an http.Handler, so any router built on net/http mounts it. Elsewhere, formfeed.ParseWebhook(secret, header, body) verifies the raw body and reads the event, answering formfeed.ErrInvalidSignature when the signature does not match; formfeed.VerifyWebhook returns a boolean instead, and a formfeed.Webhook with a Tolerance changes the five minutes. Endpoints are managed with client.Webhooks.Create(ctx, formfeed.CreateWebhookRequest{URL: …, Events: […]}), List, Update, Delete and Test; both requests take Environments. client.Webhooks.Resend(ctx, eventID, endpointID) sends a stored event again. A complete receiver is on the Webhooks page.
Usage and account
usage, err := client.Account.Usage(ctx, "") // current period
if err != nil {
log.Fatal(err)
}
fmt.Println(usage.Used, "of", usage.Included)
august, err := client.Account.Usage(ctx, "2026-08") // the period that started in August 2026
if err != nil {
log.Fatal(err)
}
fmt.Println(august.PeriodStart, august.Used)
account, err := client.Account.Get(ctx) // workspace, plan, limits (a map[string]any)
if err != nil {
log.Fatal(err)
}
fmt.Println(account["plan"])
Units are counted per organisation, in billing periods that renew on the day the subscription started (calendar months on the Free plan without a subscription). Both need account:read.
Errors
_, err := client.Renders.Create(ctx, formfeed.RenderRequest{Template: "missing"})
var ferr *formfeed.Error
if errors.As(err, &ferr) {
fmt.Println(ferr.Code, ferr.Status, ferr.RequestID) // template_not_found 404 req_…
if ferr.Problem != nil {
fmt.Println(ferr.Problem.Members) // the full problem body
}
}
ferr.Code is the problem code of the API's answer, ferr.Message its detail (else its title) and ferr.Status its HTTP status; ferr.Problem is the problem body, with Type, Title, Detail and RenderID and every member in Members, and ferr.RequestID the X-Request-Id to quote to support. err.Error() reads formfeed: template_not_found (HTTP 404): … [request req_…]. Failures on the client's side have these codes, and the status 0 where there was no answer:
| Code | When |
|---|---|
network_error | The request could not be sent or timed out on every attempt; ferr.Err is the cause, which errors.Is sees through |
timeout | Renders.WaitFor or Jobs.WaitFor ran out of time; the render or job goes on |
not_ready | Renders.Download, DownloadTo or DownloadFile of a render that has no output yet, or failed |
download_failed | The download link answered an error (the status is the link's) |
invalid_response | The API answered with a body that is not the JSON the call expects |
invalid_request | The client was made without an API key or with a region that is neither eu nor us, or a request cannot be sent (a Source and a File) |
An error answer without a problem code gets http_<status>, such as http_502. A cancelled context is not a *formfeed.Error: the call returns the context's error (Contexts). ParseWebhook answers formfeed.ErrInvalidSignature, not a *formfeed.Error.
Calls without a method
var channels map[string]any
if err := client.Request(ctx, http.MethodGet, "/templates/invoice/channels", nil, &channels); err != nil {
log.Fatal(err)
}
client.Request(ctx, method, path, body, out) reaches any call of the API with the client's key, retries and errors: path is relative to the base URL and carries its query, body is sent as JSON when it is not nil, and the answer is decoded into out, a pointer, when it has a body. It sends no Idempotency-Key unless you pass formfeed.WithIdempotencyKey.