@sitegpt/sdk is the official SiteGPT client for TypeScript and JavaScript. It calls API v2.
- Typed. Types are generated from the API v2 OpenAPI document. Each convenience method returns the
datatype of its operation. - No dependencies. It uses the global
fetch. It runs on Node.js 18 or later and in other runtimes that havefetch. - Handles the envelope. The API answers with
{ ok, data, meta }. The SDK returnsdata. It throws aSiteGPTErrorwhenokisfalse.
This SDK manages your account from code. To control the chat widget on your website, use the widget SDK.
Install
Quickstart
API access needs the Growth plan or above. See Plans and limits. Create an API token on the Agents page. See Authentication. Then:Agent onboarding without a token
The agent-first onboarding start endpoint needs no token. The response includes a temporary token for the new chatbot:health() also works without a token. Every other call returns 401 until you set apiToken.
Error handling
Every failed call throws aSiteGPTError with the fields of the API error:
Convenience methods
The client also has
sitegpt.me() and sitegpt.health().
conversations.takeOver needs version 0.3.0 or later. It takes over a conversation the same way as the dashboard. See Conversation state conflicts.
Deletes need confirmation
The API needsconfirm=true on delete operations. The SDK sends it only when you pass { confirm: true } as the last argument. These methods need it: chatbots.delete, knowledge.deleteDocument, knowledge.deleteDocuments, knowledge.revokeSource, conversations.delete, and leads.delete. Without it, the SDK throws a CONFIRMATION_REQUIRED error and sends no request.
Other endpoints: request()
Every API v2 operation works through request(path, options). Known paths autocomplete.
requestWithMeta() also returns the envelope meta, including meta.nextCursor for the next page:
OpenAPI types
The package exports the generated typescomponents, operations, and paths, and helper types such as OperationData. It also ships the OpenAPI document as @sitegpt/sdk/openapi.generated.json.
Timeouts
Requests time out after 30 seconds. Change this for the client withtimeoutMs. For one request, pass an AbortSignal. A signal replaces the timeout.
Base URL
baseUrl is https://sitegpt.ai by default. Change it only if SiteGPT gives you a different API address.