|
| 1 | +# Vapi C# Library |
| 2 | + |
| 3 | +[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2FVapiAI%2Fserver-sdk-csharp) |
| 4 | +[](https://nuget.org/packages/Vapi.Net) |
| 5 | + |
| 6 | +The Vapi C# library provides convenient access to the Vapi API from C#. |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +```sh |
| 11 | +nuget install Vapi.Net |
| 12 | +``` |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +Instantiate and use the client with the following: |
| 17 | + |
| 18 | +```csharp |
| 19 | +using Vapi.Net; |
| 20 | + |
| 21 | +var client = new VapiClient("TOKEN"); |
| 22 | +await client.Calls.CreateAsync(new CreateCallDto()); |
| 23 | +``` |
| 24 | + |
| 25 | +## Exception Handling |
| 26 | + |
| 27 | +When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error |
| 28 | +will be thrown. |
| 29 | + |
| 30 | +```csharp |
| 31 | +using Vapi.Net; |
| 32 | + |
| 33 | +try { |
| 34 | + var response = await client.Calls.CreateAsync(...); |
| 35 | +} catch (VapiClientApiException e) { |
| 36 | + System.Console.WriteLine(e.Body); |
| 37 | + System.Console.WriteLine(e.StatusCode); |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +## Advanced |
| 42 | + |
| 43 | +### Retries |
| 44 | + |
| 45 | +The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long |
| 46 | +as the request is deemed retriable and the number of retry attempts has not grown larger than the configured |
| 47 | +retry limit (default: 2). |
| 48 | + |
| 49 | +A request is deemed retriable when any of the following HTTP status codes is returned: |
| 50 | + |
| 51 | +- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout) |
| 52 | +- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests) |
| 53 | +- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors) |
| 54 | + |
| 55 | +Use the `MaxRetries` request option to configure this behavior. |
| 56 | + |
| 57 | +```csharp |
| 58 | +var response = await client.Calls.CreateAsync( |
| 59 | + ..., |
| 60 | + new RequestOptions { |
| 61 | + MaxRetries: 0 // Override MaxRetries at the request level |
| 62 | + } |
| 63 | +); |
| 64 | +``` |
| 65 | + |
| 66 | +### Timeouts |
| 67 | + |
| 68 | +The SDK defaults to a 30 second timeout. Use the `Timeout` option to configure this behavior. |
| 69 | + |
| 70 | +```csharp |
| 71 | +var response = await client.Calls.CreateAsync( |
| 72 | + ..., |
| 73 | + new RequestOptions { |
| 74 | + Timeout: TimeSpan.FromSeconds(3) // Override timeout to 3s |
| 75 | + } |
| 76 | +); |
| 77 | +``` |
| 78 | + |
| 79 | +## Contributing |
| 80 | + |
| 81 | +While we value open-source contributions to this SDK, this library is generated programmatically. |
| 82 | +Additions made directly to this library would have to be moved over to our generation code, |
| 83 | +otherwise they would be overwritten upon the next generated release. Feel free to open a PR as |
| 84 | +a proof of concept, but know that we will not be able to merge it as-is. We suggest opening |
| 85 | +an issue first to discuss with us! |
| 86 | + |
| 87 | +On the other hand, contributions to the README are always very welcome! |
0 commit comments