> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.mitu.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.mitu.ai/_mcp/server.

# Go SDK errors

The Go SDK keeps errors out of your way. Problems with your setup are reported when your program starts, either as an error from `mitu.New` or as a panic from `Charge`. Everything that happens while a request is being handled, from a missing payment to an outage at Mitu, is answered by the middleware itself, and your handler only runs once a payment has settled.

## ErrConfig

```go
var ErrConfig = errors.New("mitu: invalid configuration")
```

`ErrConfig` is the error that every configuration problem wraps. You will meet it in two places.

* **From `mitu.New`.**\
  If your key or default currency is invalid, `New` returns an error wrapping `ErrConfig`.
* **From `Charge`.**\
  If a fixed price is invalid, for example because the amount has three decimal places or the `Price` sets both `Amount` and `AmountFunc`, `Charge` panics with an error wrapping `ErrConfig`.

Use `errors.Is` to recognise it.

```go
m, err := mitu.New(ctx, opts)
if errors.Is(err, mitu.ErrConfig) {
	log.Fatalf("Mitu is misconfigured: %v", err)
}
```

## Responses the SDK sends for you

The table below shows how the middleware answers each kind of request. In every case except the last, your handler does not run.

| Situation                                                                 | What the caller receives                                     |
| ------------------------------------------------------------------------- | ------------------------------------------------------------ |
| The request carries no payment                                            | 402 Payment Required, with MPP and x402 payment options      |
| The payment was made for a different route, method, amount or currency    | A new 402 for this route and price                           |
| Mitu refuses the payment                                                  | Mitu's response, passed on unchanged                         |
| Mitu is unreachable, rate limiting or failing                             | 503 Service Unavailable, with a Retry-After header           |
| Mitu refuses a call from the SDK, for example because the key was revoked | 500 Internal Server Error, with the cause written to the log |
| `AmountFunc` returns an error or an invalid amount                        | 500 Internal Server Error                                    |
| The payment has settled                                                   | Your response, with the payment receipt in its headers       |

An outage at Mitu never causes a route to be served unpaid. The caller is told to try again later instead.

## Recommended handling

* **Fail fast at startup.**\
  Treat an `ErrConfig` from `mitu.New` as fatal, and register your routes when the program starts. That way an invalid price causes a panic before you serve any traffic, rather than surprising you later.
* **Keep an eye on 500 responses.**\
  A 500 from a charged route usually means your key needs attention. Pass a `Logger` in `Options` so that the cause is recorded and you can act on it quickly.
* **Never charge twice for one result.**\
  Once a payment has settled it is final. If your handler fails after the caller has paid, retry the work or refund the payment instead of asking the caller to pay again.