Skip to main content

Authentication & routing

Credentials

Every client needs two credentials:

CredentialWhere to find itSent as
API keySettings → API Keysx-api-key header
Workspace IDSettings → General (UUID v4)workspaceid field on every write, and workspaceid query param on every read

The SDKs inject the workspace ID automatically — you set it once on the client and never pass it per-call.

Three routing domains

ToothFairyAI traffic is served from three endpoints. The SDKs select the right one for you based on the manager/method you call, but it helps to know which is which when reading the per-method Endpoint lines:

DomainDefault base URLUsed forSDK method
Core APIhttps://api.toothfairyai.comCRUD for every resource (agents, chats, documents, …)client.request() / client.request()
AI servicehttps://ai.toothfairyai.comPredictions, planner, agent chat (/agent), search, embeddings, dispatchclient.aiRequest() / client.ai_request()
Streaminghttps://ais.toothfairyai.comServer-Sent Events (SSE) for streaming predictions and agent responsesclient.getStreamingUrl() / client.get_streaming_url()

Each manager page labels its methods with the domain they hit (for example POST /agent/create · API service vs POST /agent · AI streaming service (SSE)).

Node.js client

import { ToothFairyClient } from "@toothfairyai/sdk";

const client = new ToothFairyClient({
apiKey: process.env.TF_API_KEY!,
workspaceId: process.env.TF_WORKSPACE_ID!,
// optional overrides (defaults shown):
baseUrl: "https://api.toothfairyai.com",
aiUrl: "https://ai.toothfairyai.com",
aiStreamUrl: "https://ais.toothfairyai.com",
timeout: 120000, // ms
});

ToothFairyClientConfig fields:

FieldTypeRequiredDescription
apiKeystringyesAPI key sent as x-api-key.
workspaceIdstringyesWorkspace UUID, auto-injected into every request.
baseUrlstringnoCore API base URL. Default https://api.toothfairyai.com.
aiUrlstringnoAI service base URL. Default https://ai.toothfairyai.com.
aiStreamUrlstringnoStreaming base URL. Default https://ais.toothfairyai.com.
timeoutnumbernoRequest timeout in ms. Default 120000.

Errors are thrown as ToothFairyError (with code and status_code); see Error handling.

Python client

from toothfairyai import ToothFairyClient

client = ToothFairyClient(
api_key=os.environ["TF_API_KEY"],
workspace_id=os.environ["TF_WORKSPACE_ID"],
# optional overrides (defaults shown):
base_url="https://api.toothfairyai.com",
ai_url="https://ai.toothfairyai.com",
ai_stream_url="https://ais.toothfairyai.com",
timeout=120,
user_agent=None,
)

ToothFairyClient.__init__ parameters:

ParameterTypeRequiredDescription
api_keystryesAPI key sent as x-api-key. Raises MissingApiKeyError if empty.
workspace_idstryesWorkspace UUID, auto-injected into every request. Raises MissingWorkspaceIdError if empty.
base_urlstrnoCore API base URL. Default https://api.toothfairyai.com.
ai_urlstrnoAI service base URL. Default https://ai.toothfairyai.com.
ai_stream_urlstrnoStreaming base URL. Default https://ais.toothfairyai.com.
timeoutintnoRequest timeout in seconds. Default 120.
user_agentstrnoCustom User-Agent header.

Environment variables

Both CLIs read credentials from the environment so you don't have to pass them on every invocation:

export TF_API_KEY="your-api-key"
export TF_WORKSPACE_ID="your-workspace-id"

The CLIs also accept --apiKey / --workspaceid flags (Node) and --api-key / --workspace-id flags (Python), which override the environment.