Vapi Integration

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.

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.

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
1from vapi import Vapi
2from paygent_sdk.wrappers import VapiPaygentHook
3from paygent_sdk.models import LLMConfig, STTConfig, TTSConfig
4
5vapi_client = Vapi(token="vapi-token")
6
7# define the paygent hook
8hook = VapiPaygentHook(
9    agent_id="your-agent-id",
10    customer_id="vapi-phone-id",    
11    indicator_name="per-minute",
12    # Optional parameters
13    customer_name="John Doe",
14    llm_config=LLMConfig(model="gpt-4o", provider="openai"),
15    stt_config=STTConfig(model="nova-2", provider="deepgram"),
16    tts_config=TTSConfig(model="cartesia-v1", provider="cartesia")
17    )
18
19#attach the hook
20hook.attach(vapi_client)
21
22# All subsequent calls are now automatically tracked!
23vapi_client.calls.create(
24    assistant_id="vapi-assistant-id",
25    phone_number_id="vapi-phone-id",
26    customer={"number": "+1234567890"}
27)

Was this page helpful?

Need help? Contact us at support@withpaygent.com