> ## Documentation Index
> Fetch the complete documentation index at: https://to11.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

> createClient options, credential resolution, and what the client exposes.

`createClient(options)` is a factory function that returns a client. Call it directly; it is not a class, so do not use `new`.

```ts theme={null}
import { createClient } from "@to11ai/sdk";

const to11 = createClient({
  apiKey: process.env.TO11_API_KEY,
  projectId: process.env.TO11_PROJECT_ID,
});
```

## Credential resolution

Each option resolves with its own precedence, so an app can construct the client from the environment alone:

* `baseUrl` — option → `TO11_API_URL` → `https://api.to11.ai`.
* `apiKey`, `projectId` — option → environment variable (no default).
* `format`, `onUnknownRole` — option only.

Environment variables are read only outside a browser. An option or variable that is empty or only whitespace counts as unset; an explicit empty `apiKey` or `projectId` option throws.

Authenticate with `apiKey`, a to11 [API key](https://to11.ai/docs/platform/api-keys.md). It is required: `createClient` throws without one. The SDK sends it as `Authorization: Bearer <apiKey>` and carries the project in the URL path.

> [!NOTE]
>
> Keep credentials server-side. A to11 API key must never ship in browser code — the SDK throws if you construct a client with `apiKey` in a browser context. Use the SDK from a server, CLI, or backend job.

## Options

| Option | Type | Resolves from | Default |
| - | - | - | - |
| `baseUrl` | `string` | option → `TO11_API_URL` | `https://api.to11.ai` |
| `apiKey` | `string` | option → `TO11_API_KEY` | — (required; throws if constructed in a browser) |
| `projectId` | `string` | option → `TO11_PROJECT_ID` | — (required by `prompts.render()`) |
| `format` | `"openai" \| "anthropic"` | option | — (omit for the neutral render result) |
| `onUnknownRole` | `"drop" \| "warn" \| "error"` | option | `"drop"` |
| `timeoutMs` | `number` | option | `30000` |
| `maxRetries` | `number` | option | `3` |

`maxRetries` applies to network failures, timeouts, and 5xx responses on idempotent requests (`GET`, `PUT`, `DELETE`, and the other methods RFC 9110 calls idempotent). `POST` and `PATCH` are never retried, so a call that creates something cannot run twice.

## What the client exposes

* Resource namespaces `prompts` and `projectEnvironments`. See [Prompt management](https://to11.ai/docs/reference/typescript-sdk/prompts.md).
* Read-only accessors for the resolved config: `baseUrl`, `apiKey`, and `projectId` (or `undefined` when unset). Use `baseUrl` and `projectId` for diagnostics; treat `apiKey` as a secret and never log it.

The `projectId` set here is the default for **every** `prompts.*` method — `render()` and the lifecycle, version, and label calls (`get`, `list`, `getVersion`, `listLabels`, …). Bind it once on the client and omit it per call; pass `projectId` on an individual call only to override. `render()` always uses the client's `projectId`. The `projectEnvironments` methods take `projectId` on every call.

`format` set on the client is the default for every `render()`; a call's own `format` overrides it. See [Rendering prompts](https://to11.ai/docs/reference/typescript-sdk/rendering-prompts.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.