Skip to main content

Overview

This comprehensive guide covers everything you need to integrate with Hamsa’s platform, including REST APIs, real-time WebSocket connections, the Voice Agents SDK, webhooks, and the tool system. Whether you’re building a simple integration or a complex production system, this guide has you covered.
What This Guide Covers:
  • Authentication methods for all API types
  • REST API integration patterns
  • Real-time Speech-to-Text and Text-to-Speech APIs
  • Voice Agents Web SDK
  • Webhook integration for event-driven architectures
  • Tool system for extending agent capabilities
  • Error handling and edge cases
  • Rate limiting and quota management
  • Production best practices

Authentication

Hamsa uses different authentication methods depending on the API type. Understanding these is crucial for successful integration.

API Key Token Authentication

Used for all REST API endpoints.
Security Best Practices:
  • Never expose API keys in client-side code
  • Store keys in environment variables or secure vaults
  • Use separate keys for development and production
  • Rotate keys periodically
  • Use least-privilege keys when possible

Bearer Token (JWT) Authentication

Used for webhooks and tool authentication that the user adds to the system.

Custom Header Authentication

For tools and integrations that require custom authentication schemes.

Getting Your API Key

1

Create Account

Sign up at Hamsa Agents
2

Navigate to API Keys

Go to SettingsAPI Keys in the dashboard
3

Create New Key

Click Create API Key and provide a descriptive name
4

Copy and Store Securely

Copy the key immediately - it won’t be shown again

REST API Integration

Base URL

All REST API requests use the following base URL:

API Versioning

Hamsa provides multiple API versions. Use the version specified in the endpoint path:
Some v1 endpoints are marked as deprecated in the API reference. For these endpoints, migrate to the v2 equivalent when available. Endpoints not marked as deprecated are fully supported.

Request Format

All requests should include:

Response Format

Almost all responses follow a consistent structure: Success Response:
Error Response:

Core API Endpoints

Voice Agents

Create Agent Example:

Phone Numbers

Knowledge Base

Knowledge Base Item Types:
  • TEXT - Structured text content (50-5,000 characters)
  • FILE - PDF, DOCS, DOC, TXT, HTML, EPUB.
  • URL - Web pages (up to 100 URLs per item)

Web Tools (Custom API Integration)

Campaigns (Outbound Calling)

Call History & Conversations

Media Processing (Jobs)


Real-Time APIs

Real-Time Speech-to-Text (WebSocket)

Connect to the real-time STT endpoint for live transcription:
Supported Audio Formats:
  • linear16 - 16-bit linear PCM
  • mulaw - 8-bit μ-law

Real-Time Text-to-Speech (REST)

Standard TTS Request:
Streaming TTS Request: If you are facing any issues while working with this endpoint, please refer to this JSFiddle which has a solution our team created as an example.

Voice Agents SDK Integration

The Hamsa Voice Agents SDK provides a seamless way to embed voice interactions into web applications.

Installation

Or via CDN:

Basic Usage

Advanced Configuration

Audio Controls

Analytics & Monitoring

Conversation Control


Webhook Integration

Webhooks provide real-time notifications about call events, transcriptions, and outcomes.

Webhook Events

Setting Up Webhooks

1

Create Webhook Endpoint

Create a publicly accessible HTTPS endpoint that accepts POST requests.
2

Configure in Dashboard

Navigate to your agent’s settings and add the webhook URL.
3

Set Authentication

Configure Bearer token authentication for security.
4

Handle Events

Implement handlers for different event types.

Webhook Configuration

Webhook Handler Implementation

Call Ended Payload Structure

Webhook Best Practices

Respond Quickly

Return 200 OK within 5 seconds to avoid timeouts

Process Async

Queue events for async processing after acknowledging

Implement Idempotency

Use callId + eventType + timestamp to detect duplicates

Secure Endpoints

Use HTTPS and Bearer token authentication

Error Handling

HTTP Status Codes

Common Error Codes

Error codes are created by adding two pieces of numbers, first piece refers to the system part responsible for that error, and the second is the status code. Status code is always the last three numbers.

Error Handling Pattern


Rate Limiting & Quotas

Rate Limits

Rate Limit Headers

Handling Rate Limits

Storage Quotas

Edge Cases & Best Practices

Network Connectivity Issues

Handling Partial Responses

Concurrent Request Management

Idempotency for Critical Operations

Graceful Degradation


Production Deployment Checklist

Security

  • API keys stored in secure vault/environment variables
  • HTTPS enabled for all endpoints
  • Bearer token authentication for webhooks
  • Input validation on all endpoints
  • Rate limiting implemented
  • Secrets rotated regularly
  • Audit logging enabled

Reliability

  • Retry logic with exponential backoff
  • Circuit breaker pattern for external calls
  • Idempotency for critical operations
  • Dead letter queue for failed webhooks
  • Health check endpoints
  • Graceful shutdown handling

Monitoring

  • Error tracking (Sentry, etc.)
  • API metrics (latency, error rates)
  • Webhook delivery monitoring
  • Call analytics dashboard
  • Alerting for anomalies
  • Log aggregation

Performance

  • Connection pooling
  • Request queuing
  • Response caching where appropriate
  • Async processing for webhooks
  • Database query optimization
  • CDN for static assets

Next Steps

API Reference

Complete API endpoint documentation

Voice Agents Web SDK

Full SDK reference and examples

Webhook Guide

Deep dive into webhook integration

Tool System

Integrate external APIs with agents

Support

Contact Support

Get help from our technical team

Documentation

Browse complete documentation
Document Version: 1.0
Last Updated: 2026-01-07
API Version: v2.0.0