Go SDK
One `Invoice` struct to issue, consult, cancel and correct invoices, plus clients, catalog and webhooks — typed and validated.

The official Go SDK wraps the REST API in one Invoice struct. With it you issue, consult, cancel and correct invoices, and also manage clients, catalog and webhooks.
How to install
go get github.com/stackin-io/stackin-go-sdkIt requires Go 1.21 or later.
What the SDK does
The Invoice struct groups these methods:
- Invoice lifecycle:
Issue(),Consult(),Cancel()andReissue(). - Correction and invalidation:
Correct()(correction letter, NF-e only),Invalidate()andInvalidations()(numbering invalidation). - Lookups and other operations:
Pdf(),History(),Submissions(),Rejection(),Stats(),Received(),SyncReceived(),Manifest(),Usage(),Readiness()andClassify().
Each line item is a typed br.Product. Brazil-specific tax fields (NCM/CFOP/CEST...) are required only where the authorizer really needs them.
Beside Invoice sit:
Clients: saved clients, which an issuance references byClientID.Items: the catalog of products and services, which a line references byItemID.WebhooksandCompany.FiscalReference: tax codes and municipalities.Taxpayer: CNPJ and CPF lookup.
These are the same methods and the same contract as the Python, Node and PHP SDKs. Once you know one of them, a Go integration reads the same way. Issue/Consult/Cancel versus issue/consult/cancel is a casing convention, not a behavior difference.
How to authenticate
Use your API key as a Bearer token, the same as the raw API. It resolves the issuing company entirely: CNPJ, state, certificate and environment. Nothing about the issuer goes in the call.
A key with the sdk context is valid on sdk.stackin.io, the SDK's default host. One with the api context is valid on api.stackin.io, the raw API's host. Using one on the other's host returns 401.
An OAuth credential can cover several companies. In that case, each call names the one it acts on with WithCompany or ForCompany.
How to handle errors
Errors arrive as distinct types, not as one generic failure:
*APIError: carries the response'sStatusCodeandDetail.422when the authorizer refused the data,503to try later,502when it could not be reached.*ConnectionFailedError: a network, DNS or timeout failure before any response came back.*InvoiceError: a client-side validation problem, such as empty items, a missingNCM/CFOPon an NF-e item or an incomplete recipient address. It shows up before the request is even sent.
Known refusals have their own type, such as PaymentRequiredError (402, no allowance or credit left) and RateLimitedError (429). errors.As still finds the *APIError inside them.
How to repeat an issuance safely
The SDK never repeats a call on its own and never generates an idempotency key.
Issuing is the call you must not repeat blindly. If the response was lost, the invoice may have been authorized.
Pass IdempotencyKey in the IssueRequest, or stackin.WithIdempotencyKey on Reissue. Repeating with the same key and the same body returns the first response, with no second document and no new credit.
See the SDKs section of the API reference for install commands, or the code on GitHub.