Go - Voice Tracking

Prerequisite

If you haven't set up a voice agent in the Paygent dashboard yet, please follow our setup guide first. You'll need an Agent ID to start tracking.

The Go SDK supports Session-based voice tracking, allowing you to manage complex AI interactions with ease.

Voice Pricing

As an architect with decades of experience in high-throughput billing systems, I can tell you that flexibility is the heartbeat of a successful AI platform.

📖 Real-World Scenario

You run a dental clinic AI that handles appointment bookings. You want to charge based on the actual conversation time because longer calls use more compute resources.

💡 Solution

Scenario A: Per-minute ON

When you enable the Per-minute toggle on your Indicator, Paygent calculates the total duration reported in your SetVoiceIndicator call.

Pricing: $0.15 / min
Duration: 5.0 mins
Result: 5 * 0.15 = $0.75

✅ Result

Perfect for connectivity-based SaaS where you pass on infrastructure costs with a margin.

Indicator Step 2 Configuration
Flat Based Configuration

Configuring the Activity Indicator with the Per-minute toggle ON.

📖 Real-World Scenario

You've built a world-class Lead Qualification agent. Your customers don't care how long the call lasts; they only care that the lead was qualified successfully.

💡 Solution

Scenario B: Per-minute OFF

Disable the Per-minute toggle. Now, no matter if the call lasts 1 minute or 20 minutes, the customer is charged a single fixed rate.

Pricing: $0.20 / call
Duration: Any
Result: Flat $0.20

✅ Result

Ideal for outcome-based services where your value is tied to task completion, not duration.

Indicator Step 2 Configuration (Off)

Configuring the Activity Indicator with the Per-minute toggle OFF.

Custom Pricing

Custom Based Configuration

In modern AI architectures, one size rarely fits all. You might use GPT-5 for high-stakes negotiation agents, but switch to Gemini 2.5 for simple data entry tasks.

Tip

Custom Pricing is only visible when the Per-minute switch is ON in Step 2. This allows you to charge based on the specific infrastructure used.

Real-World Custom Example:

Paygent automatically detects the models you track via TrackVoiceSTT, TrackVoiceLLM, and TrackVoiceTTS. You can then set unique per-minute rates for each tier:

  • LLM: GPT-5 (Premium)$0.50 / min
  • LLM: Gemini 2.5 (Standard)$0.20 / min
  • STT: Deepgram Nova-2$0.05 / min
  • TTS: Azure Neural$0.08 / min

"With Custom Pricing, you no longer subsidize expensive models with cheap ones. Your margins stay protected while you provide the best possible AI experience."

Voice Session Flow Example

Here's how to implement a complete voice billing flow in Go:

voice_session.go
1package main
2
3import (
4    "fmt"
5    "time"
6    paygent "github.com/paygent-org/paygent-sdk-go"
7)
8
9func main() {
10    client := paygent.NewClient("your-paygent-api-key")
11
12    customerID := "customer-123"
13    agentID := "voice-agent-id"
14
15    // 1. Create or Get Customer (Automated)
16    client.CreateOrGetCustomer(paygent.CustomerCreateOrGetRequest{
17        ExternalID: customerID,
18        Name:       "Customer Name",
19    })
20
21    // 2. Define a unique session ID
22    // Use your own unique session ID for this customer (e.g., call SID or UUID)
23    sessionID := fmt.Sprintf("voice_session_%d", time.Now().Unix())
24    
25    // 3. Initialize Voice Session
26    client.InitializeVoiceSession(sessionID, agentID, customerID)
27
28    // 4. Track User Speech (STT Usage)
29    client.TrackVoiceSTT(sessionID, map[string]interface{}{
30        "serviceProvider": paygent.Deepgram,
31        "model":           paygent.DeepgramNova2,
32        "audioDuration":   300, // duration in seconds
33    })
34
35    // 5. Track AI Processing (LLM Usage)
36    client.TrackVoiceLLM(sessionID, map[string]interface{}{
37        "serviceProvider":  paygent.OpenAI,
38        "model":            paygent.GPT4O,
39        "promptTokens":     1000,
40        "completionTokens": 500,
41    })
42
43    // 6. Track AI Speech (TTS Usage)
44    client.TrackVoiceTTS(sessionID, map[string]interface{}{
45        "serviceProvider": paygent.DeepgramTTS,
46        "model":           paygent.DeepgramAura2,
47        "characterCount":  250,
48    })
49
50    // 7. Final Step: Set Indicator with Call Duration (Minutes)
51    client.SetVoiceIndicator(sessionID, "voice_call_completed", 2.5)
52}

How it Works

A frictionless, step-by-step developer experience designed for the modern AI stack.

01

Customer Verification

The CreateOrGetCustomer method ensures that every voice call is linked to a valid customer entry in your Paygent dashboard.

02

Stateful Sessions

By calling InitializeVoiceSession, you create a dedicated billing context for the call, allowing you to track multi-step interactions seamlessly.

03

Multi-Provider Tracking

Track usage across different providers (Deepgram, OpenAI, etc.) within the same session. Paygent handles the complex cost math for you.

04

Indicator-Based Billing

The SetVoiceIndicator call finalized the session. Use this to trigger billing based on call duration or specific business outcomes.

Was this page helpful?

Need help? Contact us at support@withpaygent.com