| 1 | from paygent_sdk import Client |
| 2 | from paygent_sdk.models import SpeechToSpeechUsageMetadata, StsInputSide, StsOutputSide, StsModalityUsage |
| 3 | |
| 4 | from paygent_sdk.models import CustomerCreateOrGetRequest |
| 5 | |
| 6 | paygent = Client("your-paygent-api-key") |
| 7 | session_id = f"voice_call_{int(time.time() * 1000)}" |
| 8 | customer_id = "customer-manual-123" |
| 9 | |
| 10 | # 1. Ensure Customer exists |
| 11 | paygent.create_or_get_customer(CustomerCreateOrGetRequest( |
| 12 | name="Manual Customer", |
| 13 | external_id=customer_id |
| 14 | )) |
| 15 | |
| 16 | # 2. Initialize Voice Session |
| 17 | paygent.initialize_voice_session(session_id, "external-agent-id", customer_id) |
| 18 | |
| 19 | # 3. Construct usage metadata manually |
| 20 | usage = SpeechToSpeechUsageMetadata( |
| 21 | input=StsInputSide( |
| 22 | audio=StsModalityUsage(minutes=1.2), |
| 23 | text=StsModalityUsage(tokens=150) |
| 24 | ), |
| 25 | output=StsOutputSide( |
| 26 | audio=StsModalityUsage(minutes=2.5), |
| 27 | text=StsModalityUsage(tokens=400) |
| 28 | ), |
| 29 | ) |
| 30 | |
| 31 | # 4. Track STS |
| 32 | paygent.track_voice_sts( |
| 33 | session_id=session_id, |
| 34 | usage_metadata=usage, |
| 35 | service_provider="custom-provider", |
| 36 | model="custom-model" |
| 37 | ) |
| 38 | |
| 39 | # 5. Finalize Session |
| 40 | paygent.set_voice_indicator(session_id, indicator_name, 3.0) |