> ## Documentation Index
> Fetch the complete documentation index at: https://docs.yasmina.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Dotnet

# Yasminaai C# Library

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github\&utm_medium=github\&utm_campaign=readme\&utm_source=https%3A%2F%2Fgithub.com%2FYasminaAI%2Fmotor-dotnet-sdk)
[![nuget shield](https://img.shields.io/nuget/v/Yasmina.Motor.DotNet)](https://nuget.org/packages/Yasmina.Motor.DotNet)

The Yasminaai C# library provides convenient access to the Yasminaai APIs from C#.

## Table of Contents

* [Requirements](#requirements)
* [Installation](#installation)
* [Reference](#reference)
* [Usage](#usage)
* [Environments](#environments)
* [Exception Handling](#exception-handling)
* [Advanced](#advanced)
  * [Retries](#retries)
  * [Timeouts](#timeouts)
  * [Raw Response](#raw-response)
  * [Additional Headers](#additional-headers)
  * [Additional Query Parameters](#additional-query-parameters)
  * [Forward Compatible Enums](#forward-compatible-enums)
* [Contributing](#contributing)

## Requirements

This SDK requires:

## Installation

```sh theme={null}
dotnet add package Yasmina.Motor.DotNet
```

## Reference

A full reference for this library is available [here](https://github.com/YasminaAI/motor-dotnet-sdk/blob/HEAD/./reference.md).

## Usage

Instantiate and use the client with the following:

```csharp theme={null}
using YasminaaiApi;

var client = new YasminaaiApiClient("TOKEN");
await client.Quotes.RequestQuotesAsync(
    new PostQuoteRequestsRequest
    {
        Otp = "123456",
        OwnerId = "owner_id",
        Phone = "phone",
        Birthdate = new DateOnly(2023, 1, 15),
        CarEstimatedCost = 1.1,
    }
);
```

## Environments

This SDK allows you to configure different environments for API requests.

```csharp theme={null}
using YasminaaiApi;

var client = new YasminaaiApiClient(new ClientOptions
{
    BaseUrl = YasminaaiApiEnvironment.Sandbox
});
```

## Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
will be thrown.

```csharp theme={null}
using YasminaaiApi;

try {
    var response = await client.Quotes.RequestQuotesAsync(...);
} catch (YasminaaiApiApiException e) {
    System.Console.WriteLine(e.Body);
    System.Console.WriteLine(e.StatusCode);

    // Access the raw HTTP response (status code, URL, headers) off the exception
    var rawResponse = e.RawResponse;
    if (rawResponse != null)
    {
        System.Console.WriteLine(rawResponse.Url);
        if (rawResponse.Headers.TryGetValue("X-Request-Id", out var requestId))
        {
            System.Console.WriteLine($"Request ID: {requestId}");
        }
    }
}
```

## Advanced

### Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
retry limit (default: 2).

Which status codes are retried depends on the `retryStatusCodes` generator configuration:

**`legacy`** (current default): retries on

* [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
* [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
* [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (All server errors, including 500)

**`recommended`**: retries on

* [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
* [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
* [502](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502) (Bad Gateway)
* [503](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) (Service Unavailable)
* [504](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504) (Gateway Timeout)

Use the `MaxRetries` request option to configure this behavior.

```csharp theme={null}
var response = await client.Quotes.RequestQuotesAsync(
    ...,
    new RequestOptions {
        MaxRetries: 0 // Override MaxRetries at the request level
    }
);
```

### Timeouts

The SDK defaults to a 30 second timeout. Use the `Timeout` option to configure this behavior.

```csharp theme={null}
var response = await client.Quotes.RequestQuotesAsync(
    ...,
    new RequestOptions {
        Timeout: TimeSpan.FromSeconds(3) // Override timeout to 3s
    }
);
```

### Raw Response

Access raw HTTP response data (status code, headers, URL) alongside parsed response data using the `.WithRawResponse()` method.

```csharp theme={null}
using YasminaaiApi;

// Access raw response data (status code, headers, etc.) alongside the parsed response
var result = await client.Quotes.RequestQuotesAsync(...).WithRawResponse();

// Access the parsed data
var data = result.Data;

// Access raw response metadata
var statusCode = result.RawResponse.StatusCode;
var headers = result.RawResponse.Headers;
var url = result.RawResponse.Url;

// Access specific headers (case-insensitive)
if (headers.TryGetValue("X-Request-Id", out var requestId))
{
    System.Console.WriteLine($"Request ID: {requestId}");
}

// For the default behavior, simply await without .WithRawResponse()
var data = await client.Quotes.RequestQuotesAsync(...);

// .WithRawResponse() also works on streaming endpoints (returns IAsyncEnumerable<T> + RawResponse)
// and on endpoints with no response body (returns RawResponse only).
```

### Additional Headers

If you would like to send additional headers as part of the request, use the `AdditionalHeaders` request option.

```csharp theme={null}
var response = await client.Quotes.RequestQuotesAsync(
    ...,
    new RequestOptions {
        AdditionalHeaders = new Dictionary<string, string?>
        {
            { "X-Custom-Header", "custom-value" }
        }
    }
);
```

### Additional Query Parameters

If you would like to send additional query parameters as part of the request, use the `AdditionalQueryParameters` request option.

```csharp theme={null}
var response = await client.Quotes.RequestQuotesAsync(
    ...,
    new RequestOptions {
        AdditionalQueryParameters = new Dictionary<string, string>
        {
            { "custom_param", "custom-value" }
        }
    }
);
```

### Forward Compatible Enums

This SDK uses forward-compatible enums that can handle unknown values gracefully.

```csharp theme={null}
using YasminaaiApi;

// Using a built-in value
var postQuoteRequestsRequestAcceptLanguage = PostQuoteRequestsRequestAcceptLanguage.Ar;

// Using a custom value
var customPostQuoteRequestsRequestAcceptLanguage = PostQuoteRequestsRequestAcceptLanguage.FromCustom("custom-value");

// Using in a switch statement
switch (postQuoteRequestsRequestAcceptLanguage.Value)
{
    case PostQuoteRequestsRequestAcceptLanguage.Values.Ar:
        Console.WriteLine("Ar");
        break;
    default:
        Console.WriteLine($"Unknown value: {postQuoteRequestsRequestAcceptLanguage.Value}");
        break;
}

// Explicit casting
string postQuoteRequestsRequestAcceptLanguageString = (string)PostQuoteRequestsRequestAcceptLanguage.Ar;
PostQuoteRequestsRequestAcceptLanguage postQuoteRequestsRequestAcceptLanguageFromString = (PostQuoteRequestsRequestAcceptLanguage)"ar";
```

## Contributing

While we value open-source contributions to this SDK, this library is generated programmatically.
Additions made directly to this library would have to be moved over to our generation code,
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!
