> ## Documentation Index
> Fetch the complete documentation index at: https://qawolf-mintlify-79e74a8b.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Client Reference

> Reference notes for runtime-facing client creation and configuration.

Runtime-facing APIs include:

* `createEmailsClient(...)`
* `configureEmailsClient(...)`
* `getCurrentEmailsClient(...)`
* `resetEmailsClient(...)`
* `buildGetInboxFn(...)`

Example:

```ts theme={null}
import { configureEmailsClient, createEmailsClient } from "@qawolf/emails";

const client = await createEmailsClient({
  apiKey: process.env["QAWOLF_API_KEY"]!,
  pollForEmailsDefaultTimeoutMs: 30_000,
  teamId: "team_123",
  url: "https://app.qawolf.com/api",
  waitForMessagesDefaultDelayMs: 1_000,
});

configureEmailsClient(client);
```

## `EmailsClientOptions`

`createEmailsClient(...)` accepts one of two transport configurations.

Use the QA Wolf API configuration for new code:

```ts theme={null}
const client = await createEmailsClient({
  apiKey: process.env["QAWOLF_API_KEY"]!,
  pollForEmailsDefaultTimeoutMs: 30_000,
  teamId: "team_123",
  url: "https://app.qawolf.com/api",
  waitForMessagesDefaultDelayMs: 1_000,
});
```

The client also supports an internal runner configuration:

```ts theme={null}
const client = await createEmailsClient({
  emailerUrl: process.env["EMAILER_URL"]!,
  pollForEmailsDefaultTimeoutMs: 30_000,
  teamId: "team_123",
  waitForMessagesDefaultDelayMs: 1_000,
});
```

Do not pass both configurations at the same time. If you use `apiKey` and
`url`, do not pass `emailerUrl`.

```ts theme={null}
type EmailsClientOptions =
  | {
      apiKey: string;
      emailerUrl?: never;
      logger?: (severity: string, message: string) => void;
      pollForEmailsDefaultTimeoutMs: number;
      teamId?: string;
      url: string;
      waitForMessagesDefaultDelayMs: number;
    }
  | {
      apiKey?: never;
      emailerUrl: string;
      logger?: (severity: string, message: string) => void;
      pollForEmailsDefaultTimeoutMs: number;
      teamId?: string;
      url?: never;
      waitForMessagesDefaultDelayMs: number;
    };
```

## Role Of `createEmailsClient(...)`

This creates a service-backed client that can be used directly by local
harnesses, tooling, or other runtime environments.

Example:

```ts theme={null}
import { createEmailsClient } from "@qawolf/emails";

const client = await createEmailsClient({
  apiKey: process.env["QAWOLF_API_KEY"]!,
  logger: (severity, message) => {
    console.log(severity, message);
  },
  pollForEmailsDefaultTimeoutMs: 30_000,
  teamId: "team_123",
  url: "https://app.qawolf.com/api",
  waitForMessagesDefaultDelayMs: 1_000,
});

const inbox = await client.getInbox({ new: true });
```

## Compatibility Note

`buildGetInboxFn(...)` remains useful for compatibility with runtimes that still
inject `getInbox` directly, but new runtime code should prefer
`createEmailsClient(...)`.

Example:

```ts theme={null}
import { buildGetInboxFn } from "@qawolf/emails";

const getInbox = await buildGetInboxFn({
  apiKey: process.env["QAWOLF_API_KEY"]!,
  pollForEmailsDefaultTimeoutMs: 30_000,
  teamId: "team_123",
  url: "https://app.qawolf.com/api",
  waitForMessagesDefaultDelayMs: 1_000,
});

const inbox = await getInbox({ new: true });
```
