---
docId: doc_8a96e902bfcd4865a028a6f1fe3039d7
title: The client
description: "Configure the client: credentials, URL, workspace, timeouts, retries and per-call options."
sidebarTitle: The client
---

# The client

Create a client with `new Platic({ apiKey })` and reuse it for your calls. `apiKey` is the only required option.

```ts
import { Platic } from "platic-sdk";

const platic = new Platic({
  apiKey: process.env.PLATIC_API_KEY!,
  timeoutMs: 20_000,
  maxRetries: 3,
});
```

## Options

| Option | Default | Description |
|---|---|---|
| `apiKey` | required | An API key (`pl_key_…`) or an OAuth access token (`pl_at_…`), sent as `Authorization: Bearer`. |
| `baseUrl` | `https://api.platic.ai` | Root of the API, without `/v1`. Must be `https://`. Plain `http://` is accepted only for `localhost`, `127.0.0.1` and `[::1]`. |
| `workspace` | none | The workspace every call acts on, for a credential that covers several. See [Workspace](#workspace). |
| `timeoutMs` | `30000` | Time limit of each attempt, in milliseconds. Some calls wait longer by default. See [Timeouts](#timeouts). |
| `maxRetries` | `2` | Retries after the first attempt, from 0 to 10. See [Retries](/sdk/retries). |
| `retryDelayMs` | `500` | First wait between attempts. It doubles each time, with jitter. |
| `maxRetryDelayMs` | `8000` | Longest wait between attempts. A `Retry-After` longer than this is not waited for: the error is thrown. |
| `fetch` | global `fetch` | Your own `fetch`, for a proxy or for tests. |
| `dangerouslyAllowBrowser` | `false` | Lets the client start in a browser. See [Browsers](#browsers). |

An invalid option throws `PlaticUsageError` when you create the client, before anything is sent.

## Base URL

The default is production, `https://api.platic.ai`. Pass the root without `/v1`:

```ts
const platic = new Platic({
  apiKey: process.env.PLATIC_API_KEY!,
  baseUrl: "http://localhost:8080", // a local server or proxy
});
```

The client does not send the key over plain `http://` to another machine or follow redirects. A 3xx response throws `PlaticApiError` with `code: "UNEXPECTED_REDIRECT"`. Check `baseUrl`: this usually means it points to a website or proxy instead of the API.

## Workspace

If your credential covers several workspaces, use `platic.workspaces.list()` to get their ids. The `requires_workspace_argument` field says whether you need to choose one.

Set `workspace` on the client to add `?workspace=<id>` to every call.

```ts
const { workspaces } = await platic.workspaces.list();

const acme = new Platic({
  apiKey: process.env.PLATIC_OAUTH_TOKEN!,
  workspace: workspaces[0]!.id,
});
```

If an operation requires you to choose a workspace and you omit it, you get `InvalidRequestError`. Find the available ids in `error.details.available`. Some reads, such as listing contacts or their conversations, let you omit it and query the authorized workspaces. `platic.conversations` always works in one workspace: the `workspace` option, or the credential's only one. The API rejects a workspace the credential cannot access. See [Workspaces](/api-reference/workspaces).

## Per-call options

Every method takes `{ signal, timeoutMs, maxRetries }` as its last argument. They apply to that call only.

```ts
const agent = await platic.agents.get(agentId, { timeoutMs: 5_000, maxRetries: 0 });
```

| Option | What it does |
|---|---|
| `signal` | An `AbortSignal`. An aborted call stops at once, is not retried and throws `PlaticAbortError`. |
| `timeoutMs` | Replaces the client's `timeoutMs` for this call. |
| `maxRetries` | Replaces the client's `maxRetries` for this call. |

```ts
const page = await platic.clients.list({ limit: 20 }, { signal: AbortSignal.timeout(5_000) });
```

## Timeouts

`timeoutMs` limits each attempt to 30 seconds by default. These operations get more time unless you set your own `timeoutMs`:

| Call | Default wait |
|---|---|
| Testing a custom API, creating or testing an MCP server, creating, changing or testing a webhook, sending a campaign, installing an agent template | 120 seconds |
| Choosing what a channel connection installs, disconnecting or deleting a channel, searching conversations | 130 seconds |
| Creating, changing, publishing or deleting a web chat; acting on a comment; testing a database, reading its schema or querying it | 70 seconds |
| Connecting or verifying an AI provider's key | 210 seconds |
| A chat turn (`chat.send`) | 550 seconds |

`files.waitForJob`, `agents.evals.runs.wait` and `channels.connections.wait` check the status until the job finishes. For these methods, `timeoutMs` limits the total wait: 10, 30 and 60 minutes by default, respectively. If it expires, they throw an error with the last status read. The job continues.

## Custom fetch

Pass your own `fetch` to route requests through a proxy, add logging or test without a network:

```ts
import { ProxyAgent, fetch as undiciFetch } from "undici";

const dispatcher = new ProxyAgent("http://proxy.internal:3128");

const platic = new Platic({
  apiKey: process.env.PLATIC_API_KEY!,
  fetch: ((input, init) => undiciFetch(input as never, { ...(init as object), dispatcher })) as typeof fetch,
});
```

The client calls your `fetch` with `redirect: "manual"` and an `AbortSignal` of its own. Keep both when you wrap it.

## Browsers

The client does not start in environments with `window` and `document`: anyone opening the page could read the key. Call the API from your server. Use `dangerouslyAllowBrowser: true` only in tests that define those globals or in an internal tool whose users already hold the key.

## Keeping the key safe

- It is sent to `baseUrl` over HTTPS. HTTP is allowed only for `localhost`, `127.0.0.1` and `[::1]`.
- If a response or network error includes the key, the SDK replaces it with `[REDACTED]`. It also hides secret values sent by a call.
- `console.log(platica)` does not show it.

## Next steps

- [Pagination](/sdk/pagination)
- [Errors](/sdk/errors)
- [Retries](/sdk/retries)
- [Authentication](/authentication)
