Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fern/products/sdks/capabilities.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ layout: overview
<Card title="OAuth Token Refresh" icon="fa-duotone fa-arrows-rotate">
Fern supports OAuth as a first class citizen
</Card>
<Card title="Retries with Backoff" icon="fa-duotone fa-repeat">
<Card title="Retries with Backoff" icon="fa-duotone fa-repeat" href="/sdks/deep-dives/retries-with-backoff">
Automatically retry failed requests with exponential backoff
</Card>
<Card title="Webhook Signature Verification" icon="fa-duotone fa-key">
Expand Down
107 changes: 107 additions & 0 deletions fern/products/sdks/guides/retries-with-backoff.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: Retries with Backoff
description: Automatically retry failures with exponential backoff
---

<Markdown src="/snippets/pro-callout.mdx" />

Fern SDKs will automatically retry failed requests 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.

### Retryable status codes

A request is deemed retryable when any of the following HTTP status codes is returned:
- [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/500) (Internal Server Errors)

Note that you can configure the list of retryable status codes as well. For example,
if you want to remove the `429` status code from the list of retryable status codes, you can do so.

### Overriding the retry limit

By default, the SDK will retry a failed request up to 2 times. SDK users can override the global
default retry limit when instantiating the client.

<CodeBlocks>
<CodeBlock title="TypeScript">
```ts {4}
import { ImdbClient } from "imdb";

const client = new ImdbClient({
maxRetries: 1 // overrides the default retry limit to 1
});
```
</CodeBlock>
<CodeBlock title="Python">
```python {4, 8}
from imdb.client import Imdb, AsyncImdb

client = Imdb({
max_retries: 1 # overrides the default retry limit to 1
})

async_client = AsyncImdb({
max_retries: 1 # overrides the default retry limit to 1
})
```
</CodeBlock>
<CodeBlock title="Java">
```java {4}
import com.imdb.ImdbClient;

ImdbClient client = new ImdbClient.Builder()
.maxRetries(1) // overrides the default retry limit to 1
.build();
```
</CodeBlock>
<CodeBlock title="Go">
```go {7}
import (
imdbclient "github.com/fern-workos/workos-go/client"
"github.com/fern-workos/workos-go/option"
)

client := imdbclient.NewClient(
option.WithMaxAttempts(1), // overrides the default retry limit to 1
)
```
</CodeBlock>
</CodeBlocks>

It's also possible to override the retry limit on a per-request basis.

<CodeBlocks>
<CodeBlock title="TypeScript">
```ts {2}
client.movie.get("tt0111161", {
maxRetries: 3 // overrides the default retry limit to 3
});
```
</CodeBlock>
<CodeBlock title="Python">
```python {2}
client.movie.get("tt0111161", {
max_retries: 3 // overrides the default retry limit to 3
})
```
</CodeBlock>
<CodeBlock title="Java">
```java {2}
client.movie().get("tt0111161", RequestOptions.builder()
.maxRetries(3) // overrides the default retry limit to 3
.build());
```
</CodeBlock>
<CodeBlock title="Go">
```go {4}
response, err := client.Movies.Get(
ctx,
"tt0111161",
option.WithMaxAttempts(1),
)
```
</CodeBlock>
</CodeBlocks>

2 changes: 2 additions & 0 deletions fern/products/sdks/sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ navigation:
hidden: true
path: ./guides/self-host-fern-generators.mdx
slug: self-host-generators
- page: Retries with Backoff
path: ./guides/retries-with-backoff.mdx
- section: Reference
contents:
- page: generators.yml
Expand Down