Skip to main content

Go SDK API reference

Full API reference for the Agora Conversational AI Go SDK.

client.NewClient

The entry point for the SDK. Creates a new API client with the given request options. All sub-clients share the same configuration.


_4
import (
_4
"github.com/AgoraIO-Conversational-AI/agent-server-sdk-go/client"
_4
"github.com/AgoraIO-Conversational-AI/agent-server-sdk-go/option"
_4
)

Constructor


_1
func NewClient(opts ...option.RequestOption) *Client

Pass one or more request options to configure authentication, regional routing, and transport behavior.


_3
c := client.NewClient(
_3
option.WithToken("<your_rest_auth_token>"),
_3
)

When using the agentkit layer, your App ID and App Certificate are passed on AgentSessionOptions — not on the client. See agentkit.NewAgentSession.

Request options

Request options can be set at client creation time (applied to all requests) or passed to individual method calls.

option.WithToken


_1
func WithToken(token string) *core.TokenOption

Sets a bearer token for authentication. This is the recommended option for new integrations and matches the onboarding guides.


_3
c := client.NewClient(
_3
option.WithToken("<your_rest_auth_token>"),
_3
)

option.WithBasicAuth


_1
func WithBasicAuth(username, password string) *core.BasicAuthOption

Sets Authorization: Basic <base64>. Use your Agora Customer ID and Customer Secret from Agora Console.

Use this only when you explicitly want Basic Auth. It is still supported by the client, but token auth is the preferred path in the narrative docs and quick starts.


_3
c := client.NewClient(
_3
option.WithBasicAuth("<customer_id>", "<customer_secret>"),
_3
)

option.WithArea


_1
func WithArea(area core.Area) *core.AreaRequestOption

Enables regional routing with automatic DNS-based domain selection.


_3
c := client.NewClient(
_3
option.WithArea(option.AreaUS),
_3
)

option.WithBaseURL


_1
func WithBaseURL(baseURL string) *core.BaseURLOption

Overrides the default API endpoint. Useful for testing.


_5
import Agora "github.com/AgoraIO-Conversational-AI/agent-server-sdk-go"
_5
_5
c := client.NewClient(
_5
option.WithBaseURL(Agora.Environments.Default),
_5
)

option.WithHTTPClient


_1
func WithHTTPClient(httpClient core.HTTPClient) *core.HTTPClientOption

Provides a custom *http.Client. Recommended for production to set timeouts.


_5
c := client.NewClient(
_5
option.WithHTTPClient(&http.Client{
_5
Timeout: 10 * time.Second,
_5
}),
_5
)

option.WithMaxAttempts


_1
func WithMaxAttempts(attempts uint) *core.MaxAttemptsOption

Sets the maximum number of retry attempts. Default: 2. Retries use exponential backoff for status codes 408, 429, and 5xx.


_3
c := client.NewClient(
_3
option.WithMaxAttempts(3),
_3
)

option.WithHTTPHeader


_1
func WithHTTPHeader(httpHeader http.Header) *core.HTTPHeaderOption

Adds custom HTTP headers to every request.

option.WithBodyProperties


_1
func WithBodyProperties(bodyProperties map[string]interface{}) *core.BodyPropertiesOption

Adds extra properties to the JSON request body.

option.WithQueryParameters


_1
func WithQueryParameters(queryParameters url.Values) *core.QueryParametersOption

Adds query parameters to the request URL.

option.WithPool


_1
func WithPool(pool *core.Pool) *core.AreaRequestOption

Uses a pre-configured Pool for regional routing.

Sub-clients

client.NewClient exposes Fern-generated sub-clients for direct REST API access. You typically do not need these when using the agentkit layer.

FieldTypeDescription
c.Agents*agents.ClientAgent lifecycle (start, stop, speak, interrupt, update, get, getHistory)
c.Telephony*telephony.ClientTelephony operations (call, hangup)
c.PhoneNumbers*phonenumbers.ClientPhone number management

All sub-client methods take context.Context as their first argument. See the generated reference for full method signatures.

Environments

The root Agora package exposes the default API endpoint:


_4
import Agora "github.com/AgoraIO-Conversational-AI/agent-server-sdk-go"
_4
_4
Agora.Environments.Default
_4
// "https://api.agora.io/api/conversational-ai-agent"

Pointer helpers

The root Agora package provides helper functions for creating pointers to literal values. These are required for optional fields in Fern-generated request structs, which use pointer types to distinguish between "not set" and "set to zero value".


_1
import Agora "github.com/AgoraIO-Conversational-AI/agent-server-sdk-go"

FunctionSignatureExample
Agora.Boolfunc(bool) *boolEnable: Agora.Bool(true)
Agora.Intfunc(int) *intIdleTimeout: Agora.Int(120)
Agora.Stringfunc(string) *stringAPIKey: Agora.String("<key>")
Agora.Float64func(float64) *float64Threshold: Agora.Float64(0.5)
Agora.Float32func(float32) *float32
Agora.Int8 / Int16 / Int32 / Int64func(intN) *intN
Agora.Uint / Uint8 / Uint16 / Uint32 / Uint64func(uintN) *uintN
Agora.UUIDfunc(uuid.UUID) *uuid.UUID
Agora.Timefunc(time.Time) *time.Time

agentkit.NewAgent

Agent is an immutable configuration object. Each vendor chaining method returns a new *Agent — the original is never modified. Define one agent at startup and create sessions from it for each user conversation.


_4
import (
_4
"github.com/AgoraIO-Conversational-AI/agent-server-sdk-go/agentkit"
_4
"github.com/AgoraIO-Conversational-AI/agent-server-sdk-go/agentkit/vendors"
_4
)

Constructor


_1
func NewAgent(opts ...AgentOption) *Agent

Pass AgentOption functions to configure the agent's name, instructions, greeting, and other properties.


_6
agent := agentkit.NewAgent(
_6
agentkit.WithName("support-assistant"),
_6
agentkit.WithInstructions("You are a helpful voice assistant."), // LLM system prompt
_6
agentkit.WithGreeting("Hello! How can I help you today?"), // first words spoken on session start
_6
agentkit.WithMaxHistory(10),
_6
)

AgentOption functions

AgentOption functions are passed to NewAgent. Each function has the signature func(*Agent).

FunctionParameter typeDescription
WithName(name)stringAgent name identifier
WithInstructions(instructions)stringLLM system prompt
WithGreeting(greeting)stringFirst message the agent speaks
WithFailureMessage(msg)stringMessage spoken when the LLM fails
WithMaxHistory(n)intMaximum conversation turns to retain
WithTurnDetectionConfig(td)*TurnDetectionConfigCascading-flow turn detection configuration. Use Config.StartOfSpeech and Config.EndOfSpeech for SOS/EOS detection. Use interruption config for interruption behavior and MLLM vendor TurnDetection for MLLM turn detection
WithInterruptionConfig(interruption)*InterruptionConfigUnified interruption control using the top-level interruption object
WithSalConfig(sal)*SalConfigSpeech analytics configuration
WithAdvancedFeatures(af)*AdvancedFeaturesAdvanced feature flags, for example EnableMllm, EnableAivad
WithTools(enabled)boolEnable or disable MCP tool invocation
WithParameters(params)*SessionParamsAdditional session parameters
WithGeofence(gf)*GeofenceConfigRegional access restriction
WithLabels(labels)map[string]stringCustom key-value labels returned in notification callbacks
WithRtc(rtc)*RtcConfigRTC media encryption
WithFillerWords(fw)*FillerWordsConfigFiller words played while waiting for the LLM response

Vendor chaining methods

Vendor methods are called on the *Agent returned by NewAgent. Each method returns a new *Agent — the original is never modified.

WithLlm(vendor)

Sets the LLM vendor. Pass an instance of NewOpenAI, NewAzureOpenAI, NewAnthropic, or NewGemini.


_1
func (a *Agent) WithLlm(vendor vendors.LLM) *Agent

WithTts(vendor)

Sets the TTS vendor. Captures the vendor's sample rate for avatar validation.


_1
func (a *Agent) WithTts(vendor vendors.TTS) *Agent

WithStt(vendor)

Sets the STT vendor. Pass an instance of any STT vendor constructor.


_1
func (a *Agent) WithStt(vendor vendors.STT) *Agent

WithMllm(vendor)

Sets the MLLM vendor for multimodal mode. Pass NewOpenAIRealtime, NewGeminiLive, or NewVertexAI. Requires AdvancedFeatures.EnableMllm = true.


_1
func (a *Agent) WithMllm(vendor vendors.MLLM) *Agent

WithAvatar(vendor)

Sets the avatar vendor. Panics if TTS is already configured with a sample rate that does not match the avatar's required rate.


_1
func (a *Agent) WithAvatar(vendor vendors.Avatar) *Agent

WithTurnDetection(config)

Configures cascading-flow turn detection. Use Config.StartOfSpeech and Config.EndOfSpeech for SOS/EOS detection. Use interruption config for interruption behavior and MLLM vendor TurnDetection for MLLM turn detection.


_1
func (a *Agent) WithTurnDetection(td *TurnDetectionConfig) *Agent

Other builder methods

The following methods follow the same pattern — each returns a new *Agent with the updated configuration.

MethodParameter typeDescription
WithInstructions(instructions)stringOverride the LLM system prompt
WithGreeting(greeting)stringOverride the greeting message
WithName(name)stringOverride the agent name
WithSal(sal)*SalConfigSet SAL configuration
WithAdvancedFeatures(af)*AdvancedFeaturesSet advanced features
WithTools(enabled)boolEnable or disable MCP tool invocation
WithParameters(params)*SessionParamsSet session parameters
WithFailureMessage(msg)stringSet the failure message
WithMaxHistory(n)intSet the maximum conversation history length
WithGeofence(gf)*GeofenceConfigSet geofence configuration
WithLabels(labels)map[string]stringSet custom labels
WithRtc(rtc)*RtcConfigSet RTC configuration
WithFillerWords(fw)*FillerWordsConfigSet filler words configuration

ToProperties()

Converts the agent configuration to a *Agora.StartAgentsRequestProperties for direct use with the low-level client. Called internally by AgentSession.Start(). Use this directly when building custom request bodies.


_1
func (a *Agent) ToProperties(opts ToPropertiesOptions) (*Agora.StartAgentsRequestProperties, error)

Returns an error if:

  • Neither Token nor AppID + AppCertificate is provided
  • In cascading mode: LLM or TTS is not configured
  • Config marshaling fails

ToPropertiesOptions

FieldTypeRequiredDescription
ChannelstringYesAgora channel name
AgentUIDstringYesAgent's UID in the channel
RemoteUIDs[]stringYesRemote participant UIDs
TokenstringConditionalPre-generated RTC+RTM token. Skips generation if set
AppIDstringConditionalAgora App ID. Required if Token is not set
AppCertificatestringConditionalAgora App Certificate. Required if Token is not set
ExpiresInintNoToken lifetime in seconds. Default: 86400. Valid range: 1–86400
IdleTimeout*intNoSession idle timeout in seconds
EnableStringUID*boolNoEnable string UID mode

Getters

Read-only methods available on any *Agent instance.

MethodReturn typeDescription
Name()stringAgent name
Instructions()stringLLM system prompt
Greeting()stringGreeting message
FailureMessage()stringMessage spoken when LLM fails
MaxHistory()*intMaximum conversation history length
LlmConfig()map[string]interface{}LLM configuration
TtsConfig()map[string]interface{}TTS configuration
SttConfig()map[string]interface{}STT configuration
MllmConfig()map[string]interface{}MLLM configuration
TtsSampleRate()*vendors.SampleRateTTS sample rate
AvatarRequiredSampleRate()*vendors.SampleRateAvatar required sample rate
Avatar()map[string]interface{}Avatar configuration
TurnDetection()*TurnDetectionConfigTurn detection configuration
Sal()*SalConfigSAL configuration
AdvancedFeatures()*AdvancedFeaturesAdvanced features
Parameters()*SessionParamsSession parameters
Geofence()*GeofenceConfigGeofence configuration
Labels()map[string]stringCustom labels
Rtc()*RtcConfigRTC configuration
FillerWords()*FillerWordsConfigFiller words configuration

agentkit.NewAgentSession

AgentSession manages the full lifecycle of a running agent. Create a session with NewAgentSession and call Start() to join the agent to the channel.


_1
import "github.com/AgoraIO-Conversational-AI/agent-server-sdk-go/agentkit"

Constructor


_1
func NewAgentSession(opts AgentSessionOptions) *AgentSession

If Name is empty, defaults to agent-<unix_timestamp>. The session starts in StatusIdle.

AgentSessionOptions

FieldTypeRequiredDescription
Client*agents.ClientYesFern-generated agents sub-client. Pass c.Agents from client.NewClient
Agent*AgentYesAgent configuration built with NewAgent
AppIDstringYesAgora App ID
AppCertificatestringConditionalRequired if Token is not set
NamestringNoSession name. Default: agent-<unix_timestamp>
ChannelstringYesAgora channel name
TokenstringConditionalPre-generated RTC+RTM token. Skips auto-generation if set
AgentUIDstringYesAgent's UID in the channel
RemoteUIDs[]stringYesRemote participant UIDs
IdleTimeout*intNoIdle timeout in seconds
EnableStringUID*boolNoEnable string UID mode
ExpiresInintNoAuto-generated token lifetime in seconds
UseAppCredentialsForRESTboolNoGenerate ConvoAI REST auth headers per request
Preset[]stringNoPreset IDs to send on session start
PipelineIDstringNoPublished pipeline ID to send on session start
DebugboolNoEnable debug logging of the start request
Warnfunc(string)NoCustom warning sink; defaults to logger

State machine

A session progresses through the following states:


_16
Start() API success
_16
┌──────┐ ┌──────────┐ ┌─────────┐
_16
│ idle │─────>│ starting │─────>│ running │
_16
└──┬───┘ └────┬─────┘ └────┬────┘
_16
│ │ │
_16
│ │ error │ Stop()
_16
│ ▼ ▼
_16
│ ┌─────────┐ ┌──────────┐
_16
│ │ error │ │ stopping │
_16
│ └────┬────┘ └────┬─────┘
_16
│ │ │
_16
│ │ │ success
_16
│ ▼ ▼
_16
│ ┌──────────┐ ┌─────────┐
_16
└─────────>│ (restart)│ │ stopped │
_16
└──────────┘ └─────────┘

TransitionTrigger
idle → startingStart() called
starting → runningAPI responds with agent ID
starting → errorAPI request fails
running → stoppingStop() called
stopping → stoppedAPI confirms agent stopped
stopping → errorStop request fails and agent was not already stopped
running → errorUnrecoverable error during interaction

Start() can also be called from stopped or error state to restart the session.

Methods

All methods take context.Context as the first argument. Register event handlers before calling Start() to avoid missing the started event.

Start(ctx)

Starts the agent session. Validates avatar/TTS configuration, generates a token if not provided, and calls the Agora API. Returns the agent ID.


_1
func (s *AgentSession) Start(ctx context.Context) (string, error)

  • Valid from: idle, stopped, error
  • Transitions to: startingrunning on success, error on failure
  • Emits: "started" on success, "error" on failure
  • Validates avatar config and avatar/TTS sample rate match before making the API call

_4
agentID, err := session.Start(ctx)
_4
if err != nil {
_4
log.Fatalf("Failed to start session: %v", err)
_4
}

Stop(ctx)

Stops the running agent and removes it from the channel.


_1
func (s *AgentSession) Stop(ctx context.Context) error

  • Valid from: running
  • Transitions to: stoppingstopped on success, error on failure
  • Emits: "stopped" on success, "error" on failure

_4
err := session.Stop(ctx)
_4
if err != nil {
_4
log.Fatalf("Failed to stop session: %v", err)
_4
}

Say(ctx, text, priority, interruptable)

Instructs the agent to speak the given text.


_1
func (s *AgentSession) Say(ctx context.Context, text string, priority *Agora.SpeakAgentsRequestPriority, interruptable *bool) error

  • Valid from: running
  • Pass nil for priority or interruptable to use defaults
ParameterTypeDescription
textstringThe text for the agent to speak
priority*Agora.SpeakAgentsRequestPriorityMessage priority. See SpeakPriority. Pass nil for default
interruptable*boolWhether this message can be interrupted. Pass nil for default

_1
err := session.Say(ctx, "One moment while I look that up.", nil, nil)

Interrupt(ctx)

Interrupts the agent's current speech.


_1
func (s *AgentSession) Interrupt(ctx context.Context) error

  • Valid from: running

Update(ctx, properties)

Updates the agent's properties mid-session without restarting. Accepts a typed properties struct in REST API format.


_1
func (s *AgentSession) Update(ctx context.Context, properties *Agora.UpdateAgentsRequestProperties) error

  • Valid from: running

GetHistory(ctx)

Retrieves the conversation history. Requires a valid agent ID — Start() must have been called successfully.


_1
func (s *AgentSession) GetHistory(ctx context.Context) (*Agora.GetHistoryAgentsResponse, error)

GetTurns(ctx)

Retrieves turn-by-turn analytics for the session. Requires a valid agent ID — Start() must have been called successfully.


_1
func (s *AgentSession) GetTurns(ctx context.Context) (*Agora.GetTurnsAgentsResponse, error)

GetInfo(ctx)

Gets the current agent status from the API. Requires a valid agent ID.


_1
func (s *AgentSession) GetInfo(ctx context.Context) (*Agora.GetAgentsResponse, error)

On(event, handler)

Registers an event handler. Multiple handlers can be registered for the same event. Handlers run synchronously; panics in handlers are recovered and reported through the session warning sink.


_1
func (s *AgentSession) On(event string, handler EventHandler)


_10
session.On("started", func(data interface{}) {
_10
info := data.(map[string]string)
_10
fmt.Println("Agent is live:", info["agent_id"])
_10
})
_10
session.On("stopped", func(data interface{}) {
_10
fmt.Println("Agent has left")
_10
})
_10
session.On("error", func(data interface{}) {
_10
log.Println("Session error:", data)
_10
})

Off(event, handler)

Unregisters a previously registered event handler.


_1
func (s *AgentSession) Off(event string, handler EventHandler)

Events

EventData typeDescription
"started"map[string]string{"agent_id": "..."}Agent successfully joined the channel
"stopped"map[string]string{"agent_id": "..."}Agent left the channel
"error"errorAn unrecoverable error occurred

Getters

Read-only methods available on any *AgentSession instance.

MethodReturn typeDescription
ID()stringAgent ID. Empty string before Start() succeeds
Status()SessionStatusCurrent session state
Agent()*AgentThe agent configuration
AppID()stringThe Agora App ID
Raw()*agents.ClientDirect access to the Fern-generated agents client for advanced operations

Using session.Raw()

Use session.Raw() to call REST API endpoints not yet exposed by the agentkit layer.


_3
response, err := session.Raw().List(ctx, &Agora.ListAgentsRequest{
_3
Appid: session.AppID(),
_3
})

Thread safety

AgentSession is safe for concurrent use across goroutines. All state mutations are protected by sync.RWMutex. Multiple goroutines can safely call Status(), ID(), and other getters while another goroutine calls Start() or Stop().

Vendors

All vendor constructors are in the agentkit/vendors package. Constructors panic if required fields are empty — this is Go-idiomatic behavior for programmer configuration errors.


_1
import "github.com/AgoraIO-Conversational-AI/agent-server-sdk-go/agentkit/vendors"

Interfaces


_21
type LLM interface {
_21
ToConfig() map[string]interface{}
_21
}
_21
_21
type TTS interface {
_21
ToConfig() map[string]interface{}
_21
GetSampleRate() *SampleRate
_21
}
_21
_21
type STT interface {
_21
ToConfig() map[string]interface{}
_21
}
_21
_21
type MLLM interface {
_21
ToConfig() map[string]interface{}
_21
}
_21
_21
type Avatar interface {
_21
ToConfig() map[string]interface{}
_21
RequiredSampleRate() SampleRate
_21
}

LLM vendors

Use with WithLlm().

NewOpenAI


_1
func NewOpenAI(opts OpenAIOptions) *OpenAI

Panics if APIKey is empty unless Model is one of the supported preset-backed OpenAI models (gpt-4o-mini, gpt-4.1-mini, gpt-5-nano, gpt-5-mini) and BaseURL / Vendor are not set.

FieldTypeRequiredDefaultDescription
APIKeystringNoOpenAI API key. Optional for supported preset-backed OpenAI models
ModelstringNo"gpt-4o-mini"Model identifier
BaseURLstringNo"https://api.openai.com/v1/chat/completions"API endpoint
Temperature*float64NoSampling temperature
TopP*float64NoNucleus sampling
MaxTokens*intNoMaximum tokens in response
SystemMessages[]map[string]interface{}NoSystem messages
GreetingMessagestringNoAgent greeting message
FailureMessagestringNoMessage spoken when LLM fails
InputModalities[]stringNo["text"]Input modalities
OutputModalities[]stringNoOutput modalities
Paramsmap[string]interface{}NoAdditional model parameters
Headersmap[string]stringNoCustom HTTP headers forwarded to the LLM provider
GreetingConfigsmap[string]interface{}NoGreeting playback configuration
TemplateVariablesmap[string]stringNoTemplate variables for messages

NewAzureOpenAI


_1
func NewAzureOpenAI(opts AzureOpenAIOptions) *AzureOpenAI

Panics if APIKey, Endpoint, or DeploymentName is empty.

FieldTypeRequiredDefaultDescription
APIKeystringYesAzure OpenAI API key
EndpointstringYesAzure endpoint URL
DeploymentNamestringYesAzure deployment name
APIVersionstringNo"2024-08-01-preview"API version
Temperature*float64NoSampling temperature
TopP*float64NoNucleus sampling
MaxTokens*intNoMaximum tokens
SystemMessages[]map[string]interface{}NoSystem messages
GreetingMessagestringNoAgent greeting message
FailureMessagestringNoMessage spoken when LLM fails
InputModalities[]stringNo["text"]Input modalities
OutputModalities[]stringNoOutput modalities
Paramsmap[string]interface{}NoAdditional model parameters
Headersmap[string]stringNoCustom HTTP headers forwarded to the LLM provider
GreetingConfigsmap[string]interface{}NoGreeting playback configuration
TemplateVariablesmap[string]stringNoTemplate variables for messages

NewAnthropic


_1
func NewAnthropic(opts AnthropicOptions) *Anthropic

Panics if APIKey is empty.

FieldTypeRequiredDefaultDescription
APIKeystringYesAnthropic API key
ModelstringNo"claude-3-5-sonnet-20241022"Model identifier
MaxTokens*intNoMaximum tokens
Temperature*float64NoSampling temperature
TopP*float64NoNucleus sampling
SystemMessages[]map[string]interface{}NoSystem messages
GreetingMessagestringNoAgent greeting message
FailureMessagestringNoMessage spoken when LLM fails
InputModalities[]stringNo["text"]Input modalities
OutputModalities[]stringNoOutput modalities
Paramsmap[string]interface{}NoAdditional model parameters
Headersmap[string]stringNoCustom HTTP headers forwarded to the LLM provider
GreetingConfigsmap[string]interface{}NoGreeting playback configuration
TemplateVariablesmap[string]stringNoTemplate variables for messages

NewGemini


_1
func NewGemini(opts GeminiOptions) *Gemini

Panics if APIKey is empty.

FieldTypeRequiredDefaultDescription
APIKeystringYesGoogle AI API key
ModelstringNo"gemini-2.0-flash-exp"Model identifier
Temperature*float64NoSampling temperature
TopP*float64NoNucleus sampling
TopK*intNoTop-K sampling
MaxOutputTokens*intNoMaximum output tokens
SystemMessages[]map[string]interface{}NoSystem messages
GreetingMessagestringNoAgent greeting message
FailureMessagestringNoMessage spoken when LLM fails
InputModalities[]stringNo["text"]Input modalities
OutputModalities[]stringNoOutput modalities
Paramsmap[string]interface{}NoAdditional model parameters
Headersmap[string]stringNoCustom HTTP headers forwarded to the LLM provider
GreetingConfigsmap[string]interface{}NoGreeting playback configuration
TemplateVariablesmap[string]stringNoTemplate variables for messages

TTS vendors

Use with WithTts(). The SampleRate field determines avatar compatibility — see WithAvatar(). Use SampleRate constants for the SampleRate field.

NewElevenLabsTTS


_1
func NewElevenLabsTTS(opts ElevenLabsTTSOptions) *ElevenLabsTTS

Panics if Key, ModelID, or VoiceID is empty.

FieldTypeRequiredDescription
KeystringYesElevenLabs API key
ModelIDstringYesModel identifier, for example "eleven_flash_v2_5"
VoiceIDstringYesVoice identifier
BaseURLstringNoCustom API endpoint
SampleRate*SampleRateNoOutput sample rate
SkipPatterns[]intNoPatterns to skip in TTS output

NewMicrosoftTTS


_1
func NewMicrosoftTTS(opts MicrosoftTTSOptions) *MicrosoftTTS

Panics if Key, Region, or VoiceName is empty.

FieldTypeRequiredDescription
KeystringYesAzure Speech Services key
RegionstringYesAzure region, for example "eastus"
VoiceNamestringYesVoice name, for example "en-US-JennyNeural"
SampleRate*SampleRateNoOutput sample rate
SkipPatterns[]intNoPatterns to skip

NewOpenAITTS

Fixed sample rate: SampleRate24kHz.


_1
func NewOpenAITTS(opts OpenAITTSOptions) *OpenAITTS

Panics if Voice is empty. APIKey is optional for the preset-backed tts-1 path.

FieldTypeRequiredDescription
APIKeystringNoOpenAI API key. Optional for the preset-backed tts-1 path
VoicestringYesVoice name: "alloy", "echo", "fable", "onyx", "nova", or "shimmer"
ModelstringNoModel identifier, for example "tts-1" or "tts-1-hd"
ResponseFormatstringNoAudio format, for example "pcm"
Speed*float64NoSpeech speed multiplier
SkipPatterns[]intNoPatterns to skip

NewCartesiaTTS


_1
func NewCartesiaTTS(opts CartesiaTTSOptions) *CartesiaTTS

Panics if APIKey or VoiceID is empty.

FieldTypeRequiredDescription
APIKeystringYesCartesia API key
VoiceIDstringYesVoice identifier (serialized as {"mode":"id","id":"..."})
ModelIDstringNoModel identifier
SampleRate*SampleRateNoOutput sample rate
SkipPatterns[]intNoPatterns to skip

NewGoogleTTS


_1
func NewGoogleTTS(opts GoogleTTSOptions) *GoogleTTS

Panics if Key or VoiceName is empty.

FieldTypeRequiredDescription
KeystringYesGoogle Cloud API key
VoiceNamestringYesVoice name
LanguageCodestringNoLanguage code
SkipPatterns[]intNoPatterns to skip

NewAmazonTTS


_1
func NewAmazonTTS(opts AmazonTTSOptions) *AmazonTTS

Panics if AccessKey, SecretKey, Region, or VoiceID is empty.

FieldTypeRequiredDescription
AccessKeystringYesAWS access key
SecretKeystringYesAWS secret key
RegionstringYesAWS region
VoiceIDstringYesAmazon Polly voice ID
SkipPatterns[]intNoPatterns to skip

NewDeepgramTTS


_1
func NewDeepgramTTS(opts DeepgramTTSOptions) *DeepgramTTS

Panics if APIKey or Model is empty.

FieldTypeRequiredDescription
APIKeystringYesDeepgram API key
ModelstringYesDeepgram TTS model, for example "aura-2-thalia-en"
BaseURLstringNoWebSocket endpoint. Defaults server-side to wss://api.deepgram.com/v1/speak
SampleRate*SampleRateNoOutput sample rate
Paramsmap[string]interface{}NoAdditional Deepgram TTS parameters
SkipPatterns[]intNoPatterns to skip

NewHumeAITTS


_1
func NewHumeAITTS(opts HumeAITTSOptions) *HumeAITTS

Panics if Key is empty.

FieldTypeRequiredDescription
KeystringYesHume AI API key
ConfigIDstringNoConfiguration ID
SkipPatterns[]intNoPatterns to skip

NewRimeTTS


_1
func NewRimeTTS(opts RimeTTSOptions) *RimeTTS

Panics if Key or Speaker is empty.

FieldTypeRequiredDescription
KeystringYesRime API key
SpeakerstringYesSpeaker identifier
ModelIDstringNoModel identifier
LangstringNoLanguage code
SamplingRate*intNoSampling rate in Hz (serialized as samplingRate)
SpeedAlpha*float64NoSpeed multiplier (serialized as speedAlpha)
SkipPatterns[]intNoPatterns to skip

NewFishAudioTTS


_1
func NewFishAudioTTS(opts FishAudioTTSOptions) *FishAudioTTS

Panics if Key or ReferenceID is empty.

FieldTypeRequiredDescription
KeystringYesFish Audio API key
ReferenceIDstringYesReference audio ID
SkipPatterns[]intNoPatterns to skip

NewMiniMaxTTS


_1
func NewMiniMaxTTS(opts MiniMaxTTSOptions) *MiniMaxTTS

Panics if Model is empty. Key is optional for supported preset-backed MiniMax models (speech-2.6-turbo, speech_2_6_turbo, speech-2.8-turbo, speech_2_8_turbo). BYOK still requires Key and GroupID, and preset-backed mode must not set GroupID, VoiceID, or URL.

FieldTypeRequiredDescription
KeystringNoMiniMax API key. Optional for supported preset-backed MiniMax models
GroupIDstringNoMiniMax group ID. Required for BYOK
ModelstringYesModel name, for example "speech-02-turbo"
VoiceIDstringNoVoice style identifier. BYOK only
URLstringNoWebSocket endpoint. BYOK only
SkipPatterns[]intNoPatterns to skip

NewMurfTTS


_1
func NewMurfTTS(opts MurfTTSOptions) *MurfTTS

Panics if Key or VoiceID is empty.

FieldTypeRequiredDescription
KeystringYesMurf API key
VoiceIDstringYesVoice ID, for example "Ariana" or "Natalie"
StylestringNoVoice style, for example "Conversational"
SkipPatterns[]intNoPatterns to skip

NewSarvamTTS


_1
func NewSarvamTTS(opts SarvamTTSOptions) *SarvamTTS

Panics if Key, Speaker, or TargetLanguageCode is empty.

FieldTypeRequiredDescription
KeystringYesSarvam API key
SpeakerstringYesSpeaker name
TargetLanguageCodestringYesTarget language code
SkipPatterns[]intNoPatterns to skip

STT vendors

Use with WithStt().

NewDeepgramSTT


_1
func NewDeepgramSTT(opts DeepgramSTTOptions) *DeepgramSTT

Panics if APIKey is empty.

FieldTypeRequiredDescription
APIKeystringYesDeepgram API key
ModelstringNoModel, for example "nova-2"
LanguagestringNoLanguage code, for example "en-US"
SmartFormat*boolNoEnable smart formatting
Punctuation*boolNoEnable punctuation
AdditionalParamsmap[string]interface{}NoAdditional vendor parameters

NewSpeechmaticsSTT


_1
func NewSpeechmaticsSTT(opts SpeechmaticsSTTOptions) *SpeechmaticsSTT

Panics if APIKey is empty.

FieldTypeRequiredDescription
APIKeystringYesSpeechmatics API key
LanguagestringNoLanguage code
ModelstringNoModel identifier

NewMicrosoftSTT


_1
func NewMicrosoftSTT(opts MicrosoftSTTOptions) *MicrosoftSTT

Panics if Key or Region is empty.

FieldTypeRequiredDescription
KeystringYesAzure Speech Services key
RegionstringYesAzure region
LanguagestringNoLanguage code

NewOpenAISTT


_1
func NewOpenAISTT(opts OpenAISTTOptions) *OpenAISTT

Panics if APIKey is empty.

FieldTypeRequiredDescription
APIKeystringYesOpenAI API key
ModelstringNoModel identifier
LanguagestringNoLanguage code

NewGoogleSTT


_1
func NewGoogleSTT(opts GoogleSTTOptions) *GoogleSTT

Panics if Key is empty.

FieldTypeRequiredDescription
KeystringYesGoogle Cloud API key
LanguagestringNoLanguage code
ModelstringNoModel identifier

NewAmazonSTT


_1
func NewAmazonSTT(opts AmazonSTTOptions) *AmazonSTT

Panics if AccessKey, SecretKey, or Region is empty.

FieldTypeRequiredDescription
AccessKeystringYesAWS access key
SecretKeystringYesAWS secret key
RegionstringYesAWS region
LanguagestringNoLanguage code

NewAssemblyAISTT


_1
func NewAssemblyAISTT(opts AssemblyAISTTOptions) *AssemblyAISTT

Panics if APIKey is empty.

FieldTypeRequiredDescription
APIKeystringYesAssemblyAI API key

NewAresSTT


_1
func NewAresSTT(opts AresSTTOptions) *AresSTT

Ares is an Agora built-in STT service — no external API key required.

FieldTypeRequiredDescription
LanguagestringNoLanguage code
AdditionalParamsmap[string]interface{}NoAdditional vendor parameters

NewSarvamSTT


_1
func NewSarvamSTT(opts SarvamSTTOptions) *SarvamSTT

Panics if APIKey is empty.

FieldTypeRequiredDescription
APIKeystringYesSarvam API key
LanguagestringNoLanguage code
ModelstringNoModel identifier

MLLM vendors

Use with WithMllm() for multimodal end-to-end audio processing without separate STT or TTS steps. Requires AdvancedFeatures.EnableMllm = true via WithAdvancedFeatures() in NewAgent.

NewOpenAIRealtime


_1
func NewOpenAIRealtime(opts OpenAIRealtimeOptions) *OpenAIRealtime

Panics if APIKey is empty.

FieldTypeRequiredDefaultDescription
APIKeystringYesOpenAI API key
ModelstringNo"gpt-4o-realtime-preview"Model identifier
URLstringNoCustom WebSocket URL
GreetingMessagestringNoAgent greeting message
FailureMessagestringNoMessage played when the model call fails
MaxHistory*intNoMaximum conversation history length
PredefinedTools[]stringNoPredefined tools, for example ["_publish_message"]
InputModalities[]stringNoInput modalities
OutputModalities[]stringNoOutput modalities
Messages[]map[string]interface{}NoConversation messages for short-term memory
Paramsmap[string]interface{}NoAdditional parameters
TurnDetection*Agora.StartAgentsRequestPropertiesMllmTurnDetectionNoMLLM turn detection configuration; overrides top-level turn detection

NewGeminiLive


_1
func NewGeminiLive(opts GeminiLiveOptions) *GeminiLive

Panics if APIKey or Model is empty.

FieldTypeRequiredDefaultDescription
APIKeystringYesGoogle AI API key
ModelstringYesGemini Live model identifier
URLstringNoCustom WebSocket URL
InstructionsstringNoSystem instruction
VoicestringNoVoice name
GreetingMessagestringNoAgent greeting message
FailureMessagestringNoMessage played when the model call fails
MaxHistory*intNoMaximum conversation history length
PredefinedTools[]stringNoPredefined tools, for example ["_publish_message"]
InputModalities[]stringNoInput modalities
OutputModalities[]stringNoOutput modalities
Messages[]map[string]interface{}NoConversation messages for short-term memory
AdditionalParamsmap[string]interface{}NoAdditional parameters
TurnDetection*Agora.StartAgentsRequestPropertiesMllmTurnDetectionNoMLLM turn detection configuration; overrides top-level turn detection

NewVertexAI


_1
func NewVertexAI(opts VertexAIOptions) *VertexAI

Panics if ProjectID or ADCredentialsString is empty.

FieldTypeRequiredDefaultDescription
ProjectIDstringYesGoogle Cloud project ID
ADCredentialsStringstringYesApplication Default Credentials JSON string
LocationstringNo"us-central1"Google Cloud region
ModelstringNo"gemini-2.0-flash-exp"Model identifier
URLstringNoCustom WebSocket URL
VoicestringNoVoice name
InstructionsstringNoSystem instruction
GreetingMessagestringNoAgent greeting message
FailureMessagestringNoMessage played when the model call fails
MaxHistory*intNoMaximum conversation history length
PredefinedTools[]stringNoPredefined tools, for example ["_publish_message"]
InputModalities[]stringNoInput modalities
OutputModalities[]stringNoOutput modalities
Messages[]map[string]interface{}NoConversation messages for short-term memory
AdditionalParamsmap[string]interface{}NoAdditional parameters
TurnDetection*Agora.StartAgentsRequestPropertiesMllmTurnDetectionNoMLLM turn detection configuration; overrides top-level turn detection

Avatar vendors

Use with WithAvatar(). Each avatar vendor requires a specific TTS sample rate — the constructor panics if the sample rate does not match.

NewHeyGenAvatar

Requires TTS at 24,000 Hz (SampleRate24kHz).


_1
func NewHeyGenAvatar(opts HeyGenAvatarOptions) *HeyGenAvatar

Panics if APIKey or AgoraUID is empty, or if Quality is not "low", "medium", or "high".

FieldTypeRequiredDescription
APIKeystringYesHeyGen API key
QualitystringYesVideo quality: "low", "medium", or "high"
AgoraUIDstringYesUID for the avatar's video stream
AgoraTokenstringNoRTC token for avatar authentication
AvatarIDstringNoHeyGen avatar ID
Enable*boolNoEnable or disable the avatar. Default: true
DisableIdleTimeout*boolNoDisable the idle timeout
ActivityIdleTimeout*intNoIdle timeout in seconds. Default: 120

NewAkoolAvatar

Requires TTS at 16,000 Hz (SampleRate16kHz).


_1
func NewAkoolAvatar(opts AkoolAvatarOptions) *AkoolAvatar

Panics if APIKey is empty.

FieldTypeRequiredDescription
APIKeystringYesAkool API key
AvatarIDstringNoAvatar ID
Enable*boolNoEnable or disable the avatar
AdditionalParamsmap[string]interface{}NoAdditional vendor parameters

NewLiveAvatarAvatar

Requires TTS at 24,000 Hz (SampleRate24kHz).


_1
func NewLiveAvatarAvatar(opts LiveAvatarAvatarOptions) *LiveAvatarAvatar

Panics if APIKey or AgoraUID is empty, or if Quality is not "low", "medium", or "high".

NewAnamAvatar


_1
func NewAnamAvatar(opts AnamAvatarOptions) *AnamAvatar

Panics if APIKey is empty.

Token utilities

Helper functions for generating and managing tokens.


_1
import "github.com/AgoraIO-Conversational-AI/agent-server-sdk-go/agentkit"

GenerateConvoAIToken()

Generates a combined RTC+RTM Conversational AI token. This is the same token the SDK generates automatically when AppID and AppCertificate are provided on AgentSessionOptions.


_1
func GenerateConvoAIToken(opts GenerateConvoAITokenOptions) (string, error)

FieldTypeRequiredDescription
AppIDstringYesAgora App ID
AppCertificatestringYesAgora App Certificate
ChannelNamestringYesThe channel the token grants access to
AccountstringYesThe UID this token is issued for, as a string
TokenExpireintNoToken lifetime in seconds. Default: 86400. Valid range: 1–86400

_7
token, err := agentkit.GenerateConvoAIToken(agentkit.GenerateConvoAITokenOptions{
_7
AppID: os.Getenv("AGORA_APP_ID"),
_7
AppCertificate: os.Getenv("AGORA_APP_CERT"),
_7
ChannelName: "support-room-123",
_7
Account: "1",
_7
TokenExpire: agentkit.ExpiresInHours(12),
_7
})

GenerateRtcToken()

Generates an RTC-only token. Use GenerateConvoAIToken() instead for most Conversational AI use cases.


_1
func GenerateRtcToken(opts GenerateTokenOptions) (string, error)

FieldTypeRequiredDescription
AppIDstringYesAgora App ID
AppCertificatestringYesAgora App Certificate
ChannelstringYesChannel name
UIDuint32YesUser ID. Use 0 for any user
RoleintNoRTC role: RolePublisher (1) or RoleSubscriber (2). Default: RolePublisher
ExpirySecondsintNoToken lifetime in seconds. Default: DefaultExpirySeconds (3600)

ExpiresInHours() / ExpiresInMinutes()

Helper functions for specifying token lifetimes. Use with AgentSessionOptions.ExpiresIn or token generation functions. Returns an error if the value is ≤ 0; warns and caps at 86400 if the result exceeds 24 hours.


_2
func ExpiresInHours(hours int) (int, error)
_2
func ExpiresInMinutes(minutes int) (int, error)


_9
expiresIn, err := agentkit.ExpiresInHours(12)
_9
if err != nil {
_9
log.Fatalf("Invalid expiry: %v", err)
_9
}
_9
_9
session := agentkit.NewAgentSession(agentkit.AgentSessionOptions{
_9
// ...
_9
ExpiresIn: expiresIn,
_9
})

Types and constants

Shared types, constants, and enums used across the SDK.

SessionStatus

Typed string constants representing the session lifecycle states. Read via session.Status().


_10
type SessionStatus string
_10
_10
const (
_10
StatusIdle SessionStatus = "idle"
_10
StatusStarting SessionStatus = "starting"
_10
StatusRunning SessionStatus = "running"
_10
StatusStopping SessionStatus = "stopping"
_10
StatusStopped SessionStatus = "stopped"
_10
StatusError SessionStatus = "error"
_10
)

SampleRate

Typed integer constants for audio sample rates. Use with TTS vendor SampleRate fields and avatar sample rate validation.


_10
type SampleRate int
_10
_10
const (
_10
SampleRate8kHz SampleRate = 8000
_10
SampleRate16kHz SampleRate = 16000
_10
SampleRate22kHz SampleRate = 22050
_10
SampleRate24kHz SampleRate = 24000
_10
SampleRate44kHz SampleRate = 44100
_10
SampleRate48kHz SampleRate = 48000
_10
)

Convenience constants for avatar sample rate requirements:


_4
const (
_4
HeyGenRequiredSampleRate = SampleRate24kHz // 24000 Hz
_4
AkoolRequiredSampleRate = SampleRate16kHz // 16000 Hz
_4
)

EventHandler

The function signature for session event handlers. Pass implementations to session.On().


_1
type EventHandler func(data interface{})

Eventdata typeCast example
"started"map[string]stringdata.(map[string]string)["agent_id"]
"stopped"map[string]stringdata.(map[string]string)["agent_id"]
"error"errordata.(error)

Area constants

Used with option.WithArea() to select the regional API endpoint.


_5
option.AreaUS // United States (west + east)
_5
option.AreaEU // Europe (west + central)
_5
option.AreaAP // Asia-Pacific (southeast + northeast)
_5
option.AreaCN // Chinese Mainland (east + north)
_5
option.AreaUnknown // Default

Type aliases

The agentkit package defines type aliases for common Fern-generated types. Use these in place of the full Agora.StartAgentsRequestProperties* names when building configuration objects.

AliasUnderlying type
TurnDetectionConfigAgora.StartAgentsRequestPropertiesTurnDetection
SalConfigAgora.StartAgentsRequestPropertiesSal
AdvancedFeaturesAgora.StartAgentsRequestPropertiesAdvancedFeatures
SessionParamsAgora.StartAgentsRequestPropertiesParameters
GeofenceConfigAgora.StartAgentsRequestPropertiesGeofence
RtcConfigAgora.StartAgentsRequestPropertiesRtc
FillerWordsConfigAgora.StartAgentsRequestPropertiesFillerWords
LlmConfigAgora.StartAgentsRequestPropertiesLlm
MllmConfigAgora.StartAgentsRequestPropertiesMllm
AsrConfigAgora.StartAgentsRequestPropertiesAsr
TtsConfigAgora.Tts
AvatarConfigAgora.StartAgentsRequestPropertiesAvatar

AgoraError

The Fern-generated error type returned when the API responds with a 4xx or 5xx status code. Use errors.As to inspect the error.


_11
import "github.com/AgoraIO-Conversational-AI/agent-server-sdk-go/core"
_11
_11
_, err := session.Start(ctx)
_11
if err != nil {
_11
var apiError *core.APIError
_11
if errors.As(err, &apiError) {
_11
log.Printf("Status: %d", apiError.StatusCode)
_11
log.Printf("Body: %s", apiError.Body)
_11
}
_11
return err
_11
}

FieldTypeDescription
StatusCodeintHTTP status code returned by the API
BodystringRaw response body from the API