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.Errorwith the API’scode,message, andhint. - Safe defaults. Delete helpers do not run unless
confirmistrue. 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
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 theSITEGPT_API_TOKEN environment variable. Then:
Responses
Every method returnssitegpt.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 noAuthorization 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, andINVALID_PATH_PARAM. For these errors,Statusis0. - 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.
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, andListSources, andConversations.Create,Conversations.Update,Leads.Update,Leads.RunAction,Messages.List,Messages.Update,Onboarding.ClaimWorkspace, andOnboarding.DeleteWorkspace. - v0.4.0 changes
DocumentStats. It now takes aurl.Valuesfilter as the third argument. Code written for v0.3.0 must addnil. - v0.3.0 adds
TakeOverandSwitchToAI. In older versions,Escalatewithnilfails with400.
context.Context first, then the IDs as string values. The other arguments have these types:
- Body fields are a
sitegpt.JSONmap. This applies to every method that sends a body, for exampleCreate,Update, theKnowledge.Add...methods,ResyncDocuments,IngestSource,Escalate, andSend. Use the API’s own field names, incamelCase, as in the OpenAPI document. - If you pass
nilas the body, the SDK sends an empty JSON object. In v0.3.0, this applies only toEscalate,TakeOver, andSwitchToAI. Their only field is an optionalmessage. - Query filters are a
url.Values. This applies toChatbots.Analytics,Knowledge.ListDocuments,Knowledge.DocumentStats,Knowledge.GetDocument,Knowledge.ListSources,Knowledge.ListSyncJobs,Conversations.List,Leads.List, andMessages.List. Passnilfor no filters.DocumentStatstakes the same filters asListDocuments. ForGetDocument, passincludeContent=trueto 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:
403 *sitegpt.Error with the code ANALYTICS_LOCKED. Chatbots.Dashboard works on every plan that includes API access.
Deletes need confirmation
The API needsconfirm=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. Requestdoes 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 readmeta.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:
*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 ishttps://sitegpt.ai by default. It is also in the constant sitegpt.DefaultBaseURL. Change it only if SiteGPT gives you a different API address: