Mitu SDKs
The Mitu SDKs let you charge for an API one request at a time. You add the SDK to a route and give that route a price. When a request arrives without payment, the SDK replies with 402 Payment Required and tells the caller how to pay using the Machine Payments Protocol (MPP) or x402. Once the caller has paid, the request continues to your code as it normally would, and the response carries a receipt for the payment.
This model suits software that pays for software. An AI agent that needs your search results, a data feed or a model inference can pay for exactly what it uses, without creating an account, storing an API key or waiting for an invoice. You keep your existing API and your existing framework. The SDK sits in front of the routes you choose and handles the payment conversation on your behalf.
There is an SDK for TypeScript, Python and Go. All three use the same Mitu payment API and behave in the same way, so everything on this page applies whichever language you work in.
Installing an SDK
All three SDKs are open source under the MIT licence. Each one needs a Mitu secret key, which you can create in the dashboard under Keys and secrets.
How the SDK and Mitu work together
The SDK runs in your backend, the server code behind your API, and attaches to the routes you choose to charge for, much like authentication or rate limiting. Every request to a priced route passes through the SDK before it reaches your handler.
The SDK and Mitu each play a separate part in every payment.
- The SDK works inside your backend.
When a request arrives without payment, the SDK asks Mitu to create a payment for that route and replies to the caller with 402 Payment Required, which includes the price and the accepted payment methods. When the caller retries with proof of payment, the SDK checks that the payment was made for that exact route and price, then passes it to Mitu to be settled. Your handler only runs once Mitu confirms the payment. - Mitu handles the payment itself.
Mitu creates the payment, verifies the proof the caller sends and settles it onchain, at an exchange rate that was locked when the payment was created. When the payment is final, Mitu sends apayment.completedwebhook to your backend so you can record it.
Your backend never has to decide whether a payment is genuine. That check always happens at Mitu, and your handler runs only after it has passed.
Callers can pay with any standard MPP or x402 client, including an agent wallet, using the payment methods enabled on your Mitu account.
Safety built into every SDK
Every SDK applies the same protections, so you do not need to build them yourself.
- No payment is accepted without Mitu’s confirmation.
Your handler runs only after Mitu has verified and settled the payment. A credential that Mitu rejects never reaches your code. - A payment unlocks one route at one price.
Each payment is tied to the method, path, amount and currency it was created for. A caller cannot pay a small amount on a cheap endpoint and reuse that payment on an expensive one. - An outage never gives your API away for free.
If Mitu cannot be reached, the route replies with 503 Service Unavailable and a Retry-After header. It does not fall back to serving the request unpaid. - Your secret key stays private.
The key is sent only to the Mitu API. It is never forwarded to payment endpoints, written to logs or included in error messages. - Only payment data crosses the boundary.
The SDK sends Mitu nothing but the payment credential, and returns nothing to the caller but payment headers.
Pricing your routes
You set each route’s price on your own server. A price can be a fixed amount, such as 0.05 USD for every search, or it can be worked out from the request, so that a premium plan costs more than a basic one. Amounts must be greater than zero and can have at most two decimal places.
Prices can be in USD or in any other currency enabled on your account. When a price is in another currency, Mitu converts it at a rate that is locked when the payment is created, so the amount the caller is asked for and the amount you receive always agree. A price can also be set to nothing for a particular request, in which case that request is served free and no payment is created.
Sandbox and production
Your secret key decides which environment the SDK talks to, with a test key connecting to the sandbox, where you can build and test without moving real money, and a live key connecting to production. There is no separate setting to change, so moving to production is a matter of swapping the key.