Go SDK

go get github.com/Glytos/glytos-sdk-go

Requires Go 1.21 or newer. Zero dependencies - the standard library only.

Setup

import glytos "github.com/Glytos/glytos-sdk-go"

client := glytos.New("gly_...")

To act in a specific environment, pass an option - dev, staging, prod, or an environment uuid. Without it, requests use the organization's default environment. A value that matches no environment falls back to the default rather than failing.

client := glytos.New("gly_...", glytos.WithEnvironment("prod"))

Timeouts

The default http.Client has a 30-second Timeout, and Go applies it to the whole exchange, including reading the body. That covers streams too: a streamed turn is cut off 30 seconds after it starts, however steadily it is arriving. A text turn can take longer than that when the model writes a long reply, so pass your own client:

client := glytos.New("gly_...", glytos.WithHTTPClient(&http.Client{Timeout: 3 * time.Minute}))

To bound a single call instead, leave Timeout at zero and use a context deadline.

Text conversations

A thread holds a conversation; a run is one turn on it. The reply is in the result - there is no run to poll. Streaming takes a callback, so it works on Go 1.21 without range-over-func. See Chat.

thread, err := client.Threads.Create(ctx, agentUUID, nil)
run, err := client.Threads.Runs.Create(ctx, *thread, &glytos.TurnParams{
    Content: "What are your opening hours?",
})

err = client.Threads.Runs.Stream(ctx, *thread,
    &glytos.TurnParams{Content: "Summarise the policy"},
    func(e glytos.StreamEvent) error {
        if e.Type == "token" {
            fmt.Print(e.Delta)
        }
        return nil
    })

Agents is an alias of Workflows: the product calls them agents, the API path is /workflows. Either works.

Resources

Every call takes a context.Context, and typed params structs for creates:

ctx := context.Background()

agents, err := client.Workflows.List(ctx, nil)
agent, err := client.Workflows.Create(ctx, glytos.WorkflowCreateParams{
    Name: "Receptionist",
    Mode: "prompt",
})

// Mint a web-call token for the browser (never ship the API key there).
token, err := client.Calls.WebToken(ctx, glytos.WebTokenParams{WorkflowUUID: agent.UUID})

The client covers Agents (alias Workflows), Threads, Folders, Imports, Chat, Calls, PhoneNumbers, SipTrunks, Campaigns, Dnc, Sessions, Webhooks, Tools, KnowledgeBase, VectorStores, Integrations, Automations, TestSuites, Analytics, Billing, Environments, Providers, APIKeys and Organizations.

Anything not wrapped

Reach any endpoint directly, with auth and error handling applied:

var out map[string]any
err := client.Do(ctx, "GET", "/audit", nil, nil, &out)

Verifying webhooks

ok := glytos.VerifyWebhook(rawBody, signatureHeader, secret, glytos.DefaultWebhookTolerance)

rawBody must be the untouched request body - parsing and re-serialising it changes the bytes and the signature will not match. It is also on the client as client.Webhooks.Verify(...). See Webhooks.