> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.withpaygent.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.withpaygent.com/_mcp/server.

# 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.

> **Warning**
>
> **Prerequisite:** Complete the [Voice Agent Setup](/documentation/voice-tracking/voice-agent-setup) before implementing voice tracking.

> **Warning**
>
> **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`**

```python title="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"}
)
```