Go SDK
Reference for ndstill-go: the client, Pay, approvals, simulate and the x402 round tripper.
github.com/ndstill/ndstill-go is the designed Go client for the v2 API: one package, context-aware calls, typed params and models, an http.RoundTripper for x402 and net/http Verify middleware. Go 1.22 or later.
Install#
go get github.com/ndstill/ndstill-goCreate a client#
import (
"os"
"github.com/ndstill/ndstill-go"
)
client := ndstill.New(os.Getenv("NDSTILL_API_KEY"))
// With options:
client = ndstill.New(os.Getenv("NDSTILL_API_KEY"),
ndstill.WithVersion("2026-11-01"),
ndstill.WithMaxRetries(2),
ndstill.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
)| Option | Default | Notes |
|---|---|---|
WithBaseURL(url) | https://api.ndstill.com/v2 | A regional cell or a local mock. |
WithVersion(v) | 2026-11-01 | Sent as Ndstill-Version. |
WithAccessToken(t) | none | Use an OAuth 2.1 token instead of the key. |
WithMaxRetries(n) | 2 | Network errors, 429, 502, 504; same idempotency key. |
WithHTTPClient(c) | http.DefaultClient with a 30 s timeout | Bring your own. |
Pay#
payment, err := client.Pay(ctx, ndstill.PayParams{
Agent: "agt_01JD8Q3W6Z",
Amount: ndstill.Money{Amount: 4200, Asset: "USD"},
Counterparty: "Delta Air Lines",
Purpose: "Flight SFO to JFK for the offsite",
})
if err != nil {
var declined *ndstill.DeclinedError
if errors.As(err, &declined) {
log.Println(declined.DeclineReasons[0].Message, declined.RequestID)
return
}
return err
}
if payment.Status == ndstill.StatusHeld {
// A person approves first.
approval, err := client.Approvals.Wait(ctx, payment.ApprovalID, 10*time.Minute)
_ = approval
_ = err
}PayParams also takes RailPreference, MandateID, Dims and IdempotencyKey. Without a key, the client generates one and reuses it on retries.
Resources#
| Method | Endpoint |
|---|---|
client.Pay / client.Payments.Create | POST /payment-intents |
client.Payments.Get, client.Payments.List | GET /payment-intents… |
client.Simulate | POST /decisions/simulate |
client.Approvals.Get, client.Approvals.Wait | GET /approvals/{id} |
client.Budgets.Check | GET /budgets for the agent's scopes |
client.Agents.Freeze, client.Freezes.Create | POST /agents/{id}/freeze, POST /freezes |
client.Policies.Validate, client.Policies.Replay | /policies/{id}/… |
ndstill.VerifyWebhook(body, header, secret) | Local Standard Webhooks check |
Simulate in tests#
func TestTravelPolicy(t *testing.T) {
sim, err := client.Simulate(ctx, ndstill.SimulateParams{
Agent: travelAgent,
Amount: ndstill.Money{Amount: 45000, Asset: "USD"},
Counterparty: "Delta Air Lines",
})
if err != nil {
t.Fatal(err)
}
if sim.WouldOutcome == ndstill.OutcomeDecline {
t.Fatalf("a normal flight would be declined: %v", sim.Reasons)
}
}Pagination#
iter := client.Payments.List(ctx, ndstill.PaymentListParams{Status: "held"})
for iter.Next() {
p := iter.Current()
_ = p
}
if err := iter.Err(); err != nil {
return err
}Errors#
Every non-2xx response is an *ndstill.Error with Type, Code, Message, RequestID, Fields and DeclineReasons; use errors.As for the typed ones: *DeclinedError, *InvalidRequestError, *StepUpRequiredError, *RateLimitError (with RetryAfter). A held payment is not an error. See Errors and decline reasons.
x402 round tripper#
httpClient := &http.Client{
Transport: ndstill.X402Transport(client, ndstill.X402Options{
Agent: "agt_01JD8Q3W6Z",
Wallet: wallet, // anything that implements ndstill.TypedDataSigner
MaxAmount: ndstill.Money{Amount: 100000, Asset: "USDC"},
}),
}
resp, err := httpClient.Get("https://api.northwind.example/v1/search?q=agents")On 402 Payment Required, the transport asks ndStill for a decision first and signs only against an approved payment approval token. See x402 and USDC.
Verify middleware#
mux.Handle("/v1/search", ndstill.Verify(ndstill.VerifyOptions{Require: "passport"})(searchHandler))
// inside the handler: agent := ndstill.AgentFrom(r.Context())See Verify for sellers.