Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.usetitan.app/llms.txt

Use this file to discover all available pages before exploring further.

The Go SDK is an idiomatic Go client for the Titan WhatsApp API. It uses functional options for configuration, accepts a context.Context on every call, and generates all types from the OpenAPI spec into go/types_gen.go. The SDK includes webhook verification and supports both server API keys and client tokens.

Installation

go get github.com/titan-api/titan-sdk-go

Create a client

import titan "github.com/titan-api/titan-sdk-go"

client := titan.NewClient("https://api.example.com", titan.WithAPIKey("titan_..."))
Pass functional options to NewClient to configure authentication, timeouts, or a custom HTTP client. titan.WithAPIKey sets a server API key.
Keep your API key on the server. Use client tokens for restricted or browser-facing clients.

Send a message

resp, err := client.Messages.Send(ctx, "default", titan.SendMessageRequest{
    ChatID: "[email protected]",
    Type:   titan.SendMessageTypeText,
    Text:   ptr("Hello from Go!"),
})
The first argument is a context.Context. The second is the session name. The third is a typed SendMessageRequest struct. All optional pointer fields use helper functions like ptr to convert literal values.

Service domains

The client exposes every Titan API domain as a field. Go uses PascalCase for all field names.
DomainField
Sessionsclient.Sessions
Messagesclient.Messages
Contactsclient.Contacts
Groupsclient.Groups
Channelsclient.Channels
Presenceclient.Presence
Profileclient.Profile
Labelsclient.Labels
Chatsclient.Chats
Webhooksclient.Webhooks
Pairingclient.Pairing
LIDsclient.LIDs
Mediaclient.Media
Client tokensclient.ClientTokens

Webhook verification

Use titan.VerifyWebhook to validate the HMAC-SHA256 signature on incoming webhook deliveries. It returns an error if the signature is invalid.
err := titan.VerifyWebhook(rawBody, signatureHeader, secret)
Pass the raw request body as []byte, the value of the X-Webhook-Signature header as a string, and your webhook secret as a string. Check the returned error before processing the event.
Always verify webhook signatures before processing events. Return a non-2xx status to Titan if verification fails.

Client tokens

To use a short-lived client token instead of a server API key, use titan.WithClientToken:
client := titan.NewClient("...", titan.WithClientToken("titan_ct_..."))

Full client token flow

import titan "github.com/titan-api/titan-sdk-go"

// Server-side: mint a token
server := titan.NewClient("https://api.example.com", titan.WithAPIKey("titan_..."))

resp, _ := server.ClientTokens.Mint(ctx, titan.MintClientTokenRequest{
    Session:     "default",
    EphemeralID: "user-123",
    TTLSeconds:  900,
})

// Browser/restricted client: use the token
browser := titan.NewClient("https://api.example.com", titan.WithClientToken(resp.Token))
See Client tokens for how to configure session rules and control what client tokens are allowed to do.

Types

All request and response types are auto-generated from the OpenAPI spec into go/types_gen.go in the titan-api/sdks monorepo. A GitHub Actions workflow regenerates the file automatically whenever the spec changes. Import types directly from the module:
import titan "github.com/titan-api/titan-sdk-go"

var req titan.SendMessageRequest

Deprecation warnings

The SDK reads Deprecation, Sunset, and Titan-SDK-Deprecation response headers automatically. When any of these headers appear, the SDK logs a warning once per client lifetime using the standard log package:
  • Deprecation: true — the API version you are calling is deprecated.
  • Sunset: <date> — the API version will be removed on the given date.
  • Titan-SDK-Deprecation — your installed module version is outdated.
If you use a structured logger, you can supply a custom logger via titan.WithLogger(...) to capture deprecation warnings in your existing log pipeline.