-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathclient.py
More file actions
439 lines (341 loc) · 16.6 KB
/
client.py
File metadata and controls
439 lines (341 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# This file was auto-generated by Fern from our API Definition.
from __future__ import annotations
import typing
import httpx
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .environment import VapiEnvironment
if typing.TYPE_CHECKING:
from .analytics.client import AnalyticsClient, AsyncAnalyticsClient
from .assistants.client import AssistantsClient, AsyncAssistantsClient
from .calls.client import AsyncCallsClient, CallsClient
from .campaigns.client import AsyncCampaignsClient, CampaignsClient
from .chats.client import AsyncChatsClient, ChatsClient
from .eval.client import AsyncEvalClient, EvalClient
from .files.client import AsyncFilesClient, FilesClient
from .insight.client import AsyncInsightClient, InsightClient
from .observability_scorecard.client import AsyncObservabilityScorecardClient, ObservabilityScorecardClient
from .phone_numbers.client import AsyncPhoneNumbersClient, PhoneNumbersClient
from .provider_resources.client import AsyncProviderResourcesClient, ProviderResourcesClient
from .sessions.client import AsyncSessionsClient, SessionsClient
from .squads.client import AsyncSquadsClient, SquadsClient
from .structured_outputs.client import AsyncStructuredOutputsClient, StructuredOutputsClient
from .tools.client import AsyncToolsClient, ToolsClient
class Vapi:
"""
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
Parameters
----------
base_url : typing.Optional[str]
The base url to use for requests from the client.
environment : VapiEnvironment
The environment to use for requests from the client. from .environment import VapiEnvironment
Defaults to VapiEnvironment.DEFAULT
token : typing.Union[str, typing.Callable[[], str]]
headers : typing.Optional[typing.Dict[str, str]]
Additional headers to send with every request.
timeout : typing.Optional[float]
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
follow_redirects : typing.Optional[bool]
Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
httpx_client : typing.Optional[httpx.Client]
The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
Examples
--------
from vapi import Vapi
client = Vapi(
token="YOUR_TOKEN",
)
"""
def __init__(
self,
*,
base_url: typing.Optional[str] = None,
environment: VapiEnvironment = VapiEnvironment.DEFAULT,
token: typing.Union[str, typing.Callable[[], str]],
headers: typing.Optional[typing.Dict[str, str]] = None,
timeout: typing.Optional[float] = None,
follow_redirects: typing.Optional[bool] = True,
httpx_client: typing.Optional[httpx.Client] = None,
):
_defaulted_timeout = (
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
)
self._client_wrapper = SyncClientWrapper(
base_url=_get_base_url(base_url=base_url, environment=environment),
token=token,
headers=headers,
httpx_client=httpx_client
if httpx_client is not None
else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
if follow_redirects is not None
else httpx.Client(timeout=_defaulted_timeout),
timeout=_defaulted_timeout,
)
self._assistants: typing.Optional[AssistantsClient] = None
self._squads: typing.Optional[SquadsClient] = None
self._calls: typing.Optional[CallsClient] = None
self._chats: typing.Optional[ChatsClient] = None
self._campaigns: typing.Optional[CampaignsClient] = None
self._sessions: typing.Optional[SessionsClient] = None
self._phone_numbers: typing.Optional[PhoneNumbersClient] = None
self._tools: typing.Optional[ToolsClient] = None
self._files: typing.Optional[FilesClient] = None
self._structured_outputs: typing.Optional[StructuredOutputsClient] = None
self._insight: typing.Optional[InsightClient] = None
self._eval: typing.Optional[EvalClient] = None
self._observability_scorecard: typing.Optional[ObservabilityScorecardClient] = None
self._provider_resources: typing.Optional[ProviderResourcesClient] = None
self._analytics: typing.Optional[AnalyticsClient] = None
@property
def assistants(self):
if self._assistants is None:
from .assistants.client import AssistantsClient # noqa: E402
self._assistants = AssistantsClient(client_wrapper=self._client_wrapper)
return self._assistants
@property
def squads(self):
if self._squads is None:
from .squads.client import SquadsClient # noqa: E402
self._squads = SquadsClient(client_wrapper=self._client_wrapper)
return self._squads
@property
def calls(self):
if self._calls is None:
from .calls.client import CallsClient # noqa: E402
self._calls = CallsClient(client_wrapper=self._client_wrapper)
return self._calls
@property
def chats(self):
if self._chats is None:
from .chats.client import ChatsClient # noqa: E402
self._chats = ChatsClient(client_wrapper=self._client_wrapper)
return self._chats
@property
def campaigns(self):
if self._campaigns is None:
from .campaigns.client import CampaignsClient # noqa: E402
self._campaigns = CampaignsClient(client_wrapper=self._client_wrapper)
return self._campaigns
@property
def sessions(self):
if self._sessions is None:
from .sessions.client import SessionsClient # noqa: E402
self._sessions = SessionsClient(client_wrapper=self._client_wrapper)
return self._sessions
@property
def phone_numbers(self):
if self._phone_numbers is None:
from .phone_numbers.client import PhoneNumbersClient # noqa: E402
self._phone_numbers = PhoneNumbersClient(client_wrapper=self._client_wrapper)
return self._phone_numbers
@property
def tools(self):
if self._tools is None:
from .tools.client import ToolsClient # noqa: E402
self._tools = ToolsClient(client_wrapper=self._client_wrapper)
return self._tools
@property
def files(self):
if self._files is None:
from .files.client import FilesClient # noqa: E402
self._files = FilesClient(client_wrapper=self._client_wrapper)
return self._files
@property
def structured_outputs(self):
if self._structured_outputs is None:
from .structured_outputs.client import StructuredOutputsClient # noqa: E402
self._structured_outputs = StructuredOutputsClient(client_wrapper=self._client_wrapper)
return self._structured_outputs
@property
def insight(self):
if self._insight is None:
from .insight.client import InsightClient # noqa: E402
self._insight = InsightClient(client_wrapper=self._client_wrapper)
return self._insight
@property
def eval(self):
if self._eval is None:
from .eval.client import EvalClient # noqa: E402
self._eval = EvalClient(client_wrapper=self._client_wrapper)
return self._eval
@property
def observability_scorecard(self):
if self._observability_scorecard is None:
from .observability_scorecard.client import ObservabilityScorecardClient # noqa: E402
self._observability_scorecard = ObservabilityScorecardClient(client_wrapper=self._client_wrapper)
return self._observability_scorecard
@property
def provider_resources(self):
if self._provider_resources is None:
from .provider_resources.client import ProviderResourcesClient # noqa: E402
self._provider_resources = ProviderResourcesClient(client_wrapper=self._client_wrapper)
return self._provider_resources
@property
def analytics(self):
if self._analytics is None:
from .analytics.client import AnalyticsClient # noqa: E402
self._analytics = AnalyticsClient(client_wrapper=self._client_wrapper)
return self._analytics
class AsyncVapi:
"""
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
Parameters
----------
base_url : typing.Optional[str]
The base url to use for requests from the client.
environment : VapiEnvironment
The environment to use for requests from the client. from .environment import VapiEnvironment
Defaults to VapiEnvironment.DEFAULT
token : typing.Union[str, typing.Callable[[], str]]
headers : typing.Optional[typing.Dict[str, str]]
Additional headers to send with every request.
timeout : typing.Optional[float]
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
follow_redirects : typing.Optional[bool]
Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
httpx_client : typing.Optional[httpx.AsyncClient]
The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
Examples
--------
from vapi import AsyncVapi
client = AsyncVapi(
token="YOUR_TOKEN",
)
"""
def __init__(
self,
*,
base_url: typing.Optional[str] = None,
environment: VapiEnvironment = VapiEnvironment.DEFAULT,
token: typing.Union[str, typing.Callable[[], str]],
headers: typing.Optional[typing.Dict[str, str]] = None,
timeout: typing.Optional[float] = None,
follow_redirects: typing.Optional[bool] = True,
httpx_client: typing.Optional[httpx.AsyncClient] = None,
):
_defaulted_timeout = (
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
)
self._client_wrapper = AsyncClientWrapper(
base_url=_get_base_url(base_url=base_url, environment=environment),
token=token,
headers=headers,
httpx_client=httpx_client
if httpx_client is not None
else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
if follow_redirects is not None
else httpx.AsyncClient(timeout=_defaulted_timeout),
timeout=_defaulted_timeout,
)
self._assistants: typing.Optional[AsyncAssistantsClient] = None
self._squads: typing.Optional[AsyncSquadsClient] = None
self._calls: typing.Optional[AsyncCallsClient] = None
self._chats: typing.Optional[AsyncChatsClient] = None
self._campaigns: typing.Optional[AsyncCampaignsClient] = None
self._sessions: typing.Optional[AsyncSessionsClient] = None
self._phone_numbers: typing.Optional[AsyncPhoneNumbersClient] = None
self._tools: typing.Optional[AsyncToolsClient] = None
self._files: typing.Optional[AsyncFilesClient] = None
self._structured_outputs: typing.Optional[AsyncStructuredOutputsClient] = None
self._insight: typing.Optional[AsyncInsightClient] = None
self._eval: typing.Optional[AsyncEvalClient] = None
self._observability_scorecard: typing.Optional[AsyncObservabilityScorecardClient] = None
self._provider_resources: typing.Optional[AsyncProviderResourcesClient] = None
self._analytics: typing.Optional[AsyncAnalyticsClient] = None
@property
def assistants(self):
if self._assistants is None:
from .assistants.client import AsyncAssistantsClient # noqa: E402
self._assistants = AsyncAssistantsClient(client_wrapper=self._client_wrapper)
return self._assistants
@property
def squads(self):
if self._squads is None:
from .squads.client import AsyncSquadsClient # noqa: E402
self._squads = AsyncSquadsClient(client_wrapper=self._client_wrapper)
return self._squads
@property
def calls(self):
if self._calls is None:
from .calls.client import AsyncCallsClient # noqa: E402
self._calls = AsyncCallsClient(client_wrapper=self._client_wrapper)
return self._calls
@property
def chats(self):
if self._chats is None:
from .chats.client import AsyncChatsClient # noqa: E402
self._chats = AsyncChatsClient(client_wrapper=self._client_wrapper)
return self._chats
@property
def campaigns(self):
if self._campaigns is None:
from .campaigns.client import AsyncCampaignsClient # noqa: E402
self._campaigns = AsyncCampaignsClient(client_wrapper=self._client_wrapper)
return self._campaigns
@property
def sessions(self):
if self._sessions is None:
from .sessions.client import AsyncSessionsClient # noqa: E402
self._sessions = AsyncSessionsClient(client_wrapper=self._client_wrapper)
return self._sessions
@property
def phone_numbers(self):
if self._phone_numbers is None:
from .phone_numbers.client import AsyncPhoneNumbersClient # noqa: E402
self._phone_numbers = AsyncPhoneNumbersClient(client_wrapper=self._client_wrapper)
return self._phone_numbers
@property
def tools(self):
if self._tools is None:
from .tools.client import AsyncToolsClient # noqa: E402
self._tools = AsyncToolsClient(client_wrapper=self._client_wrapper)
return self._tools
@property
def files(self):
if self._files is None:
from .files.client import AsyncFilesClient # noqa: E402
self._files = AsyncFilesClient(client_wrapper=self._client_wrapper)
return self._files
@property
def structured_outputs(self):
if self._structured_outputs is None:
from .structured_outputs.client import AsyncStructuredOutputsClient # noqa: E402
self._structured_outputs = AsyncStructuredOutputsClient(client_wrapper=self._client_wrapper)
return self._structured_outputs
@property
def insight(self):
if self._insight is None:
from .insight.client import AsyncInsightClient # noqa: E402
self._insight = AsyncInsightClient(client_wrapper=self._client_wrapper)
return self._insight
@property
def eval(self):
if self._eval is None:
from .eval.client import AsyncEvalClient # noqa: E402
self._eval = AsyncEvalClient(client_wrapper=self._client_wrapper)
return self._eval
@property
def observability_scorecard(self):
if self._observability_scorecard is None:
from .observability_scorecard.client import AsyncObservabilityScorecardClient # noqa: E402
self._observability_scorecard = AsyncObservabilityScorecardClient(client_wrapper=self._client_wrapper)
return self._observability_scorecard
@property
def provider_resources(self):
if self._provider_resources is None:
from .provider_resources.client import AsyncProviderResourcesClient # noqa: E402
self._provider_resources = AsyncProviderResourcesClient(client_wrapper=self._client_wrapper)
return self._provider_resources
@property
def analytics(self):
if self._analytics is None:
from .analytics.client import AsyncAnalyticsClient # noqa: E402
self._analytics = AsyncAnalyticsClient(client_wrapper=self._client_wrapper)
return self._analytics
def _get_base_url(*, base_url: typing.Optional[str] = None, environment: VapiEnvironment) -> str:
if base_url is not None:
return base_url
elif environment is not None:
return environment.value
else:
raise Exception("Please pass in either base_url or environment to construct the client")