Skip to content
Closed
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/wild-kings-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ai-sdk/gateway": patch
---

Add caching property to GatewayProviderOptions type
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 @@ -836,6 +836,12 @@ The following gateway provider options are available:

The unique identifier for the entity against which quota is tracked. Used for quota management and enforcement purposes.

- **caching** _string_

Optional automatic caching configuration for the AI Gateway. Setting this to `'auto'` enables automatic caching of responses to optimize cost and latency.

Example: `caching: 'auto'`

- **providerTimeouts** _object_

Per-provider timeouts for BYOK credentials in milliseconds. Controls how long to wait for a provider to start responding before falling back to the next available provider.
Expand Down Expand Up @@ -963,6 +969,25 @@ const { text } = await generateText({
});
```

#### Caching Example

Set `caching` to `'auto'` to enable automatic caching of responses, which can reduce cost and latency for repeated requests.

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

const { text } = await generateText({
model: 'anthropic/claude-sonnet-4.6',
prompt: 'Summarize this report...',
providerOptions: {
gateway: {
caching: 'auto',
} 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
10 changes: 10 additions & 0 deletions packages/gateway/src/gateway-provider-options.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { GatewayProviderOptions } from './gateway-provider-options';
import { describe, expectTypeOf, it } from 'vitest';

describe('GatewayProviderOptions', () => {
it('caching accepts string', () => {
expectTypeOf<GatewayProviderOptions['caching']>().toEqualTypeOf<
string | undefined
>();
});
});
5 changes: 5 additions & 0 deletions packages/gateway/src/gateway-provider-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ const gatewayProviderOptions = lazySchema(() =>
* Used for quota management and enforcement purposes.
*/
quotaEntityId: z.string().optional(),
/**
* Automatic caching configuration for the AI Gateway.
* Example: `'auto'`
*/
caching: z.string().optional(),
/**
* Per-provider timeouts for BYOK credentials in milliseconds.
* Controls how long to wait for a provider to start responding
Expand Down