Skip to content

Commit 91f4547

Browse files
committed
docs: document fallbackModel option in TypeScript and Python SDK references
Adds a "Model Fallback" section under Client Configuration explaining the feature with code examples, and adds the fallbackModel/fallback_model field to the guard, redact, and scan options tables in both SDK pages.
1 parent 7ac89b0 commit 91f4547

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

docs/content/docs/sdk/sdk/python.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ client = create_client(
7070

7171
The fallback URL can also be set via the `SUPERAGENT_FALLBACK_URL` environment variable.
7272

73+
### Model Fallback
74+
75+
When using third-party providers (e.g., Google Gemini), transient errors like 503 (high demand) or 429 (rate limited) can cause requests to fail. The SDK supports automatic model fallback: if the primary model returns a retryable error, the request is re-issued to a backup model you specify.
76+
77+
```python
78+
result = await client.guard(
79+
input="user message to analyze",
80+
model="google/gemini-2.5-flash-lite",
81+
fallback_model="google/gemini-2.5-pro"
82+
)
83+
```
84+
85+
If the primary model succeeds, `fallback_model` is never called. If it returns a retryable status code (429, 500, 502, or 503), the SDK automatically retries with the fallback model. The fallback model can be from a different provider entirely:
86+
87+
```python
88+
result = await client.guard(
89+
input="user message to analyze",
90+
model="google/gemini-2.5-flash-lite",
91+
fallback_model="openai/gpt-4o-mini"
92+
)
93+
```
94+
95+
The `fallback_model` option is available on `guard()`, `redact()`, and `scan()`. The fallback model gets a single attempt — there is no recursive fallback chain.
96+
7397
---
7498

7599
## Guard
@@ -92,6 +116,7 @@ if result.classification == "block":
92116
|--------|------|----------|---------|-------------|
93117
| `input` | `str \| bytes` | Yes | - | The input to analyze |
94118
| `model` | `str` | No | `superagent/guard-1.7b` | Model in `provider/model` format |
119+
| `fallback_model` | `str` | No | - | Backup model used when primary returns 429/500/502/503 |
95120
| `system_prompt` | `str` | No | - | Custom system prompt |
96121
| `chunk_size` | `int` | No | `8000` | Characters per chunk (0 to disable) |
97122

@@ -148,6 +173,7 @@ print(result.redacted)
148173
|--------|------|----------|---------|-------------|
149174
| `input` | `str` | Yes | - | The text to redact |
150175
| `model` | `str` | Yes | - | Model in `provider/model` format |
176+
| `fallback_model` | `str` | No | - | Backup model used when primary returns 429/500/502/503 |
151177
| `entities` | `list[str]` | No | Default PII | Entity types to redact |
152178
| `rewrite` | `bool` | No | `False` | Rewrite contextually instead of placeholders |
153179

@@ -216,6 +242,7 @@ print(f"Cost: ${response.usage.cost:.4f}")
216242
| `repo` | `str` | Yes | - | Git repository URL (https:// or git@) |
217243
| `branch` | `str` | No | Default branch | Branch, tag, or commit to checkout |
218244
| `model` | `str` | No | `anthropic/claude-sonnet-4-5` | Model for OpenCode analysis |
245+
| `fallback_model` | `str` | No | - | Backup model used when primary returns 429/500/502/503 |
219246

220247
### Response
221248

docs/content/docs/sdk/sdk/typescript.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ const client = createClient({
7070

7171
The fallback URL can also be set via the `SUPERAGENT_FALLBACK_URL` environment variable.
7272

73+
### Model Fallback
74+
75+
When using third-party providers (e.g., Google Gemini), transient errors like 503 (high demand) or 429 (rate limited) can cause requests to fail. The SDK supports automatic model fallback: if the primary model returns a retryable error, the request is re-issued to a backup model you specify.
76+
77+
```typescript
78+
const result = await client.guard({
79+
input: "user message to analyze",
80+
model: "google/gemini-2.5-flash-lite",
81+
fallbackModel: "google/gemini-2.5-pro"
82+
});
83+
```
84+
85+
If the primary model succeeds, `fallbackModel` is never called. If it returns a retryable status code (429, 500, 502, or 503), the SDK automatically retries with the fallback model. The fallback model can be from a different provider entirely:
86+
87+
```typescript
88+
const result = await client.guard({
89+
input: "user message to analyze",
90+
model: "google/gemini-2.5-flash-lite",
91+
fallbackModel: "openai/gpt-4o-mini"
92+
});
93+
```
94+
95+
The `fallbackModel` option is available on `guard()`, `redact()`, and `scan()`. The fallback model gets a single attempt — there is no recursive fallback chain.
96+
7397
---
7498

7599
## Guard
@@ -95,6 +119,7 @@ if (result.classification === "block") {
95119
|--------|------|----------|---------|-------------|
96120
| `input` | `string \| Blob \| URL` | Yes | - | The input to analyze |
97121
| `model` | `string` | No | `superagent/guard-1.7b` | Model in `provider/model` format |
122+
| `fallbackModel` | `string` | No | - | Backup model used when primary returns 429/500/502/503 |
98123
| `systemPrompt` | `string` | No | - | Custom system prompt |
99124
| `chunkSize` | `number` | No | `8000` | Characters per chunk (0 to disable) |
100125

@@ -155,6 +180,7 @@ console.log(result.redacted);
155180
|--------|------|----------|---------|-------------|
156181
| `input` | `string` | Yes | - | The text to redact |
157182
| `model` | `string` | Yes | - | Model in `provider/model` format |
183+
| `fallbackModel` | `string` | No | - | Backup model used when primary returns 429/500/502/503 |
158184
| `entities` | `string[]` | No | Default PII | Entity types to redact |
159185
| `rewrite` | `boolean` | No | `false` | Rewrite contextually instead of placeholders |
160186

@@ -225,6 +251,7 @@ console.log(`Cost: $${response.usage.cost.toFixed(4)}`);
225251
| `repo` | `string` | Yes | - | Git repository URL (https:// or git@) |
226252
| `branch` | `string` | No | Default branch | Branch, tag, or commit to checkout |
227253
| `model` | `string` | No | `anthropic/claude-sonnet-4-5` | Model for OpenCode analysis |
254+
| `fallbackModel` | `string` | No | - | Backup model used when primary returns 429/500/502/503 |
228255

229256
### Response
230257

0 commit comments

Comments
 (0)