Yasminaai Go Library
Table of Contents
Reference
A full reference for this library is available here.Usage
Instantiate and use the client with the following:Environments
You can choose between different environments by using theoption.WithBaseURL option. You can configure any arbitrary base
URL, which is particularly useful in test environments.
Errors
Structured error types are returned from API calls that return non-success status codes. These errors are compatible with theerrors.Is and errors.As APIs, so you can access the error like so:
Request Options
A variety of request options are included to adapt the behavior of the library, which includes configuring authorization tokens, or providing your own instrumented*http.Client.
These request options can either be
specified on the client so that they’re applied on every request, or for an individual request, like so:
Providing your own*http.Clientis recommended. Otherwise, thehttp.DefaultClientwill be used, and your client will wait indefinitely for a response (unless the per-request, context-based timeout is used).
Advanced
Response Headers
You can access the raw HTTP response data by using theWithRawResponse field on the client. This is useful
when you need to examine the response headers received from the API call. (When the endpoint is paginated,
the raw HTTP response data will be included automatically in the Page response object.)
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 theretryStatusCodes generator configuration:
legacy (current default): retries on
recommended: retries on
- 408 (Timeout)
- 429 (Too Many Requests)
- 502 (Bad Gateway)
- 503 (Service Unavailable)
- 504 (Gateway Timeout)
Retry-After header is present in the response, the SDK will prioritize respecting its value exactly
over the default exponential backoff.
Use the option.WithMaxAttempts option to configure this behavior for the entire client or an individual request:
Timeouts
Setting a timeout for each individual request is as simple as using the standard context library. Setting a one second timeout for an individual API call looks like the following:Explicit Null
If you want to send the explicitnull JSON value through an optional parameter, you can use the settersthat come with every object. Calling a setter method for a property will flip a bit in the
explicitFields
bitfield for that setter’s object; during serialization, any property with a flipped bit will have its
omittable status stripped, so zero or nil values will be sent explicitly rather than omitted altogether:

