createClient(options) is a factory function that returns a client. Call it directly; it is not a class, so do not use new.
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.
apiKey or projectId option throws.
Authenticate with apiKey, a to11 API key. It is required: createClient throws without one. The SDK sends it as Authorization: Bearer <apiKey> and carries the project in the URL path.
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
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
promptsandprojectEnvironments. See Prompt management. - Read-only accessors for the resolved config:
baseUrl,apiKey, andprojectId(orundefinedwhen unset). UsebaseUrlandprojectIdfor diagnostics; treatapiKeyas a secret and never log it.
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.