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
5 changes: 5 additions & 0 deletions .changeset/olive-feet-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ai-sdk/gateway': patch
---

feat (provider/gateway): add zero data retention provider option
25 changes: 25 additions & 0 deletions content/providers/01-ai-sdk-providers/00-ai-gateway.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ The following gateway provider options are available:
- Multiple credentials: `byok: { 'vertex': [{ projectId: 'proj-1', privateKey: '...' }, { projectId: 'proj-2', privateKey: '...' }] }`
- Multiple providers: `byok: { 'anthropic': [{ apiKey: '...' }], 'bedrock': [{ accessKeyId: '...', secretAccessKey: '...' }] }`

- **zeroDataRetention** _boolean_

Restricts routing requests to providers that have zero data retention policies.

You can combine these options to have fine-grained control over routing and tracking:

```ts
Expand Down Expand Up @@ -455,6 +459,27 @@ const { text } = await generateText({
// 4. Return the result from the first model that succeeds
```

#### Zero Data Retention Example

Set `zeroDataRetention` to true to ensure requests are only routed to providers
that have zero data retention policies. When `zeroDataRetention` is `false` or not
specified, there is no enforcement of restricting routing.

```ts
import type { GatewayProviderOptions } from '@ai-sdk/gateway';
import { generateText } from 'ai';

const { text } = await generateText({
model: 'anthropic/claude-sonnet-4.5',
prompt: 'Analyze this sensitive document...',
providerOptions: {
gateway: {
zeroDataRetention: true,
} satisfies GatewayProviderOptions,
},
});
```

### Provider-Specific Options

When using provider-specific options through AI Gateway, use the actual provider name (e.g. `anthropic`, `openai`, not `gateway`) as the key:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { GatewayProviderOptions } from '@ai-sdk/gateway';
import { streamText } from 'ai';
import 'dotenv/config';

async function main() {
const result = streamText({
model: 'openai/gpt-oss-120b',
prompt: 'Tell me the history of the tenrec in a few sentences.',
providerOptions: {
gateway: {
zeroDataRetention: true,
} satisfies GatewayProviderOptions,
},
});

for await (const textPart of result.textStream) {
process.stdout.write(textPart);
}

console.log();
console.log('Token usage:', await result.usage);
console.log('Finish reason:', await result.finishReason);
console.log(
'Provider metadata:',
JSON.stringify(await result.providerMetadata, null, 2),
);
}

main().catch(console.error);
7 changes: 7 additions & 0 deletions packages/gateway/src/gateway-provider-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ const gatewayProviderOptions = lazySchema(() =>
byok: z
.record(z.string(), z.array(z.record(z.string(), z.unknown())))
.optional(),
/**
* Whether to filter by only providers that state they have zero data
* retention with Vercel AI Gateway. When enabled, only providers that
* have agreements with Vercel AI Gateway for zero data retention will be
* used.
*/
zeroDataRetention: z.boolean().optional(),
}),
),
);
Expand Down
Loading