Install
Go package wellfriend.dev/go/wellfriend, for Go 1.25 or later. Import it with import "wellfriend.dev/go/wellfriend" What the registry serves now: v1.0.1 on pkg.go.dev.
go get wellfriend.dev/go/wellfriend@latestQuickstart
Create a key in the dashboard (/dashboard/developer-api/keys) and set it as WELLFRIEND_API_KEY on your server; the client reads it, and https://wellfriend.dev/api/v2 is the default address. The lines run inside a function with a context (ctx) and import "wellfriend.dev/go/wellfriend".
wf := wellfriend.New() // reads WELLFRIEND_API_KEY
res, err := wf.Tools.CompressPDF(ctx, wellfriend.File("input.pdf"), nil)
if err == nil { err = res.Save(ctx, "output.pdf") }// go get wellfriend.dev/go/wellfriend@latest
package main
import (
"context"
"fmt"
"os"
"wellfriend.dev/go/wellfriend"
)
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run() error {
// Your API key: set WELLFRIEND_API_KEY, or replace YOUR_API_KEY (keys: https://wellfriend.dev/dashboard/developer-api/keys).
apiKey := os.Getenv("WELLFRIEND_API_KEY")
if apiKey == "" {
apiKey = "YOUR_API_KEY"
}
wf := wellfriend.New(wellfriend.WithAPIKey(apiKey))
ctx := context.Background()
res, err := wf.Tools.CompressPDF(ctx, wellfriend.File("input.pdf"), nil)
if err != nil {
return err
}
return res.Save(ctx, "input-wellfriend.pdf")
}Tools
Every tool is one method, wf.Tools.<Tool>(input, params, options): it uploads the input (a path, bytes, a stream or a stored document; a list for merge), runs the tool, waits and returns the result. The result saves its first output with save(path), or every output into a folder; it also gives the bytes, a stream, the outputs, the operation and the usage. tools.run(toolId, ...) runs any tool by id, wait: false returns the started operation to wait on later, and quote(...) prices a run before you send it.
res, err := wf.Tools.CompressPDF(ctx, wellfriend.File("input.pdf"), &wellfriend.CompressPDFParams{Level: "strong"})
if err != nil {
return err
}
fmt.Println(res.Outputs, res.Usage)
merged, err := wf.Tools.Run(ctx, "merge-pdf", wellfriend.Files("a.pdf", "b.pdf"), nil)Pipelines
A pipeline runs up to ten tools on one file in one run; each step reads the previous step's output on the server. workflows.define(name, steps) keeps a named pipeline you run again like a tool. The SDK reuses one saved pipeline for the same steps instead of creating one per run.
res, err := wf.Pipeline(
wellfriend.Step{Tool: "compress-pdf"},
wellfriend.Step{Tool: "ocr-pdf"},
).Run(ctx, wellfriend.File("input.pdf"))
if err != nil {
return err
}
return res.Save(ctx, "output.pdf")Errors
Every SDK raises the same errors. A message ends with the reference to quote to Support. Network errors, 408, 429 and 5xx answers are retried twice with backoff (honouring Retry-After) for reads and for writes the SDK sends with an idempotency key; set maxRetries and timeout on the client or per call.
WellfriendError
├─ APIError (status, code, message, referenceId, details)
│ ├─ BadRequestError (400) / ValidationError (422)
│ ├─ AuthenticationError (401) / PermissionDeniedError (403)
│ ├─ NotFoundError (404) / ConflictError (409)
│ ├─ RateLimitError (429, retryAfter)
│ └─ ServerError (5xx)
├─ ConnectionError
├─ TimeoutError
├─ OperationFailedError (code, message, operation)
└─ WaitTimeoutError (operation id, to resume)res, err := wf.Tools.CompressPDF(ctx, wellfriend.File("input.pdf"), &wellfriend.CompressPDFParams{Level: "extreme"})
var apiErr *wellfriend.APIError
var failed *wellfriend.OperationFailedError
switch {
case errors.As(err, &apiErr):
fmt.Println(apiErr.Status, apiErr.Code, apiErr.Message)
case errors.As(err, &failed):
fmt.Println("the operation failed:", failed.Code)
case err != nil:
return err
}Webhooks
webhooks.verify(payload, headers, secret), also available on its own as verifyWebhook, checks the signature over the raw body with a five-minute tolerance and returns the typed event; a bad signature raises WebhookVerificationError. Pass a list of secrets while you rotate one. See /docs/webhooks/signatures.
// Use the raw request body, exactly as received.
event, err := wellfriend.VerifyWebhook(body, r.Header, os.Getenv("WELLFRIEND_WEBHOOK_SECRET"))
if err != nil {
http.Error(w, "invalid signature", http.StatusBadRequest)
return
}
fmt.Println(event.Type)Every other endpoint
Every API operation is a method named after it: DocumentVersions.Download, Webhooks.Endpoints.Create, and so on. List methods return one page and can also go through every page. The API reference (/docs/developer-api/snippets) shows each one in this language.
page, err := wf.Documents.List(ctx, &wellfriend.DocumentsListParams{Limit: 20})
file, err := wf.DocumentVersions.Download(ctx, "<documentId>", "<versionId>")
err = file.Save(ctx, "output.pdf")