Skip to main content
The Monigo Go SDK (github.com/monigo-africa/go-monigo) is a thin, zero-dependency wrapper around the Monigo REST API. It follows the same resource-based structure as the REST API and uses functional options for configuration — familiar to anyone who has used the Stripe or Plaid Go SDKs.

Installation

Requires Go 1.25 or later. No third-party dependencies — the SDK uses only the Go standard library.

Quick start

Use a test-mode API key (mk_test_...) during development. Test events are isolated from live data and won’t trigger real charges.

Client configuration

Default client

The default client sends requests to https://api.monigo.co with a standard http.Client and no timeout. For production use, always set a timeout.

Custom base URL

For self-hosted deployments or a local development server:

Idempotency

Every POST, PUT, and PATCH request to the Monigo API must include an Idempotency-Key header. The SDK handles this automatically — a UUID v4 is generated for each request. To supply your own key (recommended for retryable operations), pass WithIdempotencyKey:
For critical mutations (subscription creation, invoice finalization) pass a key derived from your own request ID. Retrying with the same key is safe — the server will return the original response without applying the operation twice.

Error handling

All methods return a standard error. When the API responds with a 4xx or 5xx status, the error is an *APIError with a status code, message, and optional field-level details.

Sentinel helpers

Instead of inspecting status codes manually, use the provided helpers:

Events

The client.Events service handles usage event ingestion and event replay.

Ingest events

The server deduplicates events by idempotency_key. Sending the same key twice is safe — the second call will appear in resp.Duplicates and won’t be counted again. A single Ingest call can contain up to 1,000 events.

Replay events

Replay reprocesses all events in a time window through the metering pipeline. This corrects rollups after an outage or after a metric definition change.

Customers

Set ExternalID to your own system’s user ID. This makes it easy to look up a customer without storing Monigo’s UUID separately.

Metrics

A metric defines what gets counted (e.g. “API calls”, “GB stored”) and how the raw event values are aggregated.

Plans

A plan combines billing period, currency, and one or more prices. Each price links a metric to a pricing model.

Pricing models

Plan types and billing periods

Subscriptions

A subscription links a customer to a plan and defines the current billing period.
A customer can have at most one active subscription per plan type. A customer may hold one active collection subscription and one active payout subscription simultaneously, but attempting to create a second active subscription of the same type returns a 409 conflict — check with monigo.IsConflict(err).

Payout accounts

Payout accounts are bank or mobile-money accounts that a customer can receive payouts to. They are scoped to a customer.

Invoices

Invoices are generated from subscriptions and contain line items derived from the customer’s usage in that billing period.
All monetary amounts (Subtotal, VATAmount, Total, UnitPrice) are returned as decimal strings (e.g. "1500.00") to preserve precision across currencies.

Usage

Query aggregated usage rollups to see how much a customer has consumed in a period.

Portal tokens

Portal tokens grant an end-customer read-only access to their invoices, payout slips, subscriptions, and payout accounts in the Monigo hosted portal. The PortalURL field of the returned token is what you share with your customer — embed it in an email, redirect the browser, or open it inside an iframe.
Set ExpiresAt (RFC3339) for a time-limited link:

List tokens for a customer

customerID accepts either a Monigo UUID or the customer’s ExternalID.

Revoke a token

Revocation is immediate. Any customer holding the corresponding URL will receive a 401 on their next request.
Portal tokens are opaque 64-character hex strings stored in the database — not JWTs — so they can be instantly revoked without waiting for an expiry timestamp.

Wallets

Customer wallets hold prepaid balances. They are the foundation of Prepaid Billing and can also be used for any credit/debit workflow. See the full Wallet Management guide for details.

Wallet constants

All wallet amounts (Balance, ReservedBalance, ledger Amount) are decimal strings to preserve precision.

Example programs

The SDK ships with seven runnable example programs under examples/: Run any example by setting MONIGO_API_KEY and executing:

Testing

The SDK has 77 unit tests with zero external dependencies. Each test spins up an in-process mock HTTP server via net/http/httptest:
To run tests in your own project against a local Monigo server, point WithBaseURL at it: