Get started9 min
1
Create the Go client
The Go client keeps a strict timeout and sends the same JSON fields as the live call route.
Go SDK
package quickcallai
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strings"
"time"
)
type Client struct {
APIKey string
BaseURL string
HTTP *http.Client
}
type InitiateCallRequest struct {
PhoneNumber string `json:"phone_number"`
CustomerName string `json:"customer_name"`
Prompt string `json:"prompt"`
Language string `json:"language,omitempty"`
VoiceModel string `json:"voice_model,omitempty"`
Provider string `json:"provider,omitempty"`
AgentID *string `json:"agent_id,omitempty"`
}
func New(apiKey string) *Client {
return &Client{
APIKey: apiKey,
BaseURL: "https://ai.quickcall.tech/api",
HTTP: &http.Client{Timeout: 30 * time.Second},
}
}
func (c *Client) do(method, path string, payload any, out any) error {
var body bytes.Buffer
if payload != nil {
if err := json.NewEncoder(&body).Encode(payload); err != nil {
return err
}
}
req, err := http.NewRequest(method, strings.TrimRight(c.BaseURL, "/")+path, &body)
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+c.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := c.HTTP.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
if len(respBody) == 0 {
return nil
}
var apiData map[string]any
if err := json.Unmarshal(respBody, &apiData); err != nil {
return err
}
if resp.StatusCode >= 400 || apiData["success"] == false {
return fmt.Errorf("quickcallai api error: %s %v", resp.Status, apiData)
}
if out == nil {
return nil
}
return json.Unmarshal(respBody, out)
}
func (c *Client) InitiateCall(input InitiateCallRequest, out any) error {
if input.Language == "" {
input.Language = "en-US"
}
if input.VoiceModel == "" {
input.VoiceModel = "aura-asteria-en"
}
if input.Provider == "" {
input.Provider = "twilio"
}
return c.do(http.MethodPost, "/calls/demo/initiate", input, out)
}
func (c *Client) GetCallStatus(callID string, out any) error {
return c.do(http.MethodGet, "/calls/demo/"+url.PathEscape(callID)+"/status", nil, out)
}
func (c *Client) EndCall(callID string, out any) error {
return c.do(http.MethodPost, "/calls/demo/"+url.PathEscape(callID)+"/end", nil, out)
}