Skip to navigation

Vapi Integration

Automatically track usage for Vapi Voice Agents using the VapiPaygentHook. This hook enriches your outbound calls with Paygent identity metadata, allowing the backend to attribute costs correctly.

Prerequisite: Complete the Voice Agent Setup before implementing voice tracking.

Required Vapi Configuration. To enable automatic usage reporting, you must configure the Server URL in your Vapi dashboard:

  1. Navigate to Settings > Org Settings > Server URL.
  2. Set the Server URL to: https://cp-api.withpaygent.com/api/v1/webhooks/vapi
  3. Add the following Custom Header:
    • Header Key: paygent-api-key
    • Header Value: "your-paygent-api-key"

Use attach() to automatically enrich all calls made by a Vapi client instance.

vapi_automatic.py
from vapi import Vapi
from paygent_sdk.wrappers import VapiPaygentHook
from paygent_sdk.models import LLMConfig, STTConfig, TTSConfig
vapi_client = Vapi(token="vapi-token")
# define the paygent hook
hook = VapiPaygentHook(
agent_id="your-agent-id",
customer_id="vapi-phone-id",
indicator_name="per-minute",
# Optional parameters
customer_name="John Doe",
llm_config=LLMConfig(model="gpt-4o", provider="openai"),
stt_config=STTConfig(model="nova-2", provider="deepgram"),
tts_config=TTSConfig(model="cartesia-v1", provider="cartesia")
)
#attach the hook
hook.attach(vapi_client)
# All subsequent calls are now automatically tracked!
vapi_client.calls.create(
assistant_id="vapi-assistant-id",
phone_number_id="vapi-phone-id",
customer={"number": "+1234567890"}
)