Skip to main content
sitegpt-go is the official SiteGPT client for Go. It calls API v2. It works like the TypeScript and Python SDKs, with one difference: it returns the whole response envelope. See Responses.
  • No dependencies. It uses only the Go standard library. It needs Go 1.22 or later.
  • Structured errors. Every non-2xx response returns a *sitegpt.Error with the API’s code, message, and hint.
  • Safe defaults. Delete helpers do not run unless confirm is true. The client removes the token from a redirect that changes the scheme, host, or port.
This SDK manages your account from code. To control the chat widget on your website, use the widget SDK.

Install

The module path is github.com/sitegpt/sitegpt-go. The package name is sitegpt.

Quickstart

API access needs the Growth plan or above. See Plans and limits. Create an API token on the Agents page. See Authentication. Put the token in the SITEGPT_API_TOKEN environment variable. Then:

Responses

Every method returns sitegpt.JSON, which is a map[string]any. It holds the whole API envelope: ok, data, and meta. Read the payload from data. Nested objects are map[string]any and lists are []any, so use type assertions to read them. The TypeScript and Python SDKs return data directly.

Agent onboarding without a token

The agent-first onboarding start endpoint needs no token. Pass an empty token. The client then sends no Authorization header. The response includes a temporary token for the new chatbot:
Onboarding.GetWorkspace(ctx, workspaceID) reads the state of the temporary workspace. Onboarding.ClaimWorkspace claims it for an account, and Onboarding.DeleteWorkspace deletes it. These two methods need v0.4.0 or later. Health also works without a token. Every other call returns 401 until you set a token.

Error handling

Every non-2xx response returns a *sitegpt.Error. Use errors.As to read it:
  • Some errors come from the SDK before it sends a request: CONFIRMATION_REQUIRED, INVALID_PATH, and INVALID_PATH_PARAM. For these errors, Status is 0.
  • Network errors and a 2xx response that is not JSON return a plain error, not a *sitegpt.Error.
  • The SDK does not retry failed requests.
See API conventions for error codes.

Convenience methods

The client also has client.Me(ctx) and client.Health(ctx). The Go SDK has helpers for the same operations as the TypeScript and Python SDKs. Use Request for every other operation. Version notes:
  • v0.4.0 adds 20 methods: the document, source, and sync job methods other than ListDocuments, DocumentStats, and ListSources, and Conversations.Create, Conversations.Update, Leads.Update, Leads.RunAction, Messages.List, Messages.Update, Onboarding.ClaimWorkspace, and Onboarding.DeleteWorkspace.
  • v0.4.0 changes DocumentStats. It now takes a url.Values filter as the third argument. Code written for v0.3.0 must add nil.
  • v0.3.0 adds TakeOver and SwitchToAI. In older versions, Escalate with nil fails with 400.
All methods take a context.Context first, then the IDs as string values. The other arguments have these types:
  • Body fields are a sitegpt.JSON map. This applies to every method that sends a body, for example Create, Update, the Knowledge.Add... methods, ResyncDocuments, IngestSource, Escalate, and Send. Use the API’s own field names, in camelCase, as in the OpenAPI document.
  • If you pass nil as the body, the SDK sends an empty JSON object. In v0.3.0, this applies only to Escalate, TakeOver, and SwitchToAI. Their only field is an optional message.
  • Query filters are a url.Values. This applies to Chatbots.Analytics, Knowledge.ListDocuments, Knowledge.DocumentStats, Knowledge.GetDocument, Knowledge.ListSources, Knowledge.ListSyncJobs, Conversations.List, Leads.List, and Messages.List. Pass nil for no filters. DocumentStats takes the same filters as ListDocuments. For GetDocument, pass includeContent=true to get the full text.

Analytics

Chatbots.Analytics returns the daily engagement series for a chatbot, with totals and a comparison to the previous period. Set the range with startDay and endDay, as YYYY-MM-DD dates in UTC. If you do not set a range, the API uses the last 30 days:
If analytics is not on your plan, the call returns a 403 *sitegpt.Error with the code ANALYTICS_LOCKED. Chatbots.Dashboard works on every plan that includes API access.

Deletes need confirmation

The API needs confirm=true on delete operations. Chatbots.Delete, Conversations.Delete, Leads.Delete, Knowledge.DeleteDocument, Knowledge.DeleteDocuments, and Knowledge.RevokeSource take a confirm bool argument. The SDK sends confirm=true only when you pass true. If you pass false, the SDK returns a CONFIRMATION_REQUIRED error and sends no request. Onboarding.DeleteWorkspace needs no confirmation, because it deletes only a temporary onboarding workspace.

Other endpoints: Request

Every API v2 operation works through Request(ctx, method, path, query, body). query is a url.Values and body is any value that encoding/json can encode. Both can be nil:
  • The path must start with /.
  • The client rejects empty path segments and . or .. segments before it sends the request. A wrong ID cannot change the request to a different route.
  • Request does not escape the path. The convenience methods escape each ID for you.
  • The full contract is the OpenAPI document at sitegpt.ai/api/v2/openapi.json.

Pagination

The SDK has no pagination helper. Because every method returns the whole envelope, you can read meta.nextCursor from the response. Pass it as cursor to get the next page:

Timeouts and custom HTTP clients

Requests time out after 10 seconds by default. To change this, pass your own *http.Client. The SDK keeps its redirect rule, so it still removes the token on a redirect to a different origin:
The client follows up to 10 redirects. If your *http.Client has its own CheckRedirect, the SDK runs that function after it removes the token. For a time limit on one call, use a context:

Base URL

The base URL is https://sitegpt.ai by default. It is also in the constant sitegpt.DefaultBaseURL. Change it only if SiteGPT gives you a different API address: