Skip to content

Conversation

@pavelgj
Copy link
Collaborator

@pavelgj pavelgj commented Nov 7, 2025

import { retry } from 'genkit/model/middleware';

const { text } = await ai.generate({
  model: googleAI.model('gemini-2.5-pro'),
  prompt: 'You are a helpful AI assistant named Walt, say hello',
  use: [
    retry({
      maxRetries: 2,
      initialDelayMs: 1000,
      backoffFactor: 2,
    }),
  ],
});
import { fallback } from 'genkit/model/middleware';

const { text } = await ai.generate({
  model: googleAI.model('gemini-2.5-pro'),
  prompt: 'You are a helpful AI assistant named Walt, say hello',
  use: [
    fallback(ai, {
      models: [googleAI.model('gemini-2.5-flash')],
      statuses: ['RESOURCE_EXHAUSTED'],
    }),
  ],
});

Checklist (if applicable):

```ts
const { text } = await ai.generate({
  model: googleAI.model('gemini-2.5-pro'),
  prompt: 'You are a helpful AI assistant named Walt, say hello',
  use: [
    retry({
      maxRetries: 2,
      initialDelayMs: 1000,
      backoffFactor: 2,
    }),
  ],
});
```

```ts
const { text } = await ai.generate({
  model: googleAI.model('gemini-2.5-pro'),
  prompt: 'You are a helpful AI assistant named Walt, say hello',
  use: [
    fallback(ai, {
      models: [googleAI.model('gemini-2.5-flash')],
      statuses: ['RESOURCE_EXHAUSTED'],
    }),
  ],
});
```
@github-actions github-actions bot added docs Improvements or additions to documentation js labels Nov 7, 2025
@pavelgj pavelgj requested review from ifielker and ssbushi November 7, 2025 17:37
@pavelgj pavelgj requested a review from ifielker November 7, 2025 21:04
@pavelgj pavelgj merged commit 72af9c3 into main Nov 11, 2025
5 checks passed
@pavelgj pavelgj deleted the pj/retry-fallback-middleware branch November 11, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation js

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants