# Configuration (/docs/typescript/sdk/client)



## Construct the client [#construct-the-client]

```ts
import { TawaGuard } from "@tawaguard/sdk";

const tawa = await TawaGuard.create(process.env.TAWA_API_KEY!);
```

`TawaGuard.create` authenticates against `/verify` before returning, so a bad
key surfaces at construction time rather than on the first scan call. Once
authenticated, the client resolves your organization's region and talks
**directly** to that region's gateway for every call after that — the
control plane is only touched once.

## Options [#options]

<TypeTable
  id="type-table-sample-types.ts-TawaGuardConfig"
  type="{
  &#x22;id&#x22;: &#x22;sample-types.ts-TawaGuardConfig&#x22;,
  &#x22;name&#x22;: &#x22;TawaGuardConfig&#x22;,
  &#x22;description&#x22;: &#x22;Options for constructing the Tawa client. Every option is optional — see\nthe Configuration page.&#x22;,
  &#x22;entries&#x22;: [
    {
      &#x22;name&#x22;: &#x22;detector&#x22;,
      &#x22;description&#x22;: &#x22;Opaque detector name, reserved for future use. The SDK does not send it\nto the service or interpret it; the service picks the detector.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;string | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;string&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;baseUrl&#x22;,
      &#x22;description&#x22;: &#x22;Override the API base URL. By default the client resolves your org's\nregion on first connect and talks directly to that region's gateway.\nSet this only for local development or a private/on-prem deployment.&#x22;,
      &#x22;tags&#x22;: [
        {
          &#x22;name&#x22;: &#x22;default&#x22;,
          &#x22;text&#x22;: &#x22;\&#x22;https://gateway.tawaguard.com/v1\&#x22;&#x22;
        }
      ],
      &#x22;type&#x22;: &#x22;string | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;string&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    }
  ]
}"
/>

```ts
const tawa = await TawaGuard.create(apiKey, {
  baseUrl: "https://tawa.internal.acme.com/v1", // override the default
});
```

## Custom base URL [#custom-base-url]

Passing `baseUrl` explicitly always wins and disables the automatic region
resolution described above — every call goes to exactly the URL you gave it.

```ts
const tawa = await TawaGuard.create(apiKey, {
  baseUrl: "https://gateway.tawaguard.com/v1",
});
```

<Callout type="warn">
  `TawaGuard.create` always calls `${baseUrl}/verify` first, with no exception
  for a custom `baseUrl` — whatever you point it at must implement that route
  itself. The example above works because the public gateway implements it.
  **Pointing `baseUrl` directly at a bare
  `tawa-gateway` or Tawa Guard worker instance does not currently work** —
  neither implements `/verify`, so construction fails immediately with a 404
  before any scan call is attempted. If you're standing up a private/on-prem
  deployment, your endpoint needs to implement `/verify` (it can be a stub
  that always returns `{ valid: true }` if you're not reusing better-auth's
  API-key model) until this gap is closed.
</Callout>

## Error handling [#error-handling]

All API and network errors throw a `FetchError`:

```ts
import { TawaGuard, FetchError } from "@tawaguard/sdk";

try {
  const tawa = await TawaGuard.create(apiKey);
  const result = await tawa.analyze("user input");
} catch (err) {
  if (err instanceof FetchError) {
    console.error(err.message); // error description
    console.error(err.status); // HTTP status code (or null for network errors)
    console.error(err.retryable); // whether a retry could succeed
  }
}
```

The client retries transient failures (HTTP `429` and `5xx`) automatically,
up to 3 attempts with exponential backoff.
