.NET SDK
Formfeed is the .NET client for the REST API, for .NET 10 and every platform of .NET Standard 2.0 (.NET 8 and 9, .NET Framework 4.6.2 and newer). It behaves exactly like the TypeScript SDK: 429, 503 and network errors are retried, every render carries an Idempotency-Key, and API problems throw FormfeedException. Every call is asynchronous and takes a CancellationToken. It sends over an HttpClient of its own or the one you pass, so it works with IHttpClientFactory, and its JSON is generated at build time, so it trims and runs under native AOT. Use it on a server: the API refuses an API key sent from a web page.
dotnet add package Formfeed
Set up a client
using Formfeed;
using var formfeed = new FormfeedClient(Environment.GetEnvironmentVariable("FORMFEED_API_KEY"));
new FormfeedClient(apiKey) takes the defaults; new FormfeedClient(options) takes a FormfeedClientOptions:
| Property | Default | Notes |
|---|---|---|
ApiKey | required | ff_live_… or ff_test_… |
Region | "eu" | "eu" (https://api-eu.formfeed.dev/v1) or "us" (https://api-us.formfeed.dev/v1) |
BaseUrl | 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 Region. |
MaxRetries | 3 | Retries on 429, 503 and network errors; 0 turns retrying off. |
Timeout | 120 seconds | The time limit of one attempt and of a download. A request that times out counts as a network error and is retried. An HttpClient you pass keeps its own Timeout as well, 100 seconds unless you set it, so give it more than this one. |
Headers | empty | Sent with every request, after the SDK's own, which they replace. |
JsonSerializerOptions | none | How an object of your own inside Data, Settings or another free map is written. In an application that is trimmed or compiled ahead of time, give options whose resolver knows its type (your own JsonSerializerContext). |
Delay | Task.Delay | How to wait between retries and polls; for tests. |
Jitter | random | The share of the 250 ms of jitter a retry waits on top, from 0 to 1; for tests. |
new FormfeedClient(apiKey, httpClient) and new FormfeedClient(options, httpClient) send over your HttpClient. Disposing the client disposes the HttpClient it made itself; one you passed stays yours. One client serves any number of calls at the same time, so make it once.
A request is a class with the API's fields as properties: RenderRequest, BatchRequest and an options class per PDF tool (MergeOptions, ProtectOptions, …). What you leave null is not sent, so the API's default applies. Data, Settings, Meta and Post are dictionaries (IDictionary<string, object?>) whose values may be strings, numbers, booleans, nested dictionaries and lists, JsonNode or JsonElement values; AdditionalFields sends a field the SDK does not name, region for one, as given. An answer is a model: render.DownloadUrl, render.PageCount, render.Units, and render.Raw with the whole answer as a JsonElement, fields of later API versions included. Values such as Status stay plain strings, so a new one never breaks a read.
Retries and idempotency
The rule is the one of the TypeScript SDK: 429, 503 and network errors are sent again up to MaxRetries 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.CreateAsync, Renders.CreateBatchAsync, every PDF tool but GetInfoAsync, and Einvoices.ValidateAsync send an Idempotency-Key, a random one unless you pass one as idempotencyKey; 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
var invoice = new Dictionary<string, object?>
{
["number"] = "2026-0042",
["lines"] = new[]
{
new Dictionary<string, object?> { ["description"] = "Consulting", ["qty"] = 8, ["price"] = 120 },
},
};
var render = await formfeed.Renders.CreateAsync(
new RenderRequest
{
Template = "invoice",
Data = new Dictionary<string, object?> { ["invoice"] = invoice },
Filename = $"invoice-{invoice["number"]}.pdf",
},
idempotencyKey: "order-8812-invoice");
// a sync render still running after 60 seconds comes back queued; wait for it
if (render.Status != "succeeded")
{
render = await formfeed.Renders.WaitForAsync(render);
}
Console.WriteLine($"{render.DownloadUrl} {render.PageCount} {render.Units}");
await formfeed.Renders.DownloadToAsync(render, "invoice.pdf");
RenderRequest has the fields of POST /renders as properties: Template, or Html with Engine, or Url, or Markdown; Version; Data; Output; Settings; Locale; Filename; ExpiresIn; Access; Mode; WebhookUrl and WebhookSecret; Meta; Dedupe; CanaryKey; ValidateData; Post; Storage. The idempotency key is an argument of the SDK's own.
A failed render throws FormfeedException. 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. Renders.GetAsync(id) fetches a render again, with a fresh download link. DownloadAsync(render) returns the file's bytes, DownloadToAsync(render, path) writes them to a file, which it replaces, DownloadToAsync(render, stream) to a stream, and each throws not_ready while the render has no output; each also takes a render's id and reads the render first.
Async renders and batches
var queued = await formfeed.Renders.CreateAsync(new RenderRequest { Template = "annual-report", Data = payload, Mode = "async" });
var done = await formfeed.Renders.WaitForAsync(queued, timeout: TimeSpan.FromMinutes(2));
var job = await formfeed.Renders.CreateBatchAsync(new BatchRequest
{
Template = "invoice",
Zip = true,
Items = orders.Select(order => new RenderRequest
{
Data = new Dictionary<string, object?> { ["invoice"] = order },
Filename = $"{order["number"]}.pdf",
Meta = new Dictionary<string, object?> { ["order_id"] = order["id"] },
}).ToList(),
});
var finished = await formfeed.Jobs.WaitForAsync(job);
Console.WriteLine($"{finished.Status} {finished.Succeeded} {finished.Failed} {finished.ZipUrl}");
Renders.WaitForAsync(render, timeout, interval) asks every interval (one second by default) until the render succeeded or failed and returns it either way; after timeout (120 seconds by default) it throws FormfeedException with the code timeout, while the render goes on. Jobs.WaitForAsync does the same for a batch (ten minutes and two seconds by default) and returns once the job is completed, partially_failed or failed. A cancelled CancellationToken stops either wait. For anything that takes more than a few seconds in production, prefer webhooks over polling.
List renders and delete outputs
var page = await formfeed.Renders.ListAsync(new RenderListQuery { Template = "invoice", Status = "failed", Limit = 20 });
foreach (var failed in page.Data)
{
Console.WriteLine($"{failed.Id} {failed.Error?.Code}");
}
// an IAsyncEnumerable that follows the cursor
var august = new RenderListQuery
{
Since = new DateTimeOffset(2026, 8, 1, 0, 0, 0, TimeSpan.Zero),
Until = new DateTimeOffset(2026, 9, 1, 0, 0, 0, TimeSpan.Zero),
};
await foreach (var listed in formfeed.Renders.ListAllAsync(august))
{
// …
}
await formfeed.Renders.DeleteOutputsAsync(render); // needs the file:delete scope
var kept = await formfeed.Renders.GetInputAsync(render); // the kept request (render:input); 410 render_input_expired when not kept
PDF tools
// in the same render: steps run as merge, watermark, password
var contract = await formfeed.Renders.CreateAsync(new RenderRequest
{
Template = "contract",
Data = data,
Post = new Dictionary<string, object?> { ["watermark"] = new Dictionary<string, object?> { ["text"] = "DRAFT" } },
});
// on renders you already have (a Render or its id) and PDFs of the library; each answers a new render
var bundle = await formfeed.Pdf.MergeAsync([invoicePdf, "terms.pdf"], new MergeOptions { Filename = "bundle.pdf" });
var locked = await formfeed.Pdf.ProtectAsync(bundle, new ProtectOptions { UserPassword = "open-sesame", Permissions = ["print"] });
var info = await formfeed.Pdf.GetInfoAsync(locked); // PageCount, Pages, Encrypted, Metadata, Form; free
// office documents to PDF: an upload (Word, Excel, PowerPoint, OpenDocument, RTF or HTML, up to 20 MB, not kept)…
var report = await formfeed.Pdf.ConvertAsync(Upload.FromPath("report.xlsx"), new ConvertOptions { SinglePageSheets = true, Filename = "report.pdf" });
// …or the output of a Word or PowerPoint template render
var offerPdf = await formfeed.Pdf.ConvertAsync(offerRender, new ConvertOptions { PageRanges = "1-3" });
// split, compress, draw, redact and fill: a stored PDF, or an Upload that is never kept
var parts = await formfeed.Pdf.SplitAsync(bundle, new SplitOptions { Ranges = ["1", "2-"] }); // output zip
var thumbnail = await formfeed.Pdf.ToImageAsync(bundle, new ToImageOptions { Pages = "1", Dpi = 72 }); // output png
var redacted = await formfeed.Pdf.RedactAsync(Upload.FromPath("invoice.pdf"), new RedactOptions { Text = ["Max Mustermann"] });
var form = (await formfeed.Pdf.GetInfoAsync("antrag.pdf")).Form; // every field's name, type, value and options
var filled = await formfeed.Pdf.FillAsync("antrag.pdf", new FillOptions
{
Fields = new Dictionary<string, object?> { ["customer.name"] = "Erika Mustermann" },
Flatten = true,
});
Starter plan and higher, 0.5 units per step on live keys; a conversion is counted like a PDF render, ToImageAsync one unit per picture. GetInfoAsync is free on every plan. A source is a Render or its id, or a LibraryFile or its id or name, each of which becomes a StoredPdf by itself. GetInfoAsync, SplitAsync, CompressAsync, ToImageAsync, RedactAsync and FillAsync also take an Upload (Upload.FromPath(path), Upload.FromBytes(bytes, name) or await Upload.FromStreamAsync(stream, name)), which is sent as multipart and never kept, and ConvertAsync takes an Upload or the render of a Word or PowerPoint template. The options are the fields of each tool as the PDF tools page describes them, output options included (Filename, ExpiresIn, Access, Meta, Storage, and AdditionalFields for the rest). A result of several files is one ZIP (render.Output == "zip"). RedactAsync draws a black box over what it removed, with NoFill = true none; FillAsync puts what it did in the render's Form.
E-invoice validation
// an e-invoice Formfeed made: the report its render keeps, free
JsonElement stored = await formfeed.Einvoices.ValidateAsync(einvoiceRender);
// one it did not make: its XML (CII or UBL), up to 4 MB, from the Starter plan
JsonElement received = await formfeed.Einvoices.ValidateAsync(Upload.FromPath("RE-2026-0001.xml"), rules: "xrechnung");
Console.WriteLine(received.GetProperty("result")); // passed, failed or not_checked
ValidateAsync takes a Render or its id, or an Upload of an XML; rules is auto (the API's default for an upload), factur-x, xrechnung or en16931. The answer is the report as JSON: which rules the file passed, by which validator and release, and which bytes it judged. Each upload counts one of the organisation's validations of the day; a render's stored report never does. See E-invoice validation.
File library
// the same name replaces the file everywhere; templates use {{ asset('brand/logo.png') }}
var logo = await formfeed.Files.UploadAsync(Upload.FromPath("logo.png", "brand/logo.png"));
Console.WriteLine(logo.Url);
await foreach (var file in formfeed.Files.ListAllAsync(new FileListQuery { Prefix = "brand/" }))
{
Console.WriteLine($"{file.Name} {file.Bytes}");
}
await formfeed.Files.DeleteAsync(logo);
// library files in post-processing: an image watermark and a PDF merged by name
await formfeed.Renders.CreateAsync(new RenderRequest
{
Template = "contract",
Data = data,
Post = new Dictionary<string, object?>
{
["watermark"] = new Dictionary<string, object?> { ["image"] = "draft.png" },
["merge_after"] = new[] { "terms.pdf" },
},
});
The upload's name is the library name, so it has to be a valid one. Files.ListAsync reads one page, GetAsync(idOrName) one file. file:read, file:write and file:delete scopes. Library files are served without a signature; see Files.
Templates
await foreach (var template in formfeed.Templates.ListAllAsync(new TemplateListQuery { Kind = "pdf" }))
{
Console.WriteLine($"{template.Slug} {template.PublishedVersion}");
}
var schema = await formfeed.Templates.GetSchemaAsync("invoice"); // JSON Schema of the expected data
var check = await formfeed.Templates.ValidateAsync("invoice", new TemplateValidation { Data = data }); // ok, template, diagnostics; renders nothing
Templates.GetAsync(slug) reads one template; GetSchemaAsync(slug, version) takes "published" (the default), "latest", a number or a channel name, and returns the stored data schema, else one inferred from the sample data. The .NET SDK reads and checks templates. Writing versions, publishing, release channels, the brand kit and shared partials have no methods yet: RequestAsync reaches them.
Webhooks
An ASP.NET Core receiver:
app.MapPost("/webhooks/formfeed", async (HttpRequest request) =>
{
// the signature covers the bytes on the wire: read the raw body, never re-serialised JSON
using var body = new MemoryStream();
await request.Body.CopyToAsync(body);
try
{
var delivery = Webhook.Parse(
app.Configuration["Formfeed:WebhookSecret"]!,
request.Headers["Webhook-Signature"],
body.ToArray());
if (delivery.Type == "render.completed")
{
var render = Render.FromJson(delivery.Data);
// …
}
return Results.NoContent();
}
catch (WebhookSignatureException)
{
return Results.Unauthorized();
}
});
Pass the raw request body, not bound to a model: the signature covers the bytes as they arrived. Webhook.Parse returns the event as a WebhookEvent (Id, Type, CreatedAt, WorkspaceId, and Data as a JsonElement, which Render.FromJson or Job.FromJson reads), and throws WebhookSignatureException when the signature does not match or its timestamp is more than five minutes from the current time (tolerance changes the five minutes). Webhook.Verify(secret, header, rawBody) returns a boolean instead of throwing. Both take the body as bytes or as a string. Endpoints are managed with Webhooks.CreateAsync(new WebhookCreate { Url = …, Events = […] }), ListAsync(), UpdateAsync(), DeleteAsync() and TestAsync(); WebhookCreate and WebhookUpdate take Environments. Webhooks.ResendAsync(eventId, endpointId) sends a stored event again. More on the Webhooks page.
Usage and account
var usage = await formfeed.Account.GetUsageAsync(); // current period
var august = await formfeed.Account.GetUsageAsync("2026-08"); // the period that started in August 2026
Console.WriteLine($"{usage.Used} of {usage.Included}");
JsonElement account = await formfeed.Account.GetAsync(); // workspace, plan, limits
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
try
{
await formfeed.Renders.CreateAsync(new RenderRequest { Template = "missing" });
}
catch (FormfeedException e)
{
Console.WriteLine($"{e.Code} {e.Status} {e.RequestId}"); // template_not_found 404 req_…
Console.WriteLine(e.Problem?.Raw); // the full problem body
}
e.Code is the problem code of the API's answer, e.Message its detail and e.Status its HTTP status; e.Problem is the problem body (Type, Title, Detail, and Raw with every member) and e.RequestId the X-Request-Id to quote to support. Failures on the client's side have the status 0 and these codes:
| Code | When |
|---|---|
network_error | The request could not be sent or timed out on every attempt |
timeout | Renders.WaitForAsync or Jobs.WaitForAsync ran out of time; the render or job goes on |
not_ready | Renders.DownloadAsync 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 created without an API key, or with a region that is neither eu nor us |
An error answer without a problem code gets http_<status>, such as http_502. A call you cancel throws OperationCanceledException, not FormfeedException. Webhook.Parse throws WebhookSignatureException, and a JsonException for a correctly signed body that is not JSON.
Any other call
JsonElement? channels = await formfeed.RequestAsync(HttpMethod.Get, "/templates/invoice/channels");
RequestAsync(method, path, body, idempotencyKey) reaches any call of the API with the client's key, retries and errors: the path after /v1, with its query; a body as a dictionary, a list or a JSON value; an Idempotency-Key when you give one. It returns the JSON answer, null for an answer without a body.
IHttpClientFactory
builder.Services
.AddHttpClient("formfeed", http => http.Timeout = TimeSpan.FromSeconds(130))
.AddTypedClient((http, services) =>
new FormfeedClient(services.GetRequiredService<IConfiguration>()["Formfeed:ApiKey"], http));
A class that takes FormfeedClient in its constructor then gets one over the factory's HttpClient, whose handlers the factory pools and renews. Its clients wait 100 seconds by default, so the line above gives them more than the SDK's 120 seconds per attempt; the SDK's own limit applies as well.