> 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.

# TypeScript SDK configuration

You configure the SDK once, when you call `createMitu`. The function checks your options straight away, so a mistake such as a malformed key or an unknown currency stops your server at startup with a [`MituConfigError`](/sdks/typescript/errors), rather than surfacing on the first paying request. Creating the client does not contact Mitu, so your server can start even if Mitu happens to be unreachable at that moment.

```ts
import { createMitu } from '@mitulabs/payments'

const mitu = createMitu({
  apiKey: process.env.MITU_API_KEY!,
  defaultCurrency: 'USD',
  logger: console,
})
```

## Options

| Option            | Type           | Description                                                                                            |
| ----------------- | -------------- | ------------------------------------------------------------------------------------------------------ |
| `apiKey`          | `string`       | Required. Your Mitu secret key, either a test key or a live key. It is only ever sent to the Mitu API. |
| `defaultCurrency` | `string`       | Optional, defaults to USD. The currency used for any price that does not name its own.                 |
| `logger`          | `Logger`       | Optional, silent by default. An object that receives the SDK's log messages.                           |
| `fetch`           | `typeof fetch` | Optional, defaults to the global `fetch`. The function the SDK uses to make its calls to Mitu.         |

## Sandbox and production

Your key decides which Mitu environment the SDK connects to, so there is no separate environment setting.

| Key      | Environment | Mitu API address                                   |
| -------- | ----------- | -------------------------------------------------- |
| Test key | Sandbox     | [https://sandbox.mitu.ai](https://sandbox.mitu.ai) |
| Live key | Production  | [https://api.mitu.ai](https://api.mitu.ai)         |

Use a sandbox key while you develop and test, and switch to a live key when you are ready to accept real payments. Any value that is not a valid Mitu key causes `createMitu` to throw a `MituConfigError`. Load the key from an environment variable or a secret manager, and never commit it to source control.

## Default currency

Most APIs price everything in one currency. Setting `defaultCurrency` means you only have to write the amount for each route. A route can still name a different currency when it needs to.

```ts
const mitu = createMitu({ apiKey: process.env.MITU_API_KEY!, defaultCurrency: 'NGN' })

charge(mitu, { amount: '2500' }) // charges 2,500 NGN
charge(mitu, { amount: '0.05', currency: 'USD' }) // charges 0.05 USD instead
```

A currency is written as a short code such as USD or NGN, and the SDK converts it to upper case for you. The currency must be enabled on your Mitu account. When a route is priced in a currency other than the one the caller pays in, Mitu converts the amount at a rate it locks when the payment is created.

## Logging

The SDK is silent unless you give it a logger. Any object with `debug`, `info`, `warn` and `error` methods will work, which includes the built-in `console` and most logging libraries.

```ts
interface Logger {
  debug(message: string, fields?: Record<string, unknown>): void
  info(message: string, fields?: Record<string, unknown>): void
  warn(message: string, fields?: Record<string, unknown>): void
  error(message: string, fields?: Record<string, unknown>): void
}
```

The SDK takes care never to log anything sensitive. Its messages never include your API key, a payment credential, a receipt, or the body of a request or response.

## Custom fetch

By default the SDK uses the global `fetch` to call Mitu. You can pass your own function instead, which is useful when you want to add tracing to outgoing calls or replace Mitu with a stub in your tests.

```ts
const mitu = createMitu({
  apiKey: process.env.MITU_API_KEY!,
  fetch: (input, init) => tracedFetch(input, init),
})
```