RevKeen Docs
SDKs

Go SDK

The official Go client library for the RevKeen API

Build and bill on RevKeen from any Go service. Idiomatic context.Context plumbing, typed request and response structs, auto-pagination iterators, webhook verification, and production-grade retries.

Repo: github.com/RevKeen/sdk-go · Releases · Issues · pkg.go.dev

Generated from packages/openapi/openapi.json. See the versioning page for the compatibility matrix.

Install

go get github.com/RevKeen/sdk-go

Requires Go 1.21+.

Quick start

package main

import (
    "context"
    "fmt"
    "os"

    revkeen "github.com/RevKeen/sdk-go"
)

func main() {
    client := revkeen.NewClient(revkeen.Config{
        APIKey: os.Getenv("REVKEEN_API_KEY"),
    })

    customer, err := client.Customers.Create(context.Background(), &revkeen.CustomerCreateParams{
        Email: revkeen.String("ops@acme.example"),
        Name:  revkeen.String("Acme Inc."),
    })
    if err != nil {
        panic(err)
    }

    fmt.Println(customer.ID)
}

Every endpoint in the API reference is a method on a resource group (client.Customers, client.Invoices, etc.).

What's inside

  • Typed request and response structs — no map[string]interface{} anywhere
  • Context-aware — every method takes context.Context for cancellation and deadlines
  • Automatic pagination iteratorsiter.Next() / iter.Current() / iter.Err()
  • Automatic retries — exponential backoff on 5xx, 429, network errors
  • Idempotency keys — attached automatically on safe-to-retry mutations
  • Webhook verificationrevkeen.Webhooks.Verify(body, signature, secret)
  • OAuth 2.1 + API-key auth — both first-class

Authentication

client := revkeen.NewClient(revkeen.Config{
    APIKey: os.Getenv("REVKEEN_API_KEY"),
})
client := revkeen.NewClient(revkeen.Config{
    OAuth: &revkeen.OAuthConfig{
        ClientID:     os.Getenv("REVKEEN_CLIENT_ID"),
        ClientSecret: os.Getenv("REVKEEN_CLIENT_SECRET"),
        Scopes:       []string{"customers:read", "invoices:write"},
    },
})

Common workflows

Create a customer and invoice

ctx := context.Background()

customer, _ := client.Customers.Create(ctx, &revkeen.CustomerCreateParams{
    Email: revkeen.String("ops@acme.example"),
    Name:  revkeen.String("Acme Inc."),
})

invoice, _ := client.Invoices.Create(ctx, &revkeen.InvoiceCreateParams{
    CustomerID: revkeen.String(customer.ID),
    Currency:   revkeen.String("USD"),
    Lines: []revkeen.InvoiceLineParams{{
        Description:     revkeen.String("Pro plan — January 2026"),
        UnitAmountMinor: revkeen.Int64(9999),
        Quantity:        revkeen.Int64(1),
    }},
})

client.Invoices.Finalize(ctx, invoice.ID)
client.Invoices.Send(ctx, invoice.ID)

Iterate with auto-pagination

iter := client.Invoices.List(ctx, &revkeen.InvoiceListParams{
    Status: revkeen.String("open"),
})

for iter.Next() {
    invoice := iter.Current()
    fmt.Println(invoice.ID, invoice.AmountDueMinor)
}
if err := iter.Err(); err != nil {
    return err
}

Verify a webhook

import (
    "io"
    "net/http"
    "os"

    revkeen "github.com/RevKeen/sdk-go"
)

func webhookHandler(w http.ResponseWriter, r *http.Request) {
    body, _ := io.ReadAll(r.Body)
    sig := r.Header.Get("X-RevKeen-Signature")

    event, err := revkeen.Webhooks.Verify(body, sig, os.Getenv("REVKEEN_WEBHOOK_SECRET"))
    if err != nil {
        http.Error(w, "invalid signature", http.StatusBadRequest)
        return
    }

    if event.Type == "invoice.paid" {
        invoice := event.Data.Object.(*revkeen.Invoice)
        fulfil(invoice)
    }

    w.WriteHeader(http.StatusOK)
}

See webhook signing for the wire format.

Error handling

import "errors"

_, err := client.Customers.Retrieve(ctx, "cus_does_not_exist")

var rkErr *revkeen.APIError
if errors.As(err, &rkErr) {
    fmt.Println(rkErr.Code)       // "resource_missing"
    fmt.Println(rkErr.StatusCode) // 404
    fmt.Println(rkErr.RequestID)  // "req_01HT..."
}

See the errors page for the full code table.

Idempotency

import "github.com/google/uuid"

refund, err := client.Refunds.Create(ctx,
    &revkeen.RefundCreateParams{
        Charge:       revkeen.String("ch_01HT..."),
        AmountMinor:  revkeen.Int64(1500),
    },
    revkeen.WithIdempotencyKey(uuid.NewString()),
)

See idempotency for the replay contract.

Retries and timeouts

client := revkeen.NewClient(revkeen.Config{
    APIKey:     os.Getenv("REVKEEN_API_KEY"),
    MaxRetries: 3,                  // default 2
    Timeout:    30 * time.Second,   // default 60s
})

Retries apply to 5xx, 429, and network errors on safe methods. Non-idempotent mutations without an idempotency key never retry.

Compatibility

Go versionStatus
1.21+Supported
1.20Compile only, some features missing
1.19 and earlierNot supported

API version pinned via APIVersion on Config. See versioning.

Resources

On this page