Go SDK

The official Voicebip SDK for Go, auto-generated from the OpenAPI spec via Fern. The module is not yet published — this page previews what the API will look like when it ships.

Installation (Coming Soon)

$go get github.com/voicebip/voicebip-go

Requires Go 1.22+.

In the Meantime

Use the REST API directly with net/http:

1package main
2
3import (
4 "bytes"
5 "encoding/json"
6 "fmt"
7 "io"
8 "net/http"
9)
10
11const apiKey = "pk_live_xxx"
12const baseURL = "https://api.voicebip.com/v1"
13
14func voicebipPost(path string, body any) (map[string]any, error) {
15 b, _ := json.Marshal(body)
16 req, _ := http.NewRequest("POST", baseURL+path, bytes.NewReader(b))
17 req.Header.Set("Authorization", "Bearer "+apiKey)
18 req.Header.Set("Content-Type", "application/json")
19 resp, err := http.DefaultClient.Do(req)
20 if err != nil {
21 return nil, err
22 }
23 defer resp.Body.Close()
24 raw, _ := io.ReadAll(resp.Body)
25 var out map[string]any
26 json.Unmarshal(raw, &out)
27 return out, nil
28}
29
30func main() {
31 agent, _ := voicebipPost("/agents", map[string]any{
32 "display_name": "Support",
33 "language": "en",
34 "system_prompt": "You are a helpful agent.",
35 })
36 fmt.Println("agent_id:", agent["agent_id"])
37}

Preview Usage

When voicebip-go is published, the same flow will look like this:

Quick start

1package main
2
3import (
4 "context"
5 "fmt"
6 "log"
7
8 voicebip "github.com/voicebip/voicebip-go"
9 "github.com/voicebip/voicebip-go/option"
10)
11
12func main() {
13 client := voicebip.NewClient(
14 option.WithAPIKey("pk_live_xxx"),
15 )
16
17 // Create an agent
18 agent, err := client.Agents.Create(context.Background(), &voicebip.CreateAgentRequest{
19 DisplayName: "Customer Support",
20 Language: "en",
21 SystemPrompt: voicebip.String("You are a helpful customer support agent."),
22 })
23 if err != nil {
24 log.Fatal(err)
25 }
26 fmt.Println("Agent:", agent.AgentID)
27
28 // Initiate an outbound call
29 call, err := client.Calls.Initiate(context.Background(), &voicebip.InitiateCallRequest{
30 AgentID: agent.AgentID,
31 FromNumber: "+234800000xxxx",
32 ToNumber: "+2348031234567",
33 })
34 if err != nil {
35 log.Fatal(err)
36 }
37 fmt.Println("Call started:", call.CallID)
38}

Mint a WebRTC token (server-side)

Use client.Webrtc.CreateToken to mint a short-lived scoped token for a browser call, then return it to the browser so @voicebip/web can start the call.

1import voicebip "github.com/voicebip/voicebip-go"
2
3func voiceTokenHandler(w http.ResponseWriter, r *http.Request) {
4 var body struct {
5 AgentID string `json:"agent_id"`
6 }
7 if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
8 http.Error(w, err.Error(), http.StatusBadRequest)
9 return
10 }
11
12 ttl := 600
13 resp, err := vbClient.Webrtc.CreateToken(r.Context(), &voicebip.CreateWebRTCTokenRequest{
14 AgentID: body.AgentID,
15 TtlSeconds: &ttl,
16 })
17 if err != nil {
18 http.Error(w, err.Error(), http.StatusInternalServerError)
19 return
20 }
21
22 json.NewEncoder(w).Encode(resp)
23}

Error handling

1import (
2 voicebip "github.com/voicebip/voicebip-go"
3 voicebipErr "github.com/voicebip/voicebip-go/errors"
4)
5
6_, err := client.Calls.Initiate(ctx, req)
7if err != nil {
8 var apiErr *voicebipErr.APIError
9 if errors.As(err, &apiErr) {
10 fmt.Printf("error_code: %s, message: %s\n", apiErr.ErrorCode, apiErr.Message)
11 switch apiErr.ErrorCode {
12 case "WORKSPACE_BLOCKED":
13 // handle zero-balance state
14 case "CALL_WINDOW_RESTRICTED":
15 // outside permitted hours
16 }
17 }
18}

Configuration

1client := voicebip.NewClient(
2 option.WithAPIKey("pk_live_xxx"),
3 option.WithBaseURL("https://api.voicebip.com"), // default; change for sandbox
4 option.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
5)

Use pk_test_xxx API keys to hit the sandbox — no real calls, no billing.

Available methods

PackageMethodsNotes
AgentsCreate, List, Get, Update, DeleteAgent CRUD
NumbersListAvailable, Provision, Get, ReleaseNumber management
CallsInitiate, Get, End, Hold, Resume, Transfer, SendDtmfVoice calls
MessagesSendSMS and WhatsApp
WebrtcCreateToken, CreateOfferBrowser call signaling
ApiKeysCreate, List, Revoke, RotateAPI key management
BillingGetUsage, GetBalance, CreateCheckoutUsage and payments
DpaAccept, GetStatusNDPR compliance
WebhooksTestWebhook testing